Class Event

java.lang.Object
org.bukkit.event.Event
Direct Known Subclasses:
AsyncPlayerPreLoginEvent, AsyncTabCompleteEvent, BlockEvent, EntityEvent, ExecuteCommandEvent, FillProfileEvent, GS4QueryEvent, HangingEvent, InventoryEvent, InventoryMoveItemEvent, InventoryPickupItemEvent, LookupProfileEvent, NetworkItemSerializeEvent, PlayerConnectionCloseEvent, PlayerEvent, PlayerHandshakeEvent, PlayerLeashEntityEvent, PlayerPreLoginEvent, PreCreatureSpawnEvent, PreFillProfileEvent, PreLookupProfileEvent, ProfileWhitelistVerifyEvent, ServerEvent, ServerExceptionEvent, ServerTickEndEvent, ServerTickStartEvent, TabCompleteEvent, ThrownEggHatchEvent, UnknownCommandEvent, VehicleEvent, WeatherEvent, WhitelistStateUpdateEvent, WhitelistToggleEvent, WorldEvent

public abstract class Event extends Object
Represents an event. All events require a static method named getHandlerList() which returns the same HandlerList as getHandlers().
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    The default constructor is defined for cleaner code.
    Event(boolean isAsync)
    This constructor is used to explicitly declare an event as synchronous or asynchronous.
    Event(TriState isAsync)
    This constructor is used to explicitly declare an event as synchronous or asynchronous or potentially unset.
  • Method Summary

    Modifier and Type
    Method
    Description
    final TriState
    Returns a tristate that, when resolving to true or false, has the exact indications defined by isAsynchronous().
    boolean
    Calls the event and tests if cancelled.
    Convenience method for providing a user-friendly identifier.
     
    final boolean
    Any custom event that should not by synchronized with other events must use the specific constructor.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Event

      public Event()
      The default constructor is defined for cleaner code. This constructor assumes the event is synchronous.
    • Event

      public Event(boolean isAsync)
      This constructor is used to explicitly declare an event as synchronous or asynchronous.
      Parameters:
      isAsync - true indicates the event will fire asynchronously, false by default from default constructor
    • Event

      public Event(@NotNull TriState isAsync)
      This constructor is used to explicitly declare an event as synchronous or asynchronous or potentially unset.
      Parameters:
      isAsync - true indicates the event will fire asynchronously, false by default from default constructor, unset indicates that the event may be called on either the server thread or off the server thread.
  • Method Details

    • asynchronous

      @NotNull public final TriState asynchronous()
      Returns a tristate that, when resolving to true or false, has the exact indications defined by isAsynchronous().

      If the tristate resolves to NOT_SET, the event may or may not have been fired off the main thread, meaning a plugin would have to validate what thread the spigot event bus was called on.

      Returns:
      the tristate enum.
    • callEvent

      public boolean callEvent()
      Calls the event and tests if cancelled.
      Returns:
      false if event was cancelled, if cancellable. otherwise true.
    • getEventName

      @NotNull public @NotNull String getEventName()
      Convenience method for providing a user-friendly identifier. By default, it is the event's class's simple name.
      Returns:
      name of this event
    • getHandlers

      @NotNull public abstract @NotNull HandlerList getHandlers()
    • isAsynchronous

      public final boolean isAsynchronous()
      Any custom event that should not by synchronized with other events must use the specific constructor. These are the caveats of using an asynchronous event:
      • The event is never fired from inside code triggered by a synchronous event. Attempting to do so results in an IllegalStateException.
      • However, asynchronous event handlers may fire synchronous or asynchronous events
      • The event may be fired multiple times simultaneously and in any order.
      • Any newly registered or unregistered handler is ignored after an event starts execution.
      • The handlers for this event may block for any length of time.
      • Some implementations may selectively declare a specific event use as asynchronous. This behavior should be clearly defined.
      • Asynchronous calls are not calculated in the plugin timing system.
      Returns:
      false by default, true if the event fires asynchronously