Solved onEnable() in multiple classes?

Discussion in 'Plugin Development' started by Minecraft Frontiers, Dec 6, 2014.

Thread Status:
Not open for further replies.
  1. Is it possible to use onEnable() in multiple classes at once?

    I would love my plugin to broadcast a message (or log into the console) when the plugin starts up. This works well from the onEnable() in the main class. However when I use onEnable() in other classes, it isn't being called.

    As a workaround, I could put all my broadcasts into the main class. On the other hand, it would feel much cleaner to have my broadcasts spread across all my classes instead.
     
  2. Offline

    Avygeil

    Minecraft Frontiers You mean like having multiple modules that would act like plugins while being in a main plugin?
    Just make a onEnable method in other classes and call it from the main one.
     
  3. Offline

    Skionz

    Minecraft Frontiers It isn't working because your other classes do not extend the JavaPlugin class and if they did an exception would be thrown. As Avygeil said, you can always invoke a method from your other class onEnable.
     
  4. I literally just want to run blocks of code that happen when the plugin is loaded. But instead of having all of these blocks in the main class, I want to put them into my other classes for "housekeeping" purposes.

    So the plugin would look like this:

    Main Class - broadcasts "Plugin loaded!"
    Class 1 - broadcasts "Class 1 loaded!"
    Class 2 - broadcasts "Class 2 loaded!"


    Ah, that is true. They don't extend that. So is there no way of running a code "on plugin start" from other classes than the main one?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  5. Offline

    Skionz

    Minecraft Frontiers Create an instance of your other classes and create the method onEnable. Then when the plugin is actually enabled invoke it like this
    Code:
    yourClassInstance.onEnable();
     
  6. Oh I see. Thank you. :)
     
    Skionz likes this.
Thread Status:
Not open for further replies.

Share This Page