From 2d5c1fd51ce7f37ea07a62c41f2fa835eb5cb1f5 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sun, 23 Feb 2014 17:41:25 +0000 Subject: Fix safety tp check above world height Performance tweak to fly check --- .../com/earth2me/essentials/utils/LocationUtil.java | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java b/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java index 1accd6d6e..1d2cbb6ae 100644 --- a/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java +++ b/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java @@ -215,6 +215,10 @@ public class LocationUtil static boolean isBlockAboveAir(final World world, final int x, final int y, final int z) { + if (y > world.getMaxHeight()) + { + return true; + } return HOLLOW_MATERIALS.contains(world.getBlockAt(x, y - 1, z).getType().getId()); } @@ -248,7 +252,7 @@ public class LocationUtil } return false; } - + // Not needed if using getSafeDestination(loc) public static Location getRoundedDestination(final Location loc) { @@ -273,7 +277,7 @@ public class LocationUtil } return getSafeDestination(loc); } - + public static Location getSafeDestination(final Location loc) throws Exception { if (loc == null || loc.getWorld() == null) @@ -347,15 +351,17 @@ public class LocationUtil final int x = loc.getBlockX(); int y = (int)Math.round(loc.getY()); final int z = loc.getBlockZ(); + int count = 0; while (LocationUtil.isBlockUnsafe(world, x, y, z) && y > -1) { y--; + count++; + if (count > 2) + { + return true; + } } - if (loc.getBlockY() - y > 1 || y < 0) - { - return true; - } - return false; + return y < 0 ? true : false; } } -- cgit v1.2.3