Interface Events
@NonExtendable
public interface Events
Registration of event listeners. Listeners of one event run in registration order. A listener
that throws is logged with the mod's id; one that throws repeatedly is removed.
-
Method Summary
Modifier and TypeMethodDescription<E extends Event>
Subscriptionlistenerruns on the main thread while the event is posted.<E extends Event>
SubscriptiononModThread(Class<E> type, Consumer<? super E> listener) listenerruns later on the mod's own thread.Registers the methods oflistenerannotated withOnMain,OnModThread, orOnClientCommand, asonMain(Class, Consumer)andonModThread(Class, Consumer)do, and schedules those annotated withEveryorEveryNTicks.
-
Method Details
-
onMain
listenerruns on the main thread while the event is posted. It may touch game objects and must return quickly: it runs inside the tick. -
onModThread
listenerruns later on the mod's own thread. It must not touch game objects; main-thread work goes throughmain().- Throws:
IllegalArgumentException- whentypeis aMainThreadEvent
-
register
Registers the methods oflistenerannotated withOnMain,OnModThread, orOnClientCommand, asonMain(Class, Consumer)andonModThread(Class, Consumer)do, and schedules those annotated withEveryorEveryNTicks. ZomboidForge registers the mod's entry point this way after its constructor and beforeMod.onLoad(); other objects opt in through this method.Each annotated method:
- returns
void. A listener has one parameter, a class that implementsEventand is neither abstract nor an interface, because listeners are matched by the event's exact class; a scheduled method has none; - carries one of the annotations;
OnModThreadnot for aMainThreadEvent,OnClientCommandonly for aClientCommandEvent; - may be static, private, and declared in a superclass of
listener's class. An instance method that a subclass overrides listens only when the override carries the annotation itself.
- Returns:
- one subscription for every listener and scheduled method of
listener; cancelling it allows registeringlisteneragain - Throws:
IllegalArgumentException- listing every method that breaks a rule, when a class the methods name cannot be loaded, or whenlisteneris registered already
- returns
-