Package io.pzstorm.storm.event
Class StormEventDispatcher
java.lang.Object
io.pzstorm.storm.event.StormEventDispatcher
This class is responsible for registering event handlers and dispatching
ZomboidEvent instances.
To register an event handler call one of the following methods:
registerEventHandler(Object)- when subscribed methods are instance methods.registerEventHandler(Class)- when subscribed methods are static methods.
SubscribeEvent will be called
by dispatchEvent(ZomboidEvent) method when an appropriate event is created by installed
StormHook. Each subscribed method has to have exactly one parameter that matches the type
of event it wants to subscribe to. For example if a method wanted to subscribe to OnRenderEvent
it would define itself in one of two ways depending on the handler registration method used:
// handler must be registered as a class
public static void handleRenderEvent(OnRenderEvent event) {
...
}
// handler must be registered as an instance
public void handleRenderEvent(OnRenderEvent event) {
...
}
Do not mix static and instance subscribed methods. A registered handler has to have all
subscribed methods declared as either static or instance methods depending on the method used
to register the handler.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.objectweb.asm.tree.InsnListcallDispatchEvent(List<org.objectweb.asm.tree.AbstractInsnNode> eventConstructorInsn) Create and return a list of instructions that callsdispatchEvent(ZomboidEvent)method.static voiddispatchEvent(ZomboidEvent event) Dispatch the given event to all methods registered in dispatch registry.static voidregisterEventHandler(Class<?> handlerClass) Register all static methods subscribed withSubscribeEventannotation in the givenClassto dispatch registry.static voidregisterEventHandler(Object handler) Register all instance methods subscribed withSubscribeEventannotation in the given object instance to dispatch registry.
-
Constructor Details
-
StormEventDispatcher
public StormEventDispatcher()
-
-
Method Details
-
registerEventHandler
Register all static methods subscribed withSubscribeEventannotation in the givenClassto dispatch registry. The registered methods will then be called by dispatched whenever an event they are subscribed to fires. Note that the methods have to be properly defined seeStormEventDispatcherclass documentation for more information.- Parameters:
handlerClass-Classof the event handler to register.- Throws:
IllegalArgumentException- if any subscribing method declared in handler is not declared asstatic, if the any subscribing method does not have exactly one argument or the argument is not an instance ofZomboidEvent.- See Also:
-
registerEventHandler
Register all instance methods subscribed withSubscribeEventannotation in the given object instance to dispatch registry. The registered methods will then be called by dispatched whenever an event they are subscribed to fires. Note that the methods have to be properly defined seeStormEventDispatcherclass documentation for more information.- Parameters:
handler- instance of the event handler to register.- Throws:
IllegalArgumentException- if any subscribing method declared in handler is declared asstatic, if the any subscribing method does not have exactly one argument or the argument is not an instance ofZomboidEvent.- See Also:
-
callDispatchEvent
public static org.objectweb.asm.tree.InsnList callDispatchEvent(List<org.objectweb.asm.tree.AbstractInsnNode> eventConstructorInsn) Create and return a list of instructions that callsdispatchEvent(ZomboidEvent)method. This is a convenience method intended to be used only byStormHookimplementations to get a list of instructions that represents a dispatch call for given event.- Parameters:
eventConstructorInsn- list of instructions that represent constructing a newZomboidEventinstance and adding the result to the stack. These instructions will be transferred to the start of the resulting instruction list.- See Also:
-
dispatchEvent
Dispatch the given event to all methods registered in dispatch registry. This is an internal method only called byStormHookimplementations installed in game code.- Parameters:
event-ZomboidEventto dispatch.- See Also:
-