summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2013-08-11 22:42:29 +0100
committerKHobbits <rob@khobbits.co.uk>2013-08-11 22:42:29 +0100
commit517d6a30cb52bcb5afc2649bb5057a464c388385 (patch)
treea686d1667b3977325482293dddce9dbc0528f5e6
parent04aed9d05eeb66bbf00531d38822996d15d679c1 (diff)
downloadEssentials-517d6a30cb52bcb5afc2649bb5057a464c388385.tar
Essentials-517d6a30cb52bcb5afc2649bb5057a464c388385.tar.gz
Essentials-517d6a30cb52bcb5afc2649bb5057a464c388385.tar.lz
Essentials-517d6a30cb52bcb5afc2649bb5057a464c388385.tar.xz
Essentials-517d6a30cb52bcb5afc2649bb5057a464c388385.zip
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.
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java11
-rw-r--r--Essentials/src/com/earth2me/essentials/Teleport.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/utils/LocationUtil.java42
4 files changed, 41 insertions, 15 deletions
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<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;
+ }
}