Skip to content

Calling an Event

BrokenEarth edited this page Apr 3, 2019 · 2 revisions

In this page, you'll learn how to call an event. If you have any issues with the wiki, don't hesitate to create a new issue here

Calling an Event

Calling an event will make an EventBus object search event methods within all registered listeners. All events methods listening to the event will be invoked. Suppose you create an event class called PlayerDrinkEvent. There are 3 event methods in two listener classes.

The first listener class is called PlayerEatEventHandler. It contains two event methods: onEat and onEat2. Those methods are listening to PlayerEatEvent. The other listener class is called PlayerDrinkEventHandler. It contains one event method: onDrink. PlayerEatEventHandler and PlayerDrinkEventHandler is registered in one event bus object. If PlayerDrinkEvent is called, onDrink method will be invoked. And if PlayerEatEvent is called, onEat and onEat2 will be called.

Summary

Calling an event is a process in which event methods listening to the event methods are searched and then executed. The listeners containing the event methods should be registered.

How To: Calling an Event

Calling an event is pretty simple, actually. You'll just need to call the callEvent method. The method requires an event object.

example of calling an event

When you run the code, Farted!!! will be printed out.

Summary

To call an event, call EventBus#callEvent(Object).

Clone this wiki locally