From 2d41f1d69641e6571c24bdb4bfaffdd87633f4ec Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sun, 4 Dec 2011 11:04:14 +0000 Subject: [PATCH] Indicate when a teleport event was triggered by ender pearls or unknown internal teleports By: Nathan Adams --- .../java/org/bukkit/craftbukkit/entity/CraftEntity.java | 9 +++++++++ .../java/org/bukkit/craftbukkit/entity/CraftPlayer.java | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index 606824494c..ccd6547554 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; import org.bukkit.Bukkit; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public abstract class CraftEntity implements org.bukkit.entity.Entity { private static final Map players = new MapMaker().softValues().makeMap(); @@ -152,6 +153,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { } public boolean teleport(Location location) { + return teleport(this, TeleportCause.PLUGIN); + } + + public boolean teleport(Location location, TeleportCause cause) { entity.world = ((CraftWorld) location.getWorld()).getHandle(); entity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); // entity.setLocation() throws no event, and so cannot be cancelled @@ -162,6 +167,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { return teleport(destination.getLocation()); } + public boolean teleport(org.bukkit.entity.Entity destination, TeleportCause cause) { + return teleport(destination.getLocation(), cause); + } + public List getNearbyEntities(double x, double y, double z) { @SuppressWarnings("unchecked") List notchEntityList = entity.world.b(entity, entity.boundingBox.b(x, y, z)); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 1e980b0407..efed45acdd 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -86,10 +86,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } } + @Override public double getEyeHeight() { return getEyeHeight(false); } + @Override public double getEyeHeight(boolean ignoreSneaking) { if (ignoreSneaking) { return 1.62D; @@ -274,7 +276,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } @Override - public boolean teleport(Location location) { + public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) { if (getHandle().netServerHandler == null) return false; // From = Players current Location @@ -282,7 +284,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { // To = Players new Location if Teleport is Successful Location to = location; // Create & Call the Teleport Event. - PlayerTeleportEvent event = new PlayerTeleportEvent((Player) this, from, to); + PlayerTeleportEvent event = new PlayerTeleportEvent((Player) this, from, to, cause); server.getPluginManager().callEvent(event); // Return False to inform the Plugin that the Teleport was unsuccessful/cancelled. if (event.isCancelled() == true) {