diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 366e0c059..d112aea88 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -271,16 +271,7 @@ public class EssentialsPlayerListener implements Listener if (user.isAuthorized("essentials.fly.safelogin")) { - final World world = user.getLocation().getWorld(); - final int x = user.getLocation().getBlockX(); - int y = user.getLocation().getBlockY(); - final int z = user.getLocation().getBlockZ(); - while (LocationUtil.isBlockUnsafe(world, x, y, z) && y > -1) - { - y--; - } - - if (user.getLocation().getBlockY() - y > 1 || y < 0) + if (LocationUtil.shouldFly(user.getLocation())) { user.setAllowFlight(true); user.setFlying(true); diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index 708016d69..3de854b8b 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -97,7 +97,7 @@ public class Teleport implements net.ess3.api.ITeleport cancel(false); teleportee.setLastLocation(); teleportee.requestTeleport(null, false); - teleportee.getBase().teleport(LocationUtil.getSafeDestination(target.getLocation()), cause); + teleportee.getBase().teleport(LocationUtil.getSafeDestination(teleportee, target.getLocation()), cause); } //The teleportPlayer function is used when you want to normally teleportPlayer someone to a location or player. diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java index 9fe317b21..6bec3afa6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java @@ -72,5 +72,6 @@ public abstract class EssentialsToggleCommand extends EssentialsCommand } } + // Make sure when implementing this method that all 3 Boolean states are handled, 'null' should toggle the existing state. abstract void togglePlayer(CommandSender sender, User user, Boolean enabled) throws NotEnoughArgumentsException; } diff --git a/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java b/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java index a9ee6f0eb..3f5f9d66d 100644 --- a/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java +++ b/Essentials/src/com/earth2me/essentials/utils/LocationUtil.java @@ -7,6 +7,8 @@ import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Set; +import net.ess3.api.IUser; +import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -20,7 +22,7 @@ public class LocationUtil // The player can stand inside these materials public static final Set HOLLOW_MATERIALS = new HashSet(); private static final HashSet TRANSPARENT_MATERIALS = new HashSet(); - + static { HOLLOW_MATERIALS.add(Material.AIR.getId()); @@ -67,7 +69,6 @@ public class LocationUtil TRANSPARENT_MATERIALS.add((byte)Material.WATER.getId()); TRANSPARENT_MATERIALS.add((byte)Material.STATIONARY_WATER.getId()); } - public final static int RADIUS = 3; public final static Vector3D[] VOLUME; @@ -153,6 +154,7 @@ public class LocationUtil return is; } + public static class Vector3D { public Vector3D(int x, int y, int z) @@ -190,7 +192,6 @@ public class LocationUtil }); VOLUME = pos.toArray(new Vector3D[0]); } - public static Location getTarget(final LivingEntity entity) throws Exception { @@ -238,6 +239,21 @@ public class LocationUtil return false; } + public static Location getSafeDestination(final IUser user, final Location loc) throws Exception + { + if (loc.getWorld().equals(user.getBase().getWorld()) + && (user.getBase().getGameMode() == GameMode.CREATIVE + || (user.isGodModeEnabled() && user.getBase().getAllowFlight()))) + { + if (shouldFly(loc)) + { + user.getBase().setFlying(true); + } + return loc; + } + return getSafeDestination(loc); + } + public static Location getSafeDestination(final Location loc) throws Exception { if (loc == null || loc.getWorld() == null) @@ -303,5 +319,23 @@ public class LocationUtil } } return new Location(world, x + 0.5, y, z + 0.5, loc.getYaw(), loc.getPitch()); - } + } + + public static boolean shouldFly(Location loc) + { + final World world = loc.getWorld(); + final int x = loc.getBlockX(); + int y = loc.getBlockY(); + final int z = loc.getBlockZ(); + while (LocationUtil.isBlockUnsafe(world, x, y, z) && y > -1) + { + y--; + } + + if (loc.getBlockY() - y > 1 || y < 0) + { + return true; + } + return false; + } }