[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 <ed@rjump.com>
This commit is contained in:
Bukkit/Spigot 2012-12-14 02:55:41 -07:00
parent 941e29786e
commit c5392313d3
4 changed files with 107 additions and 2 deletions

View file

@ -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();

View file

@ -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
* <p />
* 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;
}
}

View file

@ -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.
* <p />
* 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;
}
}

View file

@ -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();