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!");
}
}