minecraft Event Listeners in Bukkit Creating an event listener

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

To register your methods, the class containing the EventHandler(s) must implement the Listener interface.

import org.bukkit.event.Listener;

public final class ListenerClass implements Listener {
}

You need to register the event listener by adding the following call to your onEnable method in the class that extends JavaPlugin:

getServer().getPluginManager().registerEvents(new ListenerClass(), this);

To listen to any given event in your listener class, you must create a method with @EventHandler annotation on the method. The event type is specified by the Type in the method's only argument. The method may be named whatever you wish.

import org.bukkit.event.Listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerLoginEvent;  

public class ListenerClass implements Listener {
    @EventHandler
    public void onPlayerLogin(PlayerLoginEvent event) {
        event.getPlayer().sendMessage("Welcome to the server!");
    }
}


Got any minecraft Question?