Command Hierarchy

Discussion in 'Spigot Plugin Development' started by Hunky524, May 26, 2016.

  1. In the onEnable() method, you can use a line of code like this:
    Code (Text):
    getCommand("SomeCommand").setExecutor(new SomeCommand());
    This will allow you separate all your commands into different classes and keep everything organized.

    What I am wondering is if you can separate arguments like this. The idea would be to have one master command like '/Shop', but then you could have multiple commands after that like, '/Shop Create', '/Shop Remove', '/Shop Open', etc. I know I could create methods within the command class for each initial option like:
    Code (Text):
    private void create(){}
    private void remove(){}
    private void open(){}
    And just pass the onCommand parameters to those methods and handle everything there.


    I am wondering if it possible to have everything under a master command and separate all the secondary commands into their own classes. I know it might not be possible because the secondary commands aren't really a command, but are arguments.
     
  2. I have something similar to this when working with lots of commands.
    My command system works like this.
    http://hastebin.com/kiquzayizi.java

    To register the command, I just create a new instance of TestCommand and it's done.

    It uses an abstract class. You can learn more about them here