From 93ee72e2c6150f3b938db24459e99567f620fc8d Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Tue, 30 Jul 2013 08:44:22 +0200 Subject: [PATCH] Fixed maxFallingHeight-Configuration Setting and added -1 to disable --- .../minecraft/limitedcreative/regions/RegionConfig.java | 4 +++- .../limitedcreative/regions/RegionListener.java | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java index a745f50..e3a38b0 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java @@ -113,10 +113,12 @@ public class RegionConfig extends Configuration implements IConfigurationSubGrou * When the player is more than this count of blocks above the ground, he is prevented from changing the region that * sets him survival which would cause him falling and hurting. * + * Set to -1 to disable + * * default: 3 */ @IsConfigurationNode(order = 500) - public int getMaximumFloatingHeight() { + public int getMaxFallingHeight() { return config.getInt("maxFallingHeight", 3); } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java index dbe7dbe..4cf81dc 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionListener.java @@ -25,11 +25,16 @@ public class RegionListener extends Listener { super(mod); } + private boolean checkFloatingToHigh(int max, Location loc) { + if (max < 0) + return false; + return getFloatingHeight(loc) > max; + } public int getFloatingHeight(Player player) { return getFloatingHeight(player.getLocation()); } public int getFloatingHeight(Location loc) { - Block b = loc.getBlock(); + Block b = loc.getBlock().getRelative(BlockFace.DOWN); int steps = 0; while (b.getType() == Material.AIR) { steps++; @@ -39,7 +44,7 @@ public class RegionListener extends Listener { } private boolean checkSwitchFlight(PlayerMoveEvent event) { - if (event != null && event.getPlayer().getGameMode() == GameMode.CREATIVE && getFloatingHeight(event.getTo()) > mod.getConfig().getMaximumFloatingHeight()) { + if (event != null && event.getPlayer().getGameMode() == GameMode.CREATIVE && checkFloatingToHigh(mod.getConfig().getMaxFallingHeight(), event.getTo())) { // but not if he is too high Utils.sendTimeoutMessage(event.getPlayer(), L("blocked.survival_flying"));