1 Events
NotMyFault edited this page 2021-04-27 17:51:35 +02:00

PlotSquared uses the Guava EventBus to register listeners and dispatch events.

Event List

Events can be found at https://github.com/IntellectualSites/PlotSquared/tree/v5/Core/src/main/java/com/plotsquared/core/events

Registering a Listener

Registering a listener is super easy. Add the @Subscribe annotation to any methods that are listening to events, register the class with the EventBus through PlotAPI#registerListener(Class) and you're done!

public class P2Listener {

  public void P2Listener(PlotAPI api) {
    api.registerListener(this)
  }

  @Subscribe
  public void onPlayerEnterPlot(PlayerEnterPlotEvent e) {
    //do stuff
  }
}

An alternative to the above would be to register the listener elsewhere, for example:

public class MyPlugin extends JavaPlugin {

	@Override
	public void onEnable() {
		PlotAPI plotApi = new PlotAPI();
		api.registerListener(new P2Listener());
	}

}

public class P2Listener {

  @Subscribe
  public void onPlayerEnterPlot(PlayerEnterPlotEvent e) {
    //do stuff
  }
  
}