Fixed maxFallingHeight-Configuration Setting and added -1 to disable

This commit is contained in:
Jascha Starke 2013-07-30 08:44:22 +02:00
parent aab42fcdca
commit 93ee72e2c6
2 changed files with 10 additions and 3 deletions

View file

@ -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);
}

View file

@ -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"));