This repository has been archived by the owner on Jul 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Events
Hannes Greule edited this page Jul 27, 2021
·
4 revisions
PlotSquared uses the Guava EventBus to register listeners and dispatch events.
Events can be found at https://github.com/IntellectualSites/PlotSquared/tree/v6/Core/src/main/java/com/plotsquared/core/events
Registering a listener is super easy. Add the @Subscribe
(from the com.google.common.eventbus
package) annotation to any methods that are listening to events, register the class with the EventBus through PlotAPI#registerListener(Class)
and you're done! One example:
public class P2Listener {
// if you like the dependency-injection-like approach:
public P2Listener(PlotAPI api) {
api.registerListener(this);
}
// less OOP, but if you want to make things easy:
public P2Listener() {
PlotAPI api = new PlotAPI();
api.registerListener(this);
}
// A method handling a PlayerEnterPlotEvent
@Subscribe
public void onPlayerEnterPlot(PlayerEnterPlotEvent e) {
//do stuff
}
}