Indicate when a teleport event was triggered by ender pearls or unknown internal teleports

By: Nathan Adams <dinnerbone@dinnerbone.com>
This commit is contained in:
CraftBukkit/Spigot 2011-12-04 11:04:14 +00:00
parent dadf3e028c
commit 2d41f1d696
2 changed files with 13 additions and 2 deletions

View file

@ -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<String, CraftPlayer> 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<org.bukkit.entity.Entity> getNearbyEntities(double x, double y, double z) {
@SuppressWarnings("unchecked")
List<Entity> notchEntityList = entity.world.b(entity, entity.boundingBox.b(x, y, z));

View file

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