From 4272a879f925950f18ddcdeffe124ba9c43e0095 Mon Sep 17 00:00:00 2001 From: craftycreeper Date: Tue, 7 Feb 2012 23:42:43 -0500 Subject: Added EntityTeleportEvent. Fixes BUKKIT-366 --- src/main/java/org/bukkit/event/Event.java | 6 ++ .../bukkit/event/entity/EntityTeleportEvent.java | 79 ++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/main/java/org/bukkit/event/entity/EntityTeleportEvent.java diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java index 8a5035d8..448827b9 100644 --- a/src/main/java/org/bukkit/event/Event.java +++ b/src/main/java/org/bukkit/event/Event.java @@ -825,6 +825,12 @@ public abstract class Event implements Serializable { * @see org.bukkit.event.entity.EndermanPlaceEvent */ ENDERMAN_PLACE(Category.LIVING_ENTITY, EndermanPlaceEvent.class), + /** + * Called when a non-player LivingEntity teleports + * + * @see org.bukkit.event.entity.EntityTeleportEvent + */ + ENTITY_TELEPORT(Category.LIVING_ENTITY, EntityTeleportEvent.class), /** * Called when a human entity's food level changes * diff --git a/src/main/java/org/bukkit/event/entity/EntityTeleportEvent.java b/src/main/java/org/bukkit/event/entity/EntityTeleportEvent.java new file mode 100644 index 00000000..bc588043 --- /dev/null +++ b/src/main/java/org/bukkit/event/entity/EntityTeleportEvent.java @@ -0,0 +1,79 @@ +package org.bukkit.event.entity; + +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +/** + * Thrown when a non-player entity (such as an Enderman) tries to teleport from one + * location to another. + */ +@SuppressWarnings("serial") +public class EntityTeleportEvent extends EntityEvent implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + + private boolean cancel; + private Location from; + private Location to; + + public EntityTeleportEvent(Entity what, Location from, Location to) { + super(Type.ENTITY_TELEPORT, what); + this.from = from; + this.to = to; + this.cancel = false; + } + + public boolean isCancelled() { + return cancel; + } + + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + + /** + * Gets the location that this entity moved from + * + * @return Location this entity moved from + */ + public Location getFrom() { + return from; + } + + /** + * Sets the location that this entity moved from + * + * @param from New location this entity moved from + */ + public void setFrom(Location from) { + this.from = from; + } + + /** + * Gets the location that this entity moved to + * + * @return Location the entity moved to + */ + public Location getTo() { + return to; + } + + /** + * Sets the location that this entity moved to + * + * @param to New Location this entity moved to + */ + public void setTo(Location to) { + this.to = to; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} \ No newline at end of file -- cgit v1.2.3