From 772d2cb580c3f5d34721ef288e732b2ad0f2483e Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 24 Jan 2011 02:35:33 -0800 Subject: [PATCH] Added ability to disable chest protection. --- .../bukkit/WorldGuardBlockListener.java | 2 ++ .../sk89q/worldguard/bukkit/WorldGuardPlugin.java | 1 + .../protection/ApplicableRegionSet.java | 15 +++++++++++++-- .../sk89q/worldguard/protection/AreaFlags.java | 5 +++++ .../sk89q/worldguard/protection/GlobalFlags.java | 1 + 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java index b525e7cb..4f38759a 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java @@ -35,6 +35,7 @@ import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.blacklist.events.*; import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.AreaFlags; import static com.sk89q.worldguard.bukkit.BukkitUtil.*; public class WorldGuardBlockListener extends BlockListener { @@ -288,6 +289,7 @@ public void onBlockInteract(BlockInteractEvent event) { LocalPlayer localPlayer = plugin.wrapPlayer(player); if (!plugin.hasPermission(player, "/regionbypass") + && !plugin.regionManager.getApplicableRegions(pt).allowsFlag(AreaFlags.FLAG_CHEST_ACCESS) && !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) { player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); event.setCancelled(true); diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index 0f7f72e9..df02a880 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -296,6 +296,7 @@ public void loadConfiguration() { useRegions = config.getBoolean("regions.enable", true); regionWand = config.getInt("regions.wand", 287); globalFlags.canBuild = config.getBoolean("regions.default.build", true); + globalFlags.canAccessChests = config.getBoolean("regions.default.chest-access", false); try { regionLoader.load(); diff --git a/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java b/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java index 9f26a057..4fe499c2 100644 --- a/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java +++ b/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java @@ -67,7 +67,13 @@ public boolean canBuild(LocalPlayer player) { * @return */ public boolean allowsFlag(String flag) { - return isFlagAllowed(flag, true, null); + boolean def = true; + + if (flag.equals(AreaFlags.FLAG_CHEST_ACCESS)) { + def = global.canAccessChests; + } + + return isFlagAllowed(flag, def, null); } /** @@ -80,6 +86,9 @@ public boolean allowsFlag(String flag) { private boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) { boolean found = false; boolean allowed = false; // Used for ALLOW override + if (player == null) { + allowed = def; + } int lastPriority = 0; // The algorithm is as follows: @@ -120,6 +129,7 @@ private boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) { // default state is now to allow if (region.getFlags().get(flag) == State.ALLOW) { allowed = true; + found = true; continue; } @@ -145,7 +155,8 @@ private boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) { lastPriority = region.getPriority(); } - return found == false ? def : allowed || needsClear.size() == 0; + return (found == false ? def : allowed) + || (player != null && needsClear.size() == 0); } /** diff --git a/src/com/sk89q/worldguard/protection/AreaFlags.java b/src/com/sk89q/worldguard/protection/AreaFlags.java index 1512d4ed..2f75e563 100644 --- a/src/com/sk89q/worldguard/protection/AreaFlags.java +++ b/src/com/sk89q/worldguard/protection/AreaFlags.java @@ -44,6 +44,7 @@ public enum State { public static final String FLAG_LIGHTER = "l"; public static final String FLAG_FIRE_SPREAD = "f"; public static final String FLAG_LAVA_FIRE = "F"; + public static final String FLAG_CHEST_ACCESS = "c"; /** * Get the user-friendly name of a flag. If a name isn't known, then @@ -71,6 +72,8 @@ public static String getFlagName(String flag) { return "fire spread"; } else if (flag.equals(FLAG_LAVA_FIRE)) { return "lava fire spread"; + } else if (flag.equals(FLAG_CHEST_ACCESS)) { + return "chest access"; } else { return flag; } @@ -101,6 +104,8 @@ public static String fromAlias(String name) { return FLAG_FIRE_SPREAD; } else if (name.equalsIgnoreCase("lavafirespread")) { return FLAG_LAVA_FIRE; + } else if (name.equalsIgnoreCase("chest")) { + return FLAG_CHEST_ACCESS; } else { return null; } diff --git a/src/com/sk89q/worldguard/protection/GlobalFlags.java b/src/com/sk89q/worldguard/protection/GlobalFlags.java index 57ea1077..835ae723 100644 --- a/src/com/sk89q/worldguard/protection/GlobalFlags.java +++ b/src/com/sk89q/worldguard/protection/GlobalFlags.java @@ -26,4 +26,5 @@ */ public class GlobalFlags { public boolean canBuild = true; + public boolean canAccessChests = false; }