When in fly+god mode or when in creative mode, don't use safe teleport location when teleporting to other players.

Enable fly in unsafe circumstances.
This only works when teleporting within worlds for permission reasons.
This commit is contained in:
KHobbits 2013-08-11 22:42:29 +01:00
parent ee05bf371d
commit 09e8b87650
4 changed files with 41 additions and 15 deletions

View File

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

View File

@ -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.

View File

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

View File

@ -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<Integer> HOLLOW_MATERIALS = new HashSet<Integer>();
private static final HashSet<Byte> TRANSPARENT_MATERIALS = new HashSet<Byte>();
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;
}
}