From 5f12d99e73289c12743a859e8d347a77e4f890e6 Mon Sep 17 00:00:00 2001 From: DarkLiKally Date: Thu, 24 Feb 2011 23:13:13 +0100 Subject: [PATCH] Added water flow flag --- config.yml | 15 ++++++++------- .../bukkit/WorldGuardBlockListener.java | 12 ++++++++++++ .../sk89q/worldguard/bukkit/WorldGuardPlugin.java | 3 ++- .../worldguard/bukkit/commands/FlagInfo.java | 1 + .../protection/ApplicableRegionSet.java | 2 ++ .../sk89q/worldguard/protection/GlobalFlags.java | 1 + .../worldguard/protection/regions/AreaFlags.java | 5 +++++ 7 files changed, 31 insertions(+), 8 deletions(-) diff --git a/config.yml b/config.yml index e02275d7..9f51a1c0 100644 --- a/config.yml +++ b/config.yml @@ -74,13 +74,14 @@ regions: enable: on wand: 287 default: - build: true - chest-access: false - pvp: true - lighter: true - tnt: true - creeper: true - mobdamage: true + build: on + chest-access: off + pvp: on + lighter: on + tnt: on + creeper: on + mobdamage: on + waterflow: on blacklist: logging: diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java index 054353ec..6ad4fee0 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java @@ -34,6 +34,7 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.blacklist.events.*; +import com.sk89q.worldguard.protection.GlobalFlags; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.regions.AreaFlags; import static com.sk89q.worldguard.bukkit.BukkitUtil.*; @@ -207,6 +208,17 @@ public void onBlockFlow(BlockFromToEvent event) { return; } } + + if (plugin.useRegions) { + Vector pt = toVector(blockFrom.getLocation()); + RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(world.getName()); + + if (!mgr.getApplicableRegions(pt) + .allowsFlag("waterflow")) { + event.setCancelled(true); + return; + } + } } /** diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index f8f4bb92..368b41b1 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -113,7 +113,7 @@ public class WorldGuardPlugin extends JavaPlugin { public boolean teleportOnSuffocation; public boolean useRegions; public int regionWand = 287; - public String blockCreatureSpawn; + public String blockCreatureSpawn = ""; /** * Construct the plugin. * @@ -314,6 +314,7 @@ public void loadConfiguration() { globalFlags.canTnt = config.getBoolean("regions.default.tnt", true); globalFlags.allowCreeper = config.getBoolean("regions.default.creeper", true); globalFlags.allowMobDamage = config.getBoolean("regions.default.mobdamage", true); + globalFlags.allowWaterflow = config.getBoolean("regions.default.waterflow", true); globalRegionManager.setGlobalFlags(globalFlags); try { diff --git a/src/com/sk89q/worldguard/bukkit/commands/FlagInfo.java b/src/com/sk89q/worldguard/bukkit/commands/FlagInfo.java index 8d4b7a9c..0a0aa420 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/FlagInfo.java +++ b/src/com/sk89q/worldguard/bukkit/commands/FlagInfo.java @@ -55,6 +55,7 @@ public static enum FlagValueType { STRING, BOOLEAN, INT, FLOAT, DOUBLE, STATE }; flagList.add(new FlagInfo("firespread", null, FlagValueType.STATE, "states", "firespread")); flagList.add(new FlagInfo("lavafirespread", null, FlagValueType.STATE, "states", "lavafirespread")); flagList.add(new FlagInfo("chest", null, FlagValueType.STATE, "states", "chest")); + flagList.add(new FlagInfo("waterflow", null, FlagValueType.STATE, "states", "waterflow")); } public static FlagInfo getFlagInfo(String name, String subName) { diff --git a/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java b/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java index 5463b246..5a0c8f31 100644 --- a/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java +++ b/src/com/sk89q/worldguard/protection/ApplicableRegionSet.java @@ -85,6 +85,8 @@ public boolean allowsFlag(String flag) { def = global.allowCreeper; } else if (flag.equals(AreaFlags.FLAG_MOB_DAMAGE)) { def = global.allowMobDamage; + } else if (flag.equals(AreaFlags.FLAG_WATER_FLOW)) { + def = global.allowWaterflow; } return isFlagAllowed(flag, def, null); diff --git a/src/com/sk89q/worldguard/protection/GlobalFlags.java b/src/com/sk89q/worldguard/protection/GlobalFlags.java index c6a8e5a5..edf04ecf 100644 --- a/src/com/sk89q/worldguard/protection/GlobalFlags.java +++ b/src/com/sk89q/worldguard/protection/GlobalFlags.java @@ -32,4 +32,5 @@ public class GlobalFlags { public boolean canTnt = true; public boolean allowCreeper = true; public boolean allowMobDamage = true; + public boolean allowWaterflow = true; } diff --git a/src/com/sk89q/worldguard/protection/regions/AreaFlags.java b/src/com/sk89q/worldguard/protection/regions/AreaFlags.java index 92d63638..993da1f4 100644 --- a/src/com/sk89q/worldguard/protection/regions/AreaFlags.java +++ b/src/com/sk89q/worldguard/protection/regions/AreaFlags.java @@ -45,6 +45,7 @@ public enum State { public static final String FLAG_FIRE_SPREAD = "f"; public static final String FLAG_LAVA_FIRE = "F"; public static final String FLAG_CHEST_ACCESS = "C"; + public static final String FLAG_WATER_FLOW = "w"; /** * Get the user-friendly name of a flag. If a name isn't known, then @@ -74,6 +75,8 @@ public static String getFlagName(String flag) { return "lava fire spread"; } else if (flag.equals(FLAG_CHEST_ACCESS)) { return "chest access"; + } else if (flag.equals(FLAG_WATER_FLOW)) { + return "water flow"; } else { return flag; } @@ -106,6 +109,8 @@ public static String fromAlias(String name) { return FLAG_LAVA_FIRE; } else if (name.equalsIgnoreCase("chest")) { return FLAG_CHEST_ACCESS; + } else if (name.equalsIgnoreCase("waterflow")) { + return FLAG_WATER_FLOW; } else { return null; }