Interface EventHandler

All Known Implementing Classes:
Entity, EntityAreaEffectCloud, EntityArmorStand, EntityBat, EntityBee, EntityBlaze, EntityBoat, EntityCat, EntityCaveSpider, EntityChicken, EntityCow, EntityCreature, EntityCreeper, EntityDolphin, EntityEndermite, EntityEyeOfEnder, EntityFox, EntityGhast, EntityGiant, EntityGuardian, EntityIronGolem, EntityItemFrame, EntityMooshroom, EntityOcelot, EntityPanda, EntityPhantom, EntityPig, EntityPolarBear, EntityPotion, EntityRabbit, EntitySilverfish, EntitySlime, EntitySnowman, EntitySpider, EntityWitch, EntityZombie, EntityZombifiedPiglin, ExperienceOrb, FakePlayer, Instance, InstanceContainer, ItemEntity, LivingEntity, ObjectEntity, Player, SharedInstance

public interface EventHandler
Represents an element which can have Event listeners assigned to it.
  • Method Details

    • getEventCallbacksMap

      @NotNull java.util.Map<java.lang.Class<? extends Event>,​java.util.Collection<EventCallback>> getEventCallbacksMap()
      Gets a Map containing all the listeners assigned to a specific Event type.
      Returns:
      a Map with all the listeners
    • addEventCallback

      default <E extends Event> void addEventCallback​(@NotNull java.lang.Class<E> eventClass, @NotNull EventCallback<E> eventCallback)
      Adds a new event callback for the specified type eventClass.
      Type Parameters:
      E - the event type
      Parameters:
      eventClass - the event class
      eventCallback - the event callback
    • removeEventCallback

      default <E extends Event> void removeEventCallback​(@NotNull java.lang.Class<E> eventClass, @NotNull EventCallback<E> eventCallback)
      Removes an event callback.
      Type Parameters:
      E - the event type
      Parameters:
      eventClass - the event class
      eventCallback - the event callback
    • getEventCallbacks

      @NotNull default <E extends Event> java.util.Collection<EventCallback> getEventCallbacks​(@NotNull java.lang.Class<E> eventClass)
      Gets the event callbacks of a specific event type.
      Type Parameters:
      E - the event type
      Parameters:
      eventClass - the event class
      Returns:
      all event callbacks for the specified type eventClass
    • getEventCallbacks

      @NotNull default java.util.stream.Stream<EventCallback> getEventCallbacks()
      Gets a Stream containing all the EventCallback, no matter to which Event they are linked.
      Returns:
      a Stream containing all the callbacks
    • callEvent

      default <E extends Event> void callEvent​(@NotNull java.lang.Class<E> eventClass, @NotNull E event)
      Calls the specified Event with all the assigned EventCallback.

      Events are always called in the current thread.

      Type Parameters:
      E - the event type
      Parameters:
      eventClass - the event class
      event - the event object
    • callCancellableEvent

      default <E extends CancellableEvent> void callCancellableEvent​(@NotNull java.lang.Class<E> eventClass, @NotNull E event, @NotNull java.lang.Runnable successCallback)
      Calls a CancellableEvent and execute successCallback if the Event is not cancelled.

      Does call callEvent(Class, Event) internally.

      Type Parameters:
      E - the event type
      Parameters:
      eventClass - the event class
      event - the event object
      successCallback - the callback called when the event is not cancelled
      See Also:
      callEvent(Class, Event)