diff options
Diffstat (limited to 'src/main/java/org')
3 files changed, 62 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/command/defaults/TeleportCommand.java b/src/main/java/org/bukkit/command/defaults/TeleportCommand.java index 0cc63cfd..42ab9fd5 100644 --- a/src/main/java/org/bukkit/command/defaults/TeleportCommand.java +++ b/src/main/java/org/bukkit/command/defaults/TeleportCommand.java @@ -5,6 +5,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class TeleportCommand extends VanillaCommand { public TeleportCommand() { @@ -31,7 +32,7 @@ public class TeleportCommand extends VanillaCommand { sender.sendMessage("Can't find user " + args[1] + ". No tp."); } else { Command.broadcastCommandMessage(sender, "Teleporting " + victim.getName() + " to " + target.getName()); - victim.teleport(target); + victim.teleport(target, TeleportCause.COMMAND); } return true; diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java index 9b0ab70f..eca0a8a2 100644 --- a/src/main/java/org/bukkit/entity/Entity.java +++ b/src/main/java/org/bukkit/entity/Entity.java @@ -8,6 +8,7 @@ import org.bukkit.util.Vector; import java.util.List; import java.util.UUID; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; /** * Represents a base entity in the world @@ -51,6 +52,15 @@ public interface Entity { public boolean teleport(Location location); /** + * Teleports this entity to the given location + * + * @param location New location to teleport this entity to + * @praram cause The cause of this teleportation + * @return <code>true</code> if the teleport was successful + */ + public boolean teleport(Location location, TeleportCause cause); + + /** * Teleports this entity to the target Entity * * @param destination Entity to teleport this entity to @@ -59,6 +69,15 @@ public interface Entity { public boolean teleport(Entity destination); /** + * Teleports this entity to the target Entity + * + * @param destination Entity to teleport this entity to + * @praram cause The cause of this teleportation + * @return <code>true</code> if the teleport was successful + */ + public boolean teleport(Entity destination, TeleportCause cause); + + /** * Returns a list of entities within a bounding box defined by x,y,z centered around player * * @param x Size of the box along x axis diff --git a/src/main/java/org/bukkit/event/player/PlayerTeleportEvent.java b/src/main/java/org/bukkit/event/player/PlayerTeleportEvent.java index 07f520b3..667cb33e 100644 --- a/src/main/java/org/bukkit/event/player/PlayerTeleportEvent.java +++ b/src/main/java/org/bukkit/event/player/PlayerTeleportEvent.java @@ -8,11 +8,52 @@ import org.bukkit.event.Event; * Holds information for player teleport events */ public class PlayerTeleportEvent extends PlayerMoveEvent { + private TeleportCause cause = TeleportCause.UNKNOWN; + public PlayerTeleportEvent(Player player, Location from, Location to) { super(Type.PLAYER_TELEPORT, player, from, to); } + public PlayerTeleportEvent(Player player, Location from, Location to, TeleportCause cause) { + super(Type.PLAYER_TELEPORT, player, from, to); + + this.cause = cause; + } + public PlayerTeleportEvent(final Event.Type type, Player player, Location from, Location to) { super(type, player, from, to); } + + public PlayerTeleportEvent(final Event.Type type, Player player, Location from, Location to, TeleportCause cause) { + super(type, player, from, to); + + this.cause = cause; + } + + /** + * Gets the cause of this teleportation event + * @return Cause of the event + */ + public TeleportCause getCause() { + return cause; + } + + public enum TeleportCause { + /** + * Indicates the teleporation was caused by a player throwing an Ender Pearl + */ + ENDER_PEARL, + /** + * Indicates the teleportation was caused by a player executing a command + */ + COMMAND, + /** + * Indicates the teleportation was caused by a plugin + */ + PLUGIN, + /** + * Indicates the teleportation was caused by an event not covered by this enum + */ + UNKNOWN; + } } |