Fixed maxFallingHeight-Configuration Setting and added -1 to disable
This commit is contained in:
parent
aab42fcdca
commit
93ee72e2c6
2 changed files with 10 additions and 3 deletions
|
@ -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
|
* 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.
|
* sets him survival which would cause him falling and hurting.
|
||||||
*
|
*
|
||||||
|
* Set to -1 to disable
|
||||||
|
*
|
||||||
* default: 3
|
* default: 3
|
||||||
*/
|
*/
|
||||||
@IsConfigurationNode(order = 500)
|
@IsConfigurationNode(order = 500)
|
||||||
public int getMaximumFloatingHeight() {
|
public int getMaxFallingHeight() {
|
||||||
return config.getInt("maxFallingHeight", 3);
|
return config.getInt("maxFallingHeight", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,16 @@ public class RegionListener extends Listener {
|
||||||
super(mod);
|
super(mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkFloatingToHigh(int max, Location loc) {
|
||||||
|
if (max < 0)
|
||||||
|
return false;
|
||||||
|
return getFloatingHeight(loc) > max;
|
||||||
|
}
|
||||||
public int getFloatingHeight(Player player) {
|
public int getFloatingHeight(Player player) {
|
||||||
return getFloatingHeight(player.getLocation());
|
return getFloatingHeight(player.getLocation());
|
||||||
}
|
}
|
||||||
public int getFloatingHeight(Location loc) {
|
public int getFloatingHeight(Location loc) {
|
||||||
Block b = loc.getBlock();
|
Block b = loc.getBlock().getRelative(BlockFace.DOWN);
|
||||||
int steps = 0;
|
int steps = 0;
|
||||||
while (b.getType() == Material.AIR) {
|
while (b.getType() == Material.AIR) {
|
||||||
steps++;
|
steps++;
|
||||||
|
@ -39,7 +44,7 @@ public class RegionListener extends Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkSwitchFlight(PlayerMoveEvent event) {
|
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
|
// but not if he is too high
|
||||||
Utils.sendTimeoutMessage(event.getPlayer(), L("blocked.survival_flying"));
|
Utils.sendTimeoutMessage(event.getPlayer(), L("blocked.survival_flying"));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue