From c5392313d3097b2611749701950e3bf1510f617d Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 14 Dec 2012 02:55:41 -0700 Subject: [PATCH] [Bleeding] Add experimental support for entity portal traveling EntityPortalEvent is called when an entity is about to portal to a new location. This event is cancellable on top of being able to change the exit location. EntityPortalExitEvent is called when exiting the portal, allowing for adjustment of the exit velocity. By: EdGruberman --- .../event/entity/EntityPortalEnterEvent.java | 2 +- .../event/entity/EntityPortalEvent.java | 47 +++++++++++++++ .../event/entity/EntityPortalExitEvent.java | 58 +++++++++++++++++++ .../event/player/PlayerPortalEvent.java | 2 +- 4 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 paper-api/src/main/java/org/bukkit/event/entity/EntityPortalEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/entity/EntityPortalExitEvent.java diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java index 384d5db40c..87d57b0130 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java @@ -5,7 +5,7 @@ import org.bukkit.Location; import org.bukkit.event.HandlerList; /** - * Stores data for entities standing inside a portal block + * Called when an entity comes into contact with a portal */ public class EntityPortalEnterEvent extends EntityEvent { private static final HandlerList handlers = new HandlerList(); diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityPortalEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityPortalEvent.java new file mode 100644 index 0000000000..8767243a6c --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityPortalEvent.java @@ -0,0 +1,47 @@ +package org.bukkit.event.entity; + +import org.bukkit.Location; +import org.bukkit.TravelAgent; +import org.bukkit.entity.Entity; +import org.bukkit.event.HandlerList; + +/** + * Called when a non-player entity is about to teleport because it is in contact with a portal + *

+ * For players see {@link org.bukkit.event.player.PlayerPortalEvent PlayerPortalEvent} + */ +public class EntityPortalEvent extends EntityTeleportEvent { + private static final HandlerList handlers = new HandlerList(); + protected boolean useTravelAgent = true; + protected TravelAgent travelAgent; + + public EntityPortalEvent(final Entity entity, final Location from, final Location to, final TravelAgent pta) { + super(entity, from, to); + this.travelAgent = pta; + } + + public void useTravelAgent(boolean useTravelAgent) { + this.useTravelAgent = useTravelAgent; + } + + public boolean useTravelAgent() { + return useTravelAgent; + } + + public TravelAgent getPortalTravelAgent() { + return this.travelAgent; + } + + public void setPortalTravelAgent(TravelAgent travelAgent) { + this.travelAgent = travelAgent; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} \ No newline at end of file diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityPortalExitEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityPortalExitEvent.java new file mode 100644 index 0000000000..8e69e3bea8 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityPortalExitEvent.java @@ -0,0 +1,58 @@ +package org.bukkit.event.entity; + +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.event.HandlerList; +import org.bukkit.util.Vector; + +/** + * Called before an entity exits a portal. + *

+ * This event allows you to modify the velocity of the entity after they + * have successfully exeted the portal. + */ +public class EntityPortalExitEvent extends EntityTeleportEvent { + private static final HandlerList handlers = new HandlerList(); + private Vector before; + private Vector after; + + public EntityPortalExitEvent(final Entity entity, final Location from, final Location to, final Vector before, final Vector after) { + super(entity, from, to); + this.before = before; + this.after = after; + } + + /** + * Gets a copy of the velocity that the entity has before entering the portal. + * + * @return velocity of entity before entering portal + */ + public Vector getBefore() { + return this.before.clone(); + } + + /** + * Gets a copy of the velocity that the entity will have after exiting the portal. + * + * @return velocity of entity after exiting portal + */ + public Vector getAfter() { + return this.after.clone(); + } + + /** + * Sets the velocity that the entity will have after exiting the portal. + */ + public void setAfter(Vector after) { + this.after = after.clone(); + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} \ No newline at end of file diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerPortalEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerPortalEvent.java index a243b538d2..1114f5c719 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerPortalEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerPortalEvent.java @@ -6,7 +6,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; /** - * Called when a player completes the portaling process by standing in a portal + * Called when a player is about to teleport because it is in contact with a portal */ public class PlayerPortalEvent extends PlayerTeleportEvent { private static final HandlerList handlers = new HandlerList();