Class StormEventDispatcher

java.lang.Object
io.pzstorm.storm.event.StormEventDispatcher

public class StormEventDispatcher extends Object
This class is responsible for registering event handlers and dispatching ZomboidEvent instances.

To register an event handler call one of the following methods:

All methods in registered event handlers annotated with 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 Details

    • StormEventDispatcher

      public StormEventDispatcher()
  • Method Details

    • registerEventHandler

      public static void registerEventHandler(Class<?> handlerClass)
      Register all static methods subscribed with SubscribeEvent annotation in the given Class 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 see StormEventDispatcher class documentation for more information.
      Parameters:
      handlerClass - Class of the event handler to register.
      Throws:
      IllegalArgumentException - if any subscribing method declared in handler is not declared as static, if the any subscribing method does not have exactly one argument or the argument is not an instance of ZomboidEvent.
      See Also:
    • registerEventHandler

      public static void registerEventHandler(Object handler)
      Register all instance methods subscribed with SubscribeEvent annotation 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 see StormEventDispatcher class documentation for more information.
      Parameters:
      handler - instance of the event handler to register.
      Throws:
      IllegalArgumentException - if any subscribing method declared in handler is declared as static, if the any subscribing method does not have exactly one argument or the argument is not an instance of ZomboidEvent.
      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 calls dispatchEvent(ZomboidEvent) method. This is a convenience method intended to be used only by StormHook implementations to get a list of instructions that represents a dispatch call for given event.
      Parameters:
      eventConstructorInsn - list of instructions that represent constructing a new ZomboidEvent instance and adding the result to the stack. These instructions will be transferred to the start of the resulting instruction list.
      See Also:
    • dispatchEvent

      public static void dispatchEvent(ZomboidEvent event)
      Dispatch the given event to all methods registered in dispatch registry. This is an internal method only called by StormHook implementations installed in game code.
      Parameters:
      event - ZomboidEvent to dispatch.
      See Also: