From 5ea055a260274e8739cce4dd31fef4b34afc47d3 Mon Sep 17 00:00:00 2001 From: "Andy \"Spathi\" F" Date: Mon, 29 Aug 2011 14:54:04 +0200 Subject: [PATCH 1/7] WorldGuard regions will block factions claiming them --- src/com/massivecraft/factions/FPlayer.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 5ac1350d..a060e082 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -508,6 +508,12 @@ public class FPlayer { FLocation flocation = new FLocation(this); Faction otherFaction = Board.getFactionAt(flocation); + if (Worldguard.checkForRegions(this.getPlayer().getLocation())) { + // Checks for WorldGuard regions in the chunk attempting to be claimed + sendMessage("This land is protected"); + return false; + } + if (myFaction == otherFaction) { if (notifyFailure) sendMessage("You already own this land."); From a7cce7e42897f7a1c688c42928680afd485788bd Mon Sep 17 00:00:00 2001 From: "Andy \"Spathi\" F" Date: Mon, 29 Aug 2011 15:06:34 +0200 Subject: [PATCH 2/7] Changed checkForRegions to be checkForRegionsInChunk --- src/com/massivecraft/factions/FPlayer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index a060e082..ccb5382c 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -508,7 +508,7 @@ public class FPlayer { FLocation flocation = new FLocation(this); Faction otherFaction = Board.getFactionAt(flocation); - if (Worldguard.checkForRegions(this.getPlayer().getLocation())) { + if (Worldguard.checkForRegionsInChunk(this.getPlayer().getLocation())) { // Checks for WorldGuard regions in the chunk attempting to be claimed sendMessage("This land is protected"); return false; From 8be43164d281e11bb6ad5f13a9c651d5bad32154 Mon Sep 17 00:00:00 2001 From: Spathi Date: Mon, 29 Aug 2011 04:50:45 +0100 Subject: [PATCH 3/7] Worldguard region checking --- src/com/massivecraft/factions/Worldguard.java | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/com/massivecraft/factions/Worldguard.java diff --git a/src/com/massivecraft/factions/Worldguard.java b/src/com/massivecraft/factions/Worldguard.java new file mode 100644 index 00000000..36d8e568 --- /dev/null +++ b/src/com/massivecraft/factions/Worldguard.java @@ -0,0 +1,109 @@ +package com.massivecraft.factions; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.UnsupportedIntersectionException; +import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; + +import static com.sk89q.worldguard.bukkit.BukkitUtil.*; +import com.sk89q.worldguard.protection.flags.DefaultFlag; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.BlockVector; + +import org.bukkit.*; +import org.bukkit.plugin.Plugin; +import org.bukkit.entity.Player; + +/* + * Worldguard Region Checking + * Author: Spathizilla + */ + +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."); + } + } + + public static boolean isEnabled() { + return enabled; + } + + // PVP Flag check + // Returns: + // True: PVP is allowed + // False: PVP is disallowed + public static boolean isPVP(Player player) { + if(isEnabled()) { + Location loc = player.getLocation(); + World world = loc.getWorld(); + Vector pt = toVector(loc); + + RegionManager regionManager = wg.getRegionManager(world); + ApplicableRegionSet set = regionManager.getApplicableRegions(pt); + return set.allows(DefaultFlag.PVP); + } else { + // No WG hooks so we'll always bypass this check. + 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; + + try { + overlaps = region.getIntersectingRegions(allregionslist); + if(overlaps.isEmpty() || overlaps == null) { + foundregions = false; + } else { + foundregions = true; + } + } catch (UnsupportedIntersectionException e) { + e.printStackTrace(); + } + + region = null; + allregionslist = null; + overlaps = null; + + return foundregions; + } +} \ No newline at end of file From 445d10afb76823a678108803246d539044ebbced Mon Sep 17 00:00:00 2001 From: Spathi Date: Mon, 29 Aug 2011 04:59:49 +0100 Subject: [PATCH 4/7] 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 From c5f88fe71689faddccf58154f17ba84f97b394d9 Mon Sep 17 00:00:00 2001 From: Spathi Date: Wed, 31 Aug 2011 02:13:16 +0100 Subject: [PATCH 5/7] Reworked entire chunk checking + code cleanup --- src/com/massivecraft/factions/Worldguard.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/com/massivecraft/factions/Worldguard.java b/src/com/massivecraft/factions/Worldguard.java index 96059350..ba1ce089 100644 --- a/src/com/massivecraft/factions/Worldguard.java +++ b/src/com/massivecraft/factions/Worldguard.java @@ -16,7 +16,9 @@ import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.BlockVector; -import org.bukkit.*; +import org.bukkit.World; +import org.bukkit.Chunk; +import org.bukkit.Location; import org.bukkit.plugin.Plugin; import org.bukkit.entity.Player; @@ -71,21 +73,21 @@ public class Worldguard { // False: No regions found within chunk public static boolean checkForRegionsInChunk(Location loc) { if(isEnabled()) { - int plocX = loc.getBlockX(); - int plocZ = loc.getBlockZ(); World world = loc.getWorld(); + Chunk chunk = world.getChunkAt(loc); + int minChunkX = chunk.getX() * 16; + int minChunkZ = chunk.getZ() * 16; + int maxChunkX = minChunkX + 15; + int maxChunkZ = minChunkZ + 15; - Chunk chunk = world.getChunkAt(plocX, plocZ); - int chunkX = chunk.getX(); - int chunkZ = chunk.getZ(); + int worldHeight = world.getMaxHeight(); // Allow for heights other than default - BlockVector minChunk = new BlockVector(chunkX, 0, chunkZ); - BlockVector maxChunk = new BlockVector(chunkX+15, 128, chunkZ+15); + BlockVector minChunk = new BlockVector(minChunkX, 0, minChunkZ); + BlockVector maxChunk = new BlockVector(maxChunkX, worldHeight, maxChunkZ); 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; From 106944ba863f7cfe205f25899a674f980a5a5111 Mon Sep 17 00:00:00 2001 From: Spathi Date: Wed, 31 Aug 2011 02:14:46 +0100 Subject: [PATCH 6/7] Fixing code indents --- src/com/massivecraft/factions/Worldguard.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/massivecraft/factions/Worldguard.java b/src/com/massivecraft/factions/Worldguard.java index ba1ce089..00750983 100644 --- a/src/com/massivecraft/factions/Worldguard.java +++ b/src/com/massivecraft/factions/Worldguard.java @@ -10,9 +10,9 @@ import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.UnsupportedIntersectionException; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion; - import static com.sk89q.worldguard.bukkit.BukkitUtil.*; import com.sk89q.worldguard.protection.flags.DefaultFlag; + import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.BlockVector; From 61e766701014a9ec5de4bcc8369c4409bfb1cbe9 Mon Sep 17 00:00:00 2001 From: Spathi Date: Tue, 6 Sep 2011 03:31:15 +0100 Subject: [PATCH 7/7] Spout always shows displaynames even with factionless players --- src/com/massivecraft/factions/SpoutFeatures.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/massivecraft/factions/SpoutFeatures.java b/src/com/massivecraft/factions/SpoutFeatures.java index 725afedb..7a9335e0 100644 --- a/src/com/massivecraft/factions/SpoutFeatures.java +++ b/src/com/massivecraft/factions/SpoutFeatures.java @@ -147,7 +147,7 @@ public class SpoutFeatures { spoutApp.setPlayerTitle(sPlayer, viewed, addTag + "\n" + viewed.getDisplayName()); } else { - spoutApp.resetPlayerTitle(sPlayer, viewed); + spoutApp.setPlayerTitle(sPlayer, viewed, viewed.getDisplayName()); } }