Class EventManager

java.lang.Object
com.avrix.events.EventManager

public class EventManager extends Object
Manages Event subscriptions and their raising. Allows objects to register themselves as listeners for specific events and raise those events dynamically.
  • Constructor Details

    • EventManager

      public EventManager()
  • Method Details

    • getAllListeners

      public static Map<String,List<EventManager.EventListener>> getAllListeners()
      Returns a copy of all registered listeners for all events.
      Returns:
      A copy of the listener HashMap, where the key is the event name and the value is the List of listeners for that event.
    • getListenersForEvent

      public static List<EventManager.EventListener> getListenersForEvent(String eventName)
      Returns a List of listeners for the specified event.
      Parameters:
      eventName - The name of the event for which you want to get a List of listeners.
      Returns:
      A List of listeners for the specified event, or null if no listeners are registered for the given event.
    • clearAllListeners

      public static void clearAllListeners()
      Clears all registered event listeners.
    • clearListenersForEvent

      public static void clearListenersForEvent(String eventName)
      Clears all registered event listeners for a specific event.
      Parameters:
      eventName - The name of the event to clear listeners for.
    • addListener

      public static void addListener(Event listener, Priority priority)
      Registers a listener object for a specific event.
      Parameters:
      listener - Event listener. Must have a handleEvent method with a signature corresponding to the event.
      priority - Priority, events with lower priority are called last
    • addListener

      public static void addListener(Event listener)
      Registers a listener object for a specific event. Handler priority is set to NORMAL
      Parameters:
      listener - Event listener. Must have a handleEvent method with a signature corresponding to the event.
    • invokeEvent

      public static void invokeEvent(String eventName, Object... args)
      Raises an event by its name, passing arguments to listeners registered for that event. The method dynamically looks up and calls the handleEvent method on each event listener, passing the specified arguments. If an error occurs during a call, it is logged and the process continues for the remaining listeners.
      Parameters:
      eventName - The name of the event to raise. The event name is case insensitive.
      args - Arguments to be passed to the event listener's handleEvent method. The type and number of arguments must match the expected parameters of the handleEvent method.