Skip to content
This repository was archived by the owner on Nov 10, 2021. It is now read-only.

SubCommands

Julian edited this page Nov 13, 2016 · 10 revisions

You have to create the argument classes implementing ArgumentExecutor. For example something like this...

public class InfoCommand implements SubCommandExecutor {
    @Override
    public boolean execute(CommandSender cs, String[] args) {
        cs.sendMessage("Hello there!");
        return true;
    }
}

When you have all the argument classes created, you have to create another class, which implements ArgumentsInterface, to define some properties. For the previous example it would be something like this:

public enum Arguments implements SubCommandsInterface {
    INFO(
            "info", // argument
            "myplugin info", // command usage
            "Just to say hello.", // A bit useless, I know"
            new InfoCommand() // Argument instance
    ),
    
    private final String arg, usage;
    private final Enum info;
    private final SubCommandExecutor instance;

    Arguments(String argument, String usage, Enum description, SubCommandExecutor i) {
        this.arg = argument;
        this.usage = usage;
        this.info = description;
        this.instance = i;
    }

    @Override
    public String getArgument() {
        return arg;
    }

    @Override
    public String getUsage() {
        return usage;
    }

    @Override
    public Enum getDescription() {
        return info;
    }

    @Override
    public SubCommandExecutor getInstance() {
        return instance;
    }    
}

And that's all. You just have to register the arguments into your main:

// First, register the main command
SubCommandsRegisterer mainCommand = new SubCommandsRegisterer("myplugin", "myp");
// And now it will register all the arguments that you have created.
mainCommand.register(Arguments.class);

Clone this wiki locally