001 package org.bukkit.event.world; 002 003 import org.bukkit.block.Block; 004 import org.bukkit.World; 005 import org.bukkit.event.Cancellable; 006 import org.bukkit.event.HandlerList; 007 008 import java.util.ArrayList; 009 import java.util.Collection; 010 011 /** 012 * Called when a portal is created 013 */ 014 public class PortalCreateEvent extends WorldEvent implements Cancellable { 015 private static final HandlerList handlers = new HandlerList(); 016 private boolean cancel = false; 017 private final ArrayList<Block> blocks = new ArrayList<Block>(); 018 private CreateReason reason = CreateReason.FIRE; 019 020 public PortalCreateEvent(final Collection<Block> blocks, final World world, CreateReason reason) { 021 super(world); 022 023 this.blocks.addAll(blocks); 024 this.reason = reason; 025 } 026 027 /** 028 * Gets an array list of all the blocks associated with the created portal 029 * 030 * @return array list of all the blocks associated with the created portal 031 */ 032 public ArrayList<Block> getBlocks() { 033 return this.blocks; 034 } 035 036 public boolean isCancelled() { 037 return cancel; 038 } 039 040 public void setCancelled(boolean cancel) { 041 this.cancel = cancel; 042 } 043 044 /** 045 * Gets the reason for the portal's creation 046 * 047 * @return CreateReason for the portal's creation 048 */ 049 public CreateReason getReason() { 050 return reason; 051 } 052 053 @Override 054 public HandlerList getHandlers() { 055 return handlers; 056 } 057 058 public static HandlerList getHandlerList() { 059 return handlers; 060 } 061 062 /** 063 * An enum to specify the various reasons for a portal's creation 064 */ 065 public enum CreateReason { 066 /** 067 * When a portal is created 'traditionally' due to a portal frame 068 * being set on fire. 069 */ 070 FIRE, 071 /** 072 * When a portal is created as a destination for an existing portal 073 * when using the custom PortalTravelAgent 074 */ 075 OBC_DESTINATION 076 } 077 }