how to register your event in the main class

Discussion in 'Spigot Plugin Development' started by rickerd120, Jul 11, 2015.

  1. hi,

    how can i register my event in the main class, the main class is not a event, the event is in a other class called gui.
     
  2. latiku

    Supporter

    Code (Text):
    Bukkit.getServer().getPluginManager().registerEvents(new GUI(), this);
    Try that and it'll work.
     
    • Winner Winner x 1
  3. @rickerd120 Hi, you can just register events like normal only in case of that the main clas listener implements registerEvents(this, this); now would you do registerEvents(new gui(), this);


    EDIT @empshock I saw your post when it refreshed sorry
     
  4. i did put that in the onEnable but it says this; - The method getpluginmanager() is undefined for the type Server
     
  5. but in the main class also CommandExecutor is registered
     
  6. i did put that under onEnable
     
  7. latiku

    Supporter

    I have a solution.
    Code (Text):
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvents(new GUI(), this);
     
  8. yea i know that but still ; The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments (gui, main)
     
  9. latiku

    Supporter

    Check the edit

    EDIT: Sorry, in your Main class make sure it implements Listener and that'll fix the error.
     
  10. nope only the GUI the class called gui not GUI
     
  11. http://pastebin.com/wm7yrjMH <== code of the main class
     
  12. latiku

    Supporter

    I'm sorry, make sure your Main class implements Listener.
     
  13. implements Listener {
    Did you add that to your Listener Class?
     
  14. Have the GUI class implement Listener.
     
  15. latiku

    Supporter

    He needs to implement Listener in his Main and GUI class
     
  16. did that
     
  17. latiku

    Supporter

    sigh
    Implementing Listener usually solves the problem.

    Replace my code in the Main class with:
    Code (Text):
    new GUI(this);
    Then implement the replaced code in your GUI class.
    So, your GUI class code would have the code I mentioned in my last post but it won't be in your Main class
     
  18. You don't need to implement Listener in the Main class, just the Listener class ;)
     
    • Agree Agree x 1