Class EventBus

  • All Implemented Interfaces:
    IEventBus

    public class EventBus
    extends java.lang.Object
    implements IEventBus
    Default implementation of IEventBus.
    • Constructor Summary

      Constructors 
      Constructor Description
      EventBus()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T post​(T event)
      Posts an event to all subscribed event listeners.
      void registerLambdaFactory​(java.lang.String packagePrefix, LambdaListener.Factory factory)
      Registers a lambda factory to use with the specified package.
      void subscribe​(java.lang.Class<?> klass)
      Finds all correct (static only) methods with EventHandler annotation and subscribes them.
      void subscribe​(java.lang.Object object)
      Finds all correct (static and non-static) methods with EventHandler annotation and subscribes them.
      void subscribe​(IListener listener)
      Subscribes the listener (both static and non-static).
      void unsubscribe​(java.lang.Class<?> klass)
      Finds all correct (static only) methods with EventHandler annotation and unsubscribes them.
      void unsubscribe​(java.lang.Object object)
      Finds all correct (static and non-static) methods with EventHandler annotation and unsubscribes them.
      void unsubscribe​(IListener listener)
      Unsubscribes the listener (both static and non-static).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • EventBus

        public EventBus()
    • Method Detail

      • registerLambdaFactory

        public void registerLambdaFactory​(java.lang.String packagePrefix,
                                          LambdaListener.Factory factory)
        Description copied from interface: IEventBus
        Registers a lambda factory to use with the specified package.
        Specified by:
        registerLambdaFactory in interface IEventBus
        Parameters:
        packagePrefix - Package prefix that this factory will be used for, eg "meteordevelopment.orbit"
        factory - The factory to use
      • post

        public <T> T post​(T event)
        Description copied from interface: IEventBus
        Posts an event to all subscribed event listeners.
        Specified by:
        post in interface IEventBus
        Type Parameters:
        T - Type of the event
        Parameters:
        event - Event to post
        Returns:
        Event passed in
      • post

        public <T extends ICancellable> T post​(T event)
        Description copied from interface: IEventBus
        Posts a cancellable event to all subscribed event listeners. Stops after the event was cancelled.
        Specified by:
        post in interface IEventBus
        Type Parameters:
        T - Type of the event
        Parameters:
        event - Event to post
        Returns:
        Event passed in
      • subscribe

        public void subscribe​(java.lang.Object object)
        Description copied from interface: IEventBus
        Finds all correct (static and non-static) methods with EventHandler annotation and subscribes them.
        Specified by:
        subscribe in interface IEventBus
        Parameters:
        object - The object to scan for methods
      • subscribe

        public void subscribe​(java.lang.Class<?> klass)
        Description copied from interface: IEventBus
        Finds all correct (static only) methods with EventHandler annotation and subscribes them.
        Specified by:
        subscribe in interface IEventBus
        Parameters:
        klass - The class to scan for methods
      • subscribe

        public void subscribe​(IListener listener)
        Description copied from interface: IEventBus
        Subscribes the listener (both static and non-static).
        Specified by:
        subscribe in interface IEventBus
        Parameters:
        listener - Listener to subscribe
      • unsubscribe

        public void unsubscribe​(java.lang.Object object)
        Description copied from interface: IEventBus
        Finds all correct (static and non-static) methods with EventHandler annotation and unsubscribes them.
        Specified by:
        unsubscribe in interface IEventBus
        Parameters:
        object - The object to scan for methods
      • unsubscribe

        public void unsubscribe​(java.lang.Class<?> klass)
        Description copied from interface: IEventBus
        Finds all correct (static only) methods with EventHandler annotation and unsubscribes them.
        Specified by:
        unsubscribe in interface IEventBus
        Parameters:
        klass - The class to scan for methods
      • unsubscribe

        public void unsubscribe​(IListener listener)
        Description copied from interface: IEventBus
        Unsubscribes the listener (both static and non-static).
        Specified by:
        unsubscribe in interface IEventBus
        Parameters:
        listener - Listener to unsubscribe