Looking for better practise for dependency hooks

Discussion in 'Spigot Plugin Development' started by kangarko, May 16, 2015.

  1. Hello,

    I am improving my plugin, ChatControl, which is using 8+ dependencies (other bukkit plugins). The problem was that the code was too messy and chaotic so I decided to recode it, but it is not so much better now.

    This is an example class that hooks into other bukkit plugin:
    http://pastebin.com/4pJZu4AR

    but the static method is called upon first class reload and I need it to be called on plugin enable, which is done by this unfortunate way:

    Code (Text):
      private void setupDependencies() {
         if (AuthMeHook.HOOKED);
         if (EssentialsHook.HOOKED);
         if (ProtocolLibHook.HOOKED);
         if (MultiverseHook.HOOKED);
         if (RushCoreHook.HOOKED);
         if (SimpleClansHook.HOOKED);
         if (TownyHook.HOOKED);
         if (VaultHook.HOOKED);
         //etc..
       }
    Do you have any advice on improval? How do you manage many dependencies? Notice I would like to keep the static access.
     
  2. Static boolean...static blocks. The former is bad practice since you shouldn't need to use the static access. The latter is a code smell.
     
  3. Yes, remove the static part. It will both make your reloads easier and improve the quality of your plugin.
     
  4. Thanks, can you provide me same example? I would like to have dependency management in one class, not like it was before that 2/3 was in ChatFormatter and 1/3 in the main class.
     
  5. Create another class for the hooks which is run onEnable()?
     
  6. Why the static access degrades the plugin quality? Reload is not fully supported, either, and so far I did not get any problems with the new system.