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 Summary
Modifier and Type Method Description default <E extends Event>
voidaddEventCallback(java.lang.Class<E> eventClass, EventCallback<E> eventCallback)
Adds a new event callback for the specified typeeventClass
.default <E extends CancellableEvent>
voidcallCancellableEvent(java.lang.Class<E> eventClass, E event, java.lang.Runnable successCallback)
default <E extends Event>
voidcallEvent(java.lang.Class<E> eventClass, E event)
Calls the specifiedEvent
with all the assignedEventCallback
.default java.util.stream.Stream<EventCallback>
getEventCallbacks()
default <E extends Event>
java.util.Collection<EventCallback>getEventCallbacks(java.lang.Class<E> eventClass)
Gets the event callbacks of a specific event type.java.util.Map<java.lang.Class<? extends Event>,java.util.Collection<EventCallback>>
getEventCallbacksMap()
Gets aMap
containing all the listeners assigned to a specificEvent
type.default <E extends Event>
voidremoveEventCallback(java.lang.Class<E> eventClass, EventCallback<E> eventCallback)
Removes an event callback.
-
Method Details
-
getEventCallbacksMap
@NotNull java.util.Map<java.lang.Class<? extends Event>,java.util.Collection<EventCallback>> getEventCallbacksMap()Gets aMap
containing all the listeners assigned to a specificEvent
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 typeeventClass
.- Type Parameters:
E
- the event type- Parameters:
eventClass
- the event classeventCallback
- 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 classeventCallback
- 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
- Returns:
- a
Stream
containing all the callbacks
-
callEvent
Calls the specifiedEvent
with all the assignedEventCallback
.Events are always called in the current thread.
- Type Parameters:
E
- the event type- Parameters:
eventClass
- the event classevent
- 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 aCancellableEvent
and executesuccessCallback
if theEvent
is not cancelled.Does call
callEvent(Class, Event)
internally.- Type Parameters:
E
- the event type- Parameters:
eventClass
- the event classevent
- the event objectsuccessCallback
- the callback called when the event is not cancelled- See Also:
callEvent(Class, Event)
-