-2

i'm trying to create a @EventHandler, but im not sure where im supposed to put it or create a new file? If you could sample some code. (Im new to this)

1 Answers1

1

You can either create a new file or include it in your main plugin file or a separate file. Here is an example using the main file:

public class BukkitExample extends JavaPlugin implements Listener {

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        //Code to execute when a player joins
    }
}

Either way, you will need to implement Listener and register the events with the plugin manager. EventHandler is not a class that you are extending; it is an annotation. You can read the Event API Reference, and check the javadocs for a list of events and their methods.

Unihedron
  • 10,902
  • 13
  • 62
  • 72
Finn
  • 652
  • 7
  • 16