Listeners...?

Discussion in 'Plugin Development' started by 1Achmed1, Sep 21, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    1Achmed1

    So, I'm working on an update for my plugin, but it needs a listener. I've setup a second class for the listener, but I cant seem to figure out how to send events there. I've used code from the Event API Reference wiki article and still get errors.

    Here's my listener class (minus the listener):
    Code:java
    1. import org.bukkit.ChatColor;
    2. import org.bukkit.entity.Player;
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.block.SignChangeEvent;
    6.  
    7. public class Listener implements Listener {
    8. public static BetterMOTdMain plugin;
    9.  
    10. public Listener(BetterMOTdMain instance) {
    11. plugin = instance;
    12. }
    13.  


    And my main class (minus imports, and unimportant stuff):
    Code:java
    1. public class BetterMOTdMain extends JavaPlugin {
    2.  
    3. @Override
    4. public void onEnable() {
    5. getServer().getPluginManager().registerEvents(new Listener(), this);
    6. }
    7.  
     
  2. 1Achmed1 Don't name your listener class Listener, and to 'listen' just do:
    Code:java
    1.  
    2. @EventHandler
    3. public void onEvent(EventToListenHere event){
    4. //do stuff
    5. }
    6.  


    Also you're getting an error because java thinks your implementing a class to itself.
     
  3. Offline

    1Achmed1

    Tyyy :D

    EDIT: I know how to listen. I just want to know how to make my main class send events to my listener class

    RE-EDIT: I figured out the proper way to do this :)
     
Thread Status:
Not open for further replies.

Share This Page