The next method that we will create is an EventHandler
. We use the @EventHandler
annotation to tell Bukkit which of our methods are event listeners. Create a new method that has our event of choice as the only parameter. The method must be public
and it should not return anything. You may name this method anything you wish to, but most programmers will keep the name similar to the name of the event. The following code is an example of the method header:
public void onWeatherChange(WeatherChangeEvent event)
Next, we indicate that this method handles events. Just above the method, add the following annotation:
@EventHandler
On that same line we can modify some properties for the EventHandler
. One property that you are likely to add to all of your EventHandler
methods is to ignore canceled events. If the event is already canceled by another plugin then we don't want to bother listening to it. Setting the ignoreCancelled
property to true
will result in our method looking like...