Solved Secondary class not registering onEnable() event.

Discussion in 'Spigot Plugin Development' started by zach_attack, Jul 25, 2018.

Thread Status:
Not open for further replies.
  1. I'm not the best person when it comes down to java, but recently I tried splitting an onEnable event between two classes. Unfortunately, the second class is taking absolutely zero action. I have reason to believe it's an issue with how I imported it in my main.

    Secondary Class.
    Code (Java):
    (Main class imported at top)

    public class Messages implements Listener {
        private Main plugin;
        public void onEnable(){
            // Stuff I want to work yada yada
    }
     

    Main Class
    Code (Java):

    (Secondary Class imported at top)

    public class Main
      extends JavaPlugin
      implements Listener {

      public void onEnable() {
          Bukkit.getPluginManager().registerEvents(new Messages(), this)
    }
     

    Any help on the matter would be greatly appreciated. I am an actual noob when it comes to using multiple classes. :)
     
  2. Well for one, you're missing some brackets
     
    • Funny Funny x 1
  3. why would u split the onenable event? do you want code to happen when the messages class is enabled?
    if so just do
    Code (Text):
    public Messages() { }
    instead of the onenable inside the messages class
     
    • Winner Winner x 1

  4. If you don't want what Fizmo said but you can't get the class working then you shouldn't be using onEnable in that class and that's what your code should look like in the second class

    Code (Java):

    public class Messages implements Listener {

        private Main plugin = Main.getPlugin(Main.class);

        // Stuff I want to work yada yada
    }
     
    And for declaring
     
    • Useful Useful x 1
  5. I'm aware of the bracket issue. It's just more or less for demonstration purposes :)

    That was silly of me to split the event. Your solution worked for me perfectly. Thanks :)

    Also thank you for the clarification ;)
     
    • Like Like x 1
Thread Status:
Not open for further replies.