This is a quick guide on how to send events to separate classes, rather than your main. Step 1: Create a class to listen on. Make sure it isn't named Listener, or it will throw errors. Step 2: In your main class add the following code to your onEnable method: Code:java getServer().getPluginManager().registerEvents(new MyListener(), this); Be sure to replace "MyListener" with your listener class's name. Step 3: In your listening class add the following code: Code:java public static Main plugin; @EventHandlerpublic void onEvent(EventHere event) { plugin.getServer().getPluginManager().registerEvents(this, plugin);} What this code does is, it tells the Main class that it really is handling the events, and handles them. There are a few things to change: Replace "Main" with your main class Replace "onEvent(EventHere event)" with your event, and its variable. Hope this helped!
1Achmed1 You're doing it completly wrong. What your code now does: whenever event gets fired > register new listener class. Just remove the getServer... line in the listener class and it should be fine. We also have a beautiful tutorial page where this gets explained a little bit better so I'm not entirely sure why we would need this tutorial?
CaptainBern if you remove the getServer... Line un the listener class, it doesn't register correctly. Also, the wiki page about it is a little confusing, and this explains it in steps to make it easier.
"How many times can we register the listener before the server crashes, it's the hit game all the kids are playing!"
1Achmed1 Excuse me sir, everyone here on bukkit will agree with me. You don't have to register listeners inside your listener class. Your code will register itself each time something happens. Like I said before, remove tje getServer line in the listener class. In case you don't know how the event listening system works, let me explain you: when registering a listener bukkit will register that class, then get all the methods that have the @EventHandler annotation and when an event gets fired invoke the methods that have the right event param. Please change this or I report this thread for providing false information. Edit: Also our beloved member md_5 already created a tutorial providing true information: http://forums.bukkit.org/threads/new-event-system.55249/
Locked since subject is already covered by the sticky and as other people said here, this is not the way to register listeners.