Event Listener
EventService
In Reactant, we are using another way to listen to the events which is slightly different from Bukkit's way.
Reactant provided a component called EventService
, it can provide the Observable of the Bukkit events.
We have learned how to inject other components at the previous tutorial, it is your turns to try it.
Event Observable
Now we have got the EventService
,
let's try to listen to the PlayerEggThrowEvent
and send a message to the thrower.
Event Priority and Ignore Cancelled
More about Event Observable
Handling events is annoying, but you can use the operators of Observable of ReactiveX to make your lives easier. If you are wondering what can be done with the operators, check the diagrams from ReactiveX documentation and RxMarble.
Following are some examples for your reference.
Event Filtering
Filter is a useful operator for filtering the events you are interested in.
Simple Cooldown
Some time we want to make a cooldown time for the skills. With ReactiveX, we can easily create an elegant solution to count the cooldown.
Following is an example to make 10 seconds cooldown for each fart ;D
- Group the observable by the player, so that each player has its own sneak event observable.
- Map for each grouped observables: only
- For each grouped observables, throttle first event for each 10 second, then flatMap will flatten the grouped observables into single observable