Add a CreateReason to PortalCreateEvent. Addresses BUKKIT-833

By: Sam Wilson <sam.wilson@gmail.com>
This commit is contained in:
Bukkit/Spigot 2011-12-25 22:11:15 -08:00
parent 860011dcc1
commit 2e383f96df

View file

@ -9,16 +9,19 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
/** /**
* Called when the world attempts to create a matching end to a portal * Called when a portal is created
*/ */
public class PortalCreateEvent extends WorldEvent implements Cancellable { public class PortalCreateEvent extends WorldEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private boolean cancel = false; private boolean cancel = false;
private final ArrayList<Block> blocks = new ArrayList<Block>(); private final ArrayList<Block> blocks = new ArrayList<Block>();
private CreateReason reason = CreateReason.FIRE;
public PortalCreateEvent(final Collection<Block> blocks, final World world) { public PortalCreateEvent(final Collection<Block> blocks, final World world, CreateReason reason) {
super(world); super(world);
this.blocks.addAll(blocks); this.blocks.addAll(blocks);
this.reason = reason;
} }
/** /**
@ -38,6 +41,15 @@ public class PortalCreateEvent extends WorldEvent implements Cancellable {
this.cancel = cancel; this.cancel = cancel;
} }
/**
* Gets the reason for the portal's creation
*
* @return CreateReason for the portal's creation
*/
public CreateReason getReason() {
return reason;
}
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlers;
@ -46,4 +58,18 @@ public class PortalCreateEvent extends WorldEvent implements Cancellable {
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return handlers;
} }
/**
* An enum to specify the various reasons for a portal's creation
*/
public enum CreateReason {
/**
* When a portal is created 'traditionally' due to a portal frame being set on fire.
*/
FIRE,
/**
* When a portal is created as a destination for an existing portal when using the custom PortalTravelAgent
*/
OBC_DESTINATION
}
} }