All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bukkit.event.world.PortalCreateEvent Maven / Gradle / Ivy

package org.bukkit.event.world;

import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Called when a portal is created
 */
public class PortalCreateEvent extends WorldEvent implements Cancellable {
  private static final HandlerList handlers = new HandlerList();
  private final ArrayList blocks = new ArrayList();
  private boolean cancel = false;
  private CreateReason reason = CreateReason.FIRE;

  public PortalCreateEvent(final Collection blocks, final World world, CreateReason reason) {
    super(world);

    this.blocks.addAll(blocks);
    this.reason = reason;
  }

  public static HandlerList getHandlerList() {
    return handlers;
  }

  /**
   * Gets an array list of all the blocks associated with the created portal
   *
   * @return array list of all the blocks associated with the created portal
   */
  public ArrayList getBlocks() {
    return this.blocks;
  }

  public boolean isCancelled() {
    return cancel;
  }

  public void setCancelled(boolean 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
  public HandlerList getHandlers() {
    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
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy