Plugin 'components'

Discussion in 'Plugin Development' started by rcth, May 2, 2015.

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

    rcth

    Hello users,

    I want to make a new publicly availible plugin, but I have an important question.

    Some plugins like Essentials have different components/modules. Essentials has the core, but also EssentialsSpawn, EssentialsChat etc. How can I achieve such things? A core plugin and different modules to expand the possibilities.
     
  2. Offline

    Totom3

    There's only one thing you need to do to make sure two plugins can interact with each other: make one depend on the other in it's plugin.yml. Let's take EssentialsSpawn as an example. It requires Essentials in order to work, or in other words, it depends on Essentials. If Essentials is not present, EssentialsSpawn will not enable. To make sure Essentials is present and is loaded, the developers of EssentialsSpawn had to tell Bukkit that their plugin required it, and there's only 1 way of doing so: by specifying it in the plugin.yml file, with the depend tag.

    For example:
    CorePlugin's plugin.yml:
    Code:
    name: CorePlugin
    [ .... ]
    ModuleThatExtendsCorePlugin's plugin.yml:
    Code:
    depend: [CorePlugin]
    Bukkit will then make sure CorePlugin is loaded before loading ModuleThatExtendsCorePlugin, and ModuleThatExtendsCorePlugin will be able of using CorePlugin's classes.
     
  3. I'm currently making a plugin with different modules, that combines many of my plugins into one.
    It has a superclass called Module, with all the stuff such as name, enabling/disabling, custom configs, (un-)regis.
    And theres a ModuleManager that handles all the different modules and allows easy enabling/disabling of each module.
     
  4. Offline

    rcth

    Thank you.

    Could you give me an example on that? I don't completely get it.
     
  5. A little example (mine is much more complex but I don't wanna give you all the code):
    Code:java
    1. public class Module implements CommandExecutor, Listener {
    2.  
    3. public String name;
    4. public boolean enabled;
    5.  
    6. public Module() {
    7. enable();
    8. }
    9.  
    10. public void enable() {
    11. enabled = true;
    12. name = getClass().getSimpleName();
    13. Bukkit.getPluginManager().registerEvents(this, Main.getInstance());
    14. }
    15. public void disable() {
    16. enabled = false;
    17. HandlerList.unregisterAll(this);
    18. }
    19.  
    20. public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
    21. return true;
    22. }
    23. }

    Code:java
    1. public class ModuleManager {
    2.  
    3. public Set<Module> modules = new HashSet<Module>();
    4.  
    5. public void loadModules() {
    6. modules.add(new JoinMessages());
    7. }
    8. }

    Code:java
    1. public class JoinMessages extends Module {
    2.  
    3. @EventHandler
    4. public void onJoin(PlayerJoinEvent e) {
    5. e.getPlayer().sendMessage("Hi");
    6. }
    7. }
     
    Last edited: May 2, 2015
  6. Offline

    rcth

    Thank you.

    And if I'm correct, the joinmessages is a different plugin then?
     
  7. @rcth
    No. The joinmessages is a "module". You can make as many modules as you want to use within one plugin.
    I placed each of the modules in one package.
    The whole stuff with Module, ModuleManager and the modules itself are in one single plugin
     
  8. Offline

    RainoBoy97

    @FisheyLP
    You either forgot to implement the methods from CommandExecutor or to make Module abstract.
     
    TeddyTheTeddy likes this.
  9. @RainoBoy97
    Yeah I know It was just a little overview..
    Why abstract? I tested it with normal and abstract class, and booth of them worked.
     
  10. Offline

    RainoBoy97

    Yeah, but then you have to implement the methods from the CommandExecutor class.
     
  11. Offline

    rcth

    That wasn't really what I meant. I meant to have different plugins (which act as modules) besides the core plugin. Essentials has the EssentialsProtect, EssentialsEconomy etc. modules.
     
  12. Oops, I understood that wrong..
    In your different plugins, you need a dependency of your main plugin, and of course, create an easy to use API in your main plugin.
     
  13. Offline

    rcth

    Thank you for your help!
     
Thread Status:
Not open for further replies.

Share This Page