Interface EventInvoker<T>
- Type Parameters:
T- the listener type
- All Known Implementing Classes:
EventInvokerImpl
@NonExtendable
public interface EventInvoker<T>
One cross-loader event, identified by its listener type: a functional interface.
Listeners are kept here, in common code, and run in EventPhase order; each loader only fires the event
through invoker(). Events are found by their listener type, like
EventInvoker.lookup(ServerTickEvents.End.class).register(server -> ...);
or through the constant of the class that declares them (ServerTickEvents.END); both are the same event.
Mods declare their own events with create(Class):
public static final EventInvoker<Reloaded> RELOADED = EventInvoker.create(Reloaded.class);
RELOADED.invoker().onReloaded(server);
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> EventInvoker<T> A new event, with listeners combined by the listener method's return type:void: every listener runs;EventResult: listeners run until one interrupts, whose result is returned (elseEventResult.PASS);EventResultHolder: the same, with its value;boolean: listeners run until one returnsfalse. Usecreate(Class, Function)for anything else, or for a hot event that shouldn't go through reflection.static <T> EventInvoker<T> A new event whose invoker is built bycombinerfrom the current listeners, in phase order.booleanbooleanhasListeners(EventPhase.Band band) invoker()Fires the event: calls every listener as the event combines them.invoker(EventPhase.Band band) Fires the event for the listeners of one band only, in phase order: what a loader hook calls from each of its places (before, among and after other mods' listeners).static <T> EventInvoker<T> The event with this listener type.voidregister(EventPhase phase, T listener) Adds a listener in the given phase.default voidAdds a listener in theEventPhase.DEFAULTphase.type()The listener type identifying this event.booleanunregister(T listener) Removes a listener, from whichever phase it was added to.
-
Method Details
-
lookup
The event with this listener type. The class declaring the listener type (for nested types) is initialised first, so its events exist.- Throws:
IllegalArgumentException- when no event has this listener type
-
create
A new event, with listeners combined by the listener method's return type:void: every listener runs;EventResult: listeners run until one interrupts, whose result is returned (elseEventResult.PASS);EventResultHolder: the same, with its value;boolean: listeners run until one returnsfalse.
create(Class, Function)for anything else, or for a hot event that shouldn't go through reflection.- Throws:
IllegalArgumentException- when the type isn't a functional interface, or already has an event
-
create
A new event whose invoker is built bycombinerfrom the current listeners, in phase order. The combiner runs again whenever the listeners change, so the invoker it returns can simply loop over the list.- Throws:
IllegalArgumentException- when the type already has an event
-
type
-
register
Adds a listener in theEventPhase.DEFAULTphase. -
register
Adds a listener in the given phase. For events whose loader hook fires eachEventPhase.Bandat its own place,EventPhase.FIRSTalso runs before other mods' own listeners of the game event andEventPhase.LASTafter them. -
unregister
Removes a listener, from whichever phase it was added to.- Returns:
- whether it was registered
-
hasListeners
boolean hasListeners()- Returns:
- whether the event has any listeners, so a loader can skip building its arguments
-
hasListeners
- Returns:
- whether the event has listeners in phases of this band
-
invoker
T invoker()Fires the event: calls every listener as the event combines them. -
invoker
Fires the event for the listeners of one band only, in phase order: what a loader hook calls from each of its places (before, among and after other mods' listeners). The three bands together areinvoker().
-