Listeners & Events

The JeakBot framework is built around events. Events can be fired by anyone and received by any compatible registered listener.
They are used to establish a loose flow of data from event emitters to listeners.

What is a listener?

Listeners are instances of classes that have at least one matching method annotated with @Listener
A listener method has the following signature: void <name>(<? extends IEvent> event);
In words:

  • Void return type (no return value)
  • One argument of type IEvent or a subinterface
    When a listener is registered, these methods will be the ones receiving the event.

How to register a listener?

To register a listener, call IEventService#registerListener(Object listener) from anywhere in your code.
You can register multiple listeners by using the convenience method #registerListeners(Object... listeners).



Plugin instances are automatically registered as a listener!

When will a listener method be fired?

The event service decides what methods will be called based on their parameter type.
If the event type is compatible with the parameter type (as defined by Class#isAssignableFrom), the method will be called.
That means that a IPreConnectEvent will be received by listeners on IPreConnectEvent as-well as listeners on IBotStateEvent (as they are less specific and compatible) and so on.

What’s Next