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 EcreateEvent(EventType eventType, Target target) Creates an event of a given type with a given target.voiddestroy()Removes all listeners.final voiddispatchEvent(EventType eventType, Target target) Equivalent ofEventDispatcherContext.invoke(Enum, Object).protected Loggerprotected voidInvokes an event.voidInvokes the event of a given type with a given target.final voidoff(EventType eventType, EventListener<E> listener) Equivalent ofEventDispatcherContext.removeListener(Enum, EventListener).final EventListener<E> on(EventType eventType, EventListener<E> listener) Equivalent ofEventDispatcherContext.addListener(Enum, EventListener).final EventListener<E> once(EventType eventType, EventListener<E> listener) Equivalent ofEventDispatcherContext.addListener(Enum, EventListener, boolean), where the last argument istrue.protected voidPropagates the event to other objects in relation to the target object.voidremoveListener(EventType eventType, EventListener<E> listener) Removes a listener that was listening to a given type of event.voidSets the logger of this event dispatcher, which is used to log errors thrown by listeners.protected booleanshouldInvoke(EventType eventType) protected booleanshouldPropagate(EventType eventType) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.prozilla.pine.common.event.EventDispatcherContext
addListener, addTargetedListener
-
Field Details
-
logger
-
-
Constructor Details
-
EventDispatcher
public EventDispatcher()
-
-
Method Details
-
on
Description copied from interface:EventDispatcherContextEquivalent ofEventDispatcherContext.addListener(Enum, EventListener). -
off
Description copied from interface:EventDispatcherContextEquivalent ofEventDispatcherContext.removeListener(Enum, EventListener). -
once
Description copied from interface:EventDispatcherContextEquivalent ofEventDispatcherContext.addListener(Enum, EventListener, boolean), where the last argument istrue. -
dispatchEvent
Description copied from interface:EventDispatcherContextEquivalent ofEventDispatcherContext.invoke(Enum, Object).- Specified by:
dispatchEventin interfaceEventDispatcherContext<EventType extends Enum<EventType>,Target, E extends Event<EventType, ? super Target>>
-
addListener
Description copied from interface:EventDispatcherContextAdds 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:
addListenerin 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:EventDispatcherContextRemoves a listener that was listening to a given type of event.- Specified by:
removeListenerin 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:EventDispatcherContextInvokes 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
-
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:
destroyin interfaceDestructible
-