From 16ce56c1ad3d53fda949547b86e0cc0648dcb9a4 Mon Sep 17 00:00:00 2001 From: Deaygo Date: Fri, 23 Mar 2012 16:44:19 -0400 Subject: [PATCH] Added allow-flight boolean flag for regions Closes #198 --- CHANGELOG.txt | 4 +++- .../worldguard/bukkit/FlagStateManager.java | 1 + .../bukkit/WorldGuardPlayerListener.java | 20 +++++++++++++++++++ .../protection/flags/DefaultFlag.java | 3 ++- 4 files changed, 26 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/main/java/com/sk89q/worldguard/bukkit/FlagStateManager.java mode change 100644 => 100755 src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java mode change 100644 => 100755 src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d068dabf..9064a6bc 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,4 +1,6 @@ 5.5.2: + - Added 'allow-flight' flag, which allows or disallows flight per-region + - Restructured /region list - A cancellable event is now fired if WorldGuard disallows PvP. (for developers!) - Made /region setparent check worldguard.region.setparent.own/member. instead of worldguard.region.setparent.own/member.. - Allowed passing # in place of a region ID, where is the index as displayed by /region list. @@ -387,4 +389,4 @@ EduardBaer, TomyLobo, and halvors - Added block lag fix. 1.0 -- Initial release. \ No newline at end of file +- Initial release. diff --git a/src/main/java/com/sk89q/worldguard/bukkit/FlagStateManager.java b/src/main/java/com/sk89q/worldguard/bukkit/FlagStateManager.java old mode 100644 new mode 100755 index db4028b4..6f26228e --- a/src/main/java/com/sk89q/worldguard/bukkit/FlagStateManager.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/FlagStateManager.java @@ -220,6 +220,7 @@ public static class PlayerFlagState { public Boolean lastExitAllowed = null; public Boolean notifiedForLeave = false; public Boolean notifiedForEnter = false; + public Boolean lastAllowFlight = null; public World lastWorld; public int lastBlockX; public int lastBlockY; diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java old mode 100644 new mode 100755 index c9d9c87d..14b8fdad --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java @@ -65,6 +65,7 @@ import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import org.bukkit.GameMode; /** * Handles all events thrown in relation to a player. @@ -158,6 +159,7 @@ public void onPlayerMove(PlayerMoveEvent event) { String farewell = set.getFlag(DefaultFlag.FAREWELL_MESSAGE);//, localPlayer); Boolean notifyEnter = set.getFlag(DefaultFlag.NOTIFY_ENTER);//, localPlayer); Boolean notifyLeave = set.getFlag(DefaultFlag.NOTIFY_LEAVE);//, localPlayer); + Boolean allowFlight = set.getFlag(DefaultFlag.ALLOW_FLIGHT);//, localPlayer); if (state.lastFarewell != null && (farewell == null || !state.lastFarewell.equals(farewell))) { @@ -197,6 +199,24 @@ public void onPlayerMove(PlayerMoveEvent event) { + ChatColor.WHITE + regionList); } + + if (allowFlight == null) { + if ((plugin.getServer().getDefaultGameMode() == GameMode.CREATIVE + && player.getGameMode() == GameMode.CREATIVE) + || player.getGameMode() == GameMode.CREATIVE) { + allowFlight = true; + } else { + allowFlight = false; + } + } + + if (player.getAllowFlight() && !allowFlight) { + player.setAllowFlight(false); + state.lastAllowFlight = true; + } else if (!player.getAllowFlight() && allowFlight) { + player.setAllowFlight(true); + state.lastAllowFlight = false; + } state.lastGreeting = greeting; state.lastFarewell = farewell; diff --git a/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java b/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java old mode 100644 new mode 100755 index 361ed7f8..f091f807 --- a/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java +++ b/src/main/java/com/sk89q/worldguard/protection/flags/DefaultFlag.java @@ -80,6 +80,7 @@ public final class DefaultFlag { public static final DoubleFlag PRICE = new DoubleFlag("price"); public static final SetFlag BLOCKED_CMDS = new SetFlag("blocked-cmds", RegionGroup.ALL, new CommandStringFlag(null)); public static final SetFlag ALLOWED_CMDS = new SetFlag("allowed-cmds", RegionGroup.ALL, new CommandStringFlag(null)); + public static final BooleanFlag ALLOW_FLIGHT = new BooleanFlag("allow-flight", RegionGroup.ALL); public static final Flag[] flagsList = new Flag[] { PASSTHROUGH, BUILD, CONSTRUCT, PVP, CHEST_ACCESS, PISTONS, @@ -94,7 +95,7 @@ public final class DefaultFlag { MUSHROOMS, LEAF_DECAY, GRASS_SPREAD, FIRE_SPREAD, LAVA_FIRE, LAVA_FLOW, WATER_FLOW, TELE_LOC, SPAWN_LOC, - BLOCKED_CMDS, ALLOWED_CMDS, PRICE, BUYABLE, + BLOCKED_CMDS, ALLOWED_CMDS, PRICE, BUYABLE, ALLOW_FLIGHT, };