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)
Asked
Active
Viewed 231 times
-2
-
Please look at the wiki. It explains everything. – Aug 24 '14 at 15:24
-
Welcome to [so]. Questions here should __show research effort or attempts__. Please take a __[tour]__. – Unihedron Aug 25 '14 at 04:31
1 Answers
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.