From 445d10afb76823a678108803246d539044ebbced Mon Sep 17 00:00:00 2001 From: Spathi Date: Mon, 29 Aug 2011 04:59:49 +0100 Subject: [PATCH] Optional disabling of WG checks --- src/com/massivecraft/factions/Conf.java | 2 + src/com/massivecraft/factions/Factions.java | 4 + src/com/massivecraft/factions/Worldguard.java | 82 ++++++++++--------- 3 files changed, 49 insertions(+), 39 deletions(-) diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index 82c3ab1c..6c75eda9 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -63,6 +63,8 @@ public class Conf { public static double autoLeaveAfterDaysOfInactivity = 14.0; + public static boolean worldGuardChecking = true; + public static boolean homesEnabled = true; public static boolean homesMustBeInClaimedTerritory = true; public static boolean homesTeleportToOnDeath = true; diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 58136cc9..5bd19217 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -151,6 +151,10 @@ public class Factions extends JavaPlugin { Econ.setup(this); Econ.monitorPlugins(); + if(Conf.worldGuardChecking) { + Worldguard.init(this); + } + // Register events PluginManager pm = this.getServer().getPluginManager(); pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Highest, this); diff --git a/src/com/massivecraft/factions/Worldguard.java b/src/com/massivecraft/factions/Worldguard.java index 36d8e568..96059350 100644 --- a/src/com/massivecraft/factions/Worldguard.java +++ b/src/com/massivecraft/factions/Worldguard.java @@ -28,18 +28,18 @@ import org.bukkit.entity.Player; public class Worldguard { private static WorldGuardPlugin wg; private static boolean enabled = false; - + public static void init(Plugin plugin) { Plugin wgplug = plugin.getServer().getPluginManager().getPlugin("WorldGuard"); if (wgplug == null || !(wgplug instanceof WorldGuardPlugin)) { enabled = false; wg = null; System.out.println("[Factions] Could not hook to WorldGuard. WorldGuard checks are disabled."); - } else { - wg = (WorldGuardPlugin) wgplug; - enabled = true; - System.out.println("[Factions] Successfully hooked to WorldGuard."); - } + } else { + wg = (WorldGuardPlugin) wgplug; + enabled = true; + System.out.println("[Factions] Successfully hooked to WorldGuard."); + } } public static boolean isEnabled() { @@ -64,46 +64,50 @@ public class Worldguard { return true; } } - + // Check for Regions in chunk the chunk // Returns: // True: Regions found within chunk // False: No regions found within chunk public static boolean checkForRegionsInChunk(Location loc) { - int plocX = loc.getBlockX(); - int plocZ = loc.getBlockZ(); - World world = loc.getWorld(); - - Chunk chunk = world.getChunkAt(plocX, plocZ); - int chunkX = chunk.getX(); - int chunkZ = chunk.getZ(); - - BlockVector minChunk = new BlockVector(chunkX, 0, chunkZ); - BlockVector maxChunk = new BlockVector(chunkX+15, 128, chunkZ+15); - - RegionManager regionManager = wg.getRegionManager(world); - ProtectedCuboidRegion region = new ProtectedCuboidRegion("wgfactionoverlapcheck", minChunk, maxChunk); - Map allregions = regionManager.getRegions(); - - List allregionslist = new ArrayList(allregions.values()); - List overlaps; - boolean foundregions = false; + if(isEnabled()) { + int plocX = loc.getBlockX(); + int plocZ = loc.getBlockZ(); + World world = loc.getWorld(); - try { - overlaps = region.getIntersectingRegions(allregionslist); - if(overlaps.isEmpty() || overlaps == null) { - foundregions = false; - } else { - foundregions = true; + Chunk chunk = world.getChunkAt(plocX, plocZ); + int chunkX = chunk.getX(); + int chunkZ = chunk.getZ(); + + BlockVector minChunk = new BlockVector(chunkX, 0, chunkZ); + BlockVector maxChunk = new BlockVector(chunkX+15, 128, chunkZ+15); + + RegionManager regionManager = wg.getRegionManager(world); + ProtectedCuboidRegion region = new ProtectedCuboidRegion("wgfactionoverlapcheck", minChunk, maxChunk); + Map allregions = regionManager.getRegions(); + + List allregionslist = new ArrayList(allregions.values()); + List overlaps; + boolean foundregions = false; + + try { + overlaps = region.getIntersectingRegions(allregionslist); + if(overlaps.isEmpty() || overlaps == null) { + foundregions = false; + } else { + foundregions = true; + } + } catch (UnsupportedIntersectionException e) { + e.printStackTrace(); } - } catch (UnsupportedIntersectionException e) { - e.printStackTrace(); - } - region = null; - allregionslist = null; - overlaps = null; - - return foundregions; + region = null; + allregionslist = null; + overlaps = null; + + return foundregions; + } else { + return false; + } } } \ No newline at end of file