You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
4.2 KiB
126 lines
4.2 KiB
10 years ago
|
package ru.simsonic.rscPermissions.Bukkit;
|
||
11 years ago
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||
|
import java.util.Collections;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.HashSet;
|
||
|
import java.util.Map;
|
||
|
import java.util.Set;
|
||
|
import net.t00thpick1.residence.Residence;
|
||
|
import net.t00thpick1.residence.api.ResidenceAPI;
|
||
|
import net.t00thpick1.residence.api.ResidenceManager;
|
||
|
import net.t00thpick1.residence.api.areas.ResidenceArea;
|
||
|
import org.bukkit.Location;
|
||
|
import org.bukkit.World;
|
||
|
import org.bukkit.entity.Player;
|
||
|
import org.bukkit.plugin.Plugin;
|
||
10 years ago
|
import ru.simsonic.rscPermissions.BukkitPluginMain;
|
||
11 years ago
|
|
||
10 years ago
|
public final class BukkitRegionProviders
|
||
11 years ago
|
{
|
||
11 years ago
|
private final BukkitPluginMain plugin;
|
||
11 years ago
|
private Plugin worldguard;
|
||
|
private Plugin residence;
|
||
|
private final Map<Player, Set<String>> regionsByPlayer = new HashMap<>();
|
||
|
private final Map<Player, Integer> playerRegionHashes = new HashMap<>();
|
||
|
private final Map<Player, World> playerLastWorld = new HashMap<>();
|
||
10 years ago
|
public BukkitRegionProviders(BukkitPluginMain rscp)
|
||
11 years ago
|
{
|
||
|
this.plugin = rscp;
|
||
|
}
|
||
|
public synchronized void integrate()
|
||
|
{
|
||
|
// WorldGuard
|
||
|
if(plugin.settings.isUseWorldGuard())
|
||
|
{
|
||
|
final Plugin pluginWG = plugin.getServer().getPluginManager().getPlugin("WorldGuard");
|
||
|
if((pluginWG != null) && (pluginWG instanceof WorldGuardPlugin))
|
||
|
{
|
||
|
this.worldguard = pluginWG;
|
||
11 years ago
|
BukkitPluginMain.consoleLog.info("[rscp] WorldGuard was found and integrated.");
|
||
11 years ago
|
} else {
|
||
|
this.worldguard = null;
|
||
11 years ago
|
BukkitPluginMain.consoleLog.info("[rscp] WorldGuard was not found.");
|
||
11 years ago
|
}
|
||
|
} else
|
||
|
this.worldguard = null;
|
||
|
// Residence
|
||
|
if(plugin.settings.isUseResidence())
|
||
|
{
|
||
|
final Plugin pluginR = plugin.getServer().getPluginManager().getPlugin("Residence");
|
||
|
if((pluginR != null) && (pluginR instanceof Residence))
|
||
|
{
|
||
|
this.residence = pluginR;
|
||
11 years ago
|
BukkitPluginMain.consoleLog.info("[rscp] Residence was found and integrated.");
|
||
11 years ago
|
} else {
|
||
|
this.residence = null;
|
||
11 years ago
|
BukkitPluginMain.consoleLog.info("[rscp] Residence was not found.");
|
||
11 years ago
|
}
|
||
|
} else
|
||
|
this.residence = null;
|
||
|
}
|
||
|
public synchronized void deintegrate()
|
||
|
{
|
||
|
this.worldguard = null;
|
||
|
this.residence = null;
|
||
|
}
|
||
11 years ago
|
public synchronized boolean isRegionListChanged(Player player)
|
||
11 years ago
|
{
|
||
|
final Location location = player.getLocation();
|
||
|
final World world = location.getWorld();
|
||
|
final Set<String> playerRegions = new HashSet<>();
|
||
|
// WorldGuard
|
||
|
if(worldguard != null && worldguard.isEnabled())
|
||
|
try
|
||
|
{
|
||
|
final WorldGuardPlugin pluginWG = (WorldGuardPlugin)worldguard;
|
||
|
final RegionManager rman = pluginWG.getRegionManager(world);
|
||
|
if(rman == null)
|
||
|
return false;
|
||
|
// Get list
|
||
|
final ApplicableRegionSet appregs = rman.getApplicableRegions(location);
|
||
|
for(ProtectedRegion region : appregs)
|
||
|
playerRegions.add(region.getId());
|
||
|
} catch(RuntimeException ex) {
|
||
|
}
|
||
|
// Residence
|
||
|
if(residence != null && residence.isEnabled())
|
||
|
try
|
||
|
{
|
||
|
// Get list
|
||
|
final ResidenceManager residenceManager = ResidenceAPI.getResidenceManager();
|
||
|
if(residenceManager != null)
|
||
|
{
|
||
|
final ResidenceArea residenceArea = residenceManager.getByLocation(location);
|
||
|
if(residenceArea != null)
|
||
|
playerRegions.add(residenceArea.getFullName());
|
||
|
}
|
||
|
} catch(RuntimeException ex) {
|
||
|
}
|
||
|
// Is it changed?
|
||
|
int hashcode = playerRegions.hashCode();
|
||
|
if(playerLastWorld.containsKey(player))
|
||
|
if(playerLastWorld.get(player).equals(world))
|
||
|
if(hashcode == playerRegionHashes.get(player))
|
||
|
return false;
|
||
|
// Update
|
||
|
playerRegionHashes.put(player, hashcode);
|
||
|
regionsByPlayer.put(player, playerRegions);
|
||
|
playerLastWorld.put(player, world);
|
||
|
return true;
|
||
|
}
|
||
11 years ago
|
public synchronized Set<String> getPlayerRegions(Player player)
|
||
11 years ago
|
{
|
||
|
Set<String> result = regionsByPlayer.get(player);
|
||
|
return (result != null) ? result : Collections.<String>emptySet();
|
||
|
}
|
||
|
public synchronized void removePlayer(Player player)
|
||
|
{
|
||
|
playerRegionHashes.remove(player);
|
||
|
regionsByPlayer.remove(player);
|
||
|
playerLastWorld.remove(player);
|
||
|
}
|
||
11 years ago
|
}
|