Class ApiEventInjector
java.lang.Object
com.seibel.distanthorizons.coreapi.DependencyInjection.DependencyInjector<IDhApiEvent>
com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector
- All Implemented Interfaces:
IDhApiEventInjector
,IDependencyInjector<IDhApiEvent>
public class ApiEventInjector
extends DependencyInjector<IDhApiEvent>
implements IDhApiEventInjector
This class takes care of dependency injection for API events.
-
Field Summary
FieldsFields inherited from class com.seibel.distanthorizons.coreapi.DependencyInjection.DependencyInjector
allowDuplicateBindings, bindableInterface, dependencies
-
Method Summary
Modifier and TypeMethodDescriptionvoid
bind
(Class<? extends IDhApiEvent> abstractEvent, IDhApiEvent eventImplementation) Links the given implementation object to an interface, so it can be referenced later.static <T> DhApiEventParam
<T> createEventParamWrapper
(IDhApiEvent<T> event, T parameter) Wraps the event parameter object in aDhApiCancelableEventParam
orDhApiEventParam
depending on if it should allow cancellation or not.<T,
U extends IDhApiEvent<T>>
booleanfireAllEvents
(Class<U> abstractEventClass, T eventInput) Fires all bound events of the given type (does nothing if no events are bound).boolean
unbind
(Class<? extends IDhApiEvent> abstractEvent, Class<? extends IDhApiEvent> eventClassToRemove) Unlinks the given event handler, preventing the handler from being called in the future.Methods inherited from class com.seibel.distanthorizons.coreapi.DependencyInjection.DependencyInjector
checkIfClassExtends, checkIfClassImplements, clear, get, get, getAll, runDelayedSetup
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IDependencyInjector
checkIfClassExtends, checkIfClassImplements, clear, get, get, getAll, runDelayedSetup
-
Field Details
-
INSTANCE
-
-
Method Details
-
bind
public void bind(Class<? extends IDhApiEvent> abstractEvent, IDhApiEvent eventImplementation) throws IllegalStateException, IllegalArgumentException Description copied from interface:IDependencyInjector
Links the given implementation object to an interface, so it can be referenced later.- Specified by:
bind
in interfaceIDependencyInjector<IDhApiEvent>
- Overrides:
bind
in classDependencyInjector<IDhApiEvent>
- Parameters:
abstractEvent
- The interface (or parent class) the implementation object should implement.eventImplementation
- An object that implements the dependencyInterface interface.- Throws:
IllegalStateException
- if the interface has already been bound and duplicates aren't allowedIllegalArgumentException
- if the implementation object doesn't implement the interface
-
unbind
public boolean unbind(Class<? extends IDhApiEvent> abstractEvent, Class<? extends IDhApiEvent> eventClassToRemove) throws IllegalArgumentException Description copied from interface:IDhApiEventInjector
Unlinks the given event handler, preventing the handler from being called in the future.- Specified by:
unbind
in interfaceIDhApiEventInjector
- Parameters:
abstractEvent
- the base interface for theIDhApiEvent
eventClassToRemove
- the concreteIDhApiEvent
class to remove- Returns:
- true if the handler was unbound, false if the handler wasn't bound.
- Throws:
IllegalArgumentException
- if the implementation object doesn't implement the interface
-
fireAllEvents
public <T,U extends IDhApiEvent<T>> boolean fireAllEvents(Class<U> abstractEventClass, T eventInput) Description copied from interface:IDhApiEventInjector
Fires all bound events of the given type (does nothing if no events are bound).- Specified by:
fireAllEvents
in interfaceIDhApiEventInjector
- Type Parameters:
T
- the parameter type taken by the event handlers.U
- theIDhApiEvent
's class- Parameters:
abstractEventClass
- event typeeventInput
- event parameter- Returns:
- if any of the bound event handlers notified that this event should be canceled.
-
createEventParamWrapper
Wraps the event parameter object in aDhApiCancelableEventParam
orDhApiEventParam
depending on if it should allow cancellation or not.- Type Parameters:
T
- the event parameter type- Parameters:
event
- the event instanceparameter
- the event's parameter object- Returns:
- the event parameter wrapped in a
DhApiCancelableEventParam
orDhApiEventParam
-