Package dev.prozilla.pine.common.event
Class EventDispatcher<EventType extends Enum<EventType>,Target,E extends Event<EventType,? super Target>>
java.lang.Object
dev.prozilla.pine.common.event.EventDispatcher<EventType,Target,E>
- Type Parameters:
E
- The type of event this object can dispatch
- All Implemented Interfaces:
EventDispatcherContext<EventType,
,Target, E> Destructible
- Direct Known Subclasses:
AssetPoolEventDispatcher
,NodeEventDispatcher
,SimpleEventDispatcher
public abstract class EventDispatcher<EventType extends Enum<EventType>,Target,E extends Event<EventType,? super Target>>
extends Object
implements EventDispatcherContext<EventType,Target,E>, Destructible
Represents an object that can dispatch events.
-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.prozilla.pine.common.event.EventDispatcherContext
EventDispatcherContext.EphemeralEventListener<EventType extends Enum<EventType>,
E extends Event<EventType, ?>> -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddListener
(EventType eventType, EventListener<E> listener) Adds a listener that listens to a given type of event.protected abstract E
createEvent
(EventType eventType, Target target) Creates an event of a given type with a given target.void
destroy()
Removes all listeners.protected Logger
protected void
Invokes an event.void
Invokes the event of a given type with a given target.protected void
Propagates the event to other objects in relation to the target object.void
removeListener
(EventType eventType, EventListener<E> listener) Removes a listener that was listening to a given type of event.void
Sets the logger of this event dispatcher, which is used to log errors thrown by listeners.protected boolean
protected boolean
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface dev.prozilla.pine.common.event.EventDispatcherContext
addListener, addTargetedListener, off, on, once
-
Field Details
-
logger
-
-
Constructor Details
-
EventDispatcher
public EventDispatcher()
-
-
Method Details
-
addListener
Description copied from interface:EventDispatcherContext
Adds a listener that listens to a given type of event.Unicity is not required. If a listener is added multiple times, it will be called multiple times per event.
- Specified by:
addListener
in interfaceEventDispatcherContext<EventType extends Enum<EventType>,
Target, E extends Event<EventType, ? super Target>> - Parameters:
eventType
- The type of event to listen tolistener
- The listener to add- Returns:
- The listener that was added.
-
removeListener
Description copied from interface:EventDispatcherContext
Removes a listener that was listening to a given type of event.- Specified by:
removeListener
in interfaceEventDispatcherContext<EventType extends Enum<EventType>,
Target, E extends Event<EventType, ? super Target>> - Parameters:
eventType
- The type of event that was being listened tolistener
- The listener to remove
-
invoke
Description copied from interface:EventDispatcherContext
Invokes the event of a given type with a given target. -
createEvent
Creates an event of a given type with a given target.- Parameters:
eventType
- The type of event to createtarget
- The target of the event- Returns:
- The new event
-
invoke
Invokes an event.- Parameters:
event
- The event to invoke
-
shouldInvoke
protected boolean shouldInvoke() -
shouldPropagate
protected boolean shouldPropagate() -
propagate
Propagates the event to other objects in relation to the target object. This method is called after the event has been invoked, unless the propagation was stopped.The default implementation does nothing.
- Parameters:
event
- The event to propagate
-
setLogger
Sets the logger of this event dispatcher, which is used to log errors thrown by listeners. -
getLogger
-
destroy
public void destroy()Removes all listeners.- Specified by:
destroy
in interfaceDestructible
-