This repository was archived by the owner on Nov 10, 2021. It is now read-only.
Repository navigation
SubCommands
Julian edited this page Aug 8, 2017
·
10 revisions
You have to create the subcommands classes implementing SubCommandExecutor. For example, create 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 subcommands classes created, you have to create another class, which implements SubCommandsInterface, to simplify the subcommands management. For the previous example, create 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,
(pl, args) -> pl.getName().equalsIgnoreCase("tester") // Java 8 - Lambda expressions
),
INFO2(
"info2", // argument
"myplugin info2", // command usage
"Just to say hello 2.", // A bit useless, I know"
new InfoCommand() // Argument instance
);
private final String arg, usage;
private final Enum info;
private final SubCommandExecutor instance;
private final CustomCondition condition;
Arguments(String argument, String usage, Enum desc, SubCommandExecutor instance) {
this(argument, usage, desc, instance, null);
}
Arguments(String argument, String usage, Enum description, SubCommandExecutor i, CustomCondition condition) {
this.arg = argument;
this.usage = usage;
this.info = description;
this.instance = i;
this.condition = condition;
}
@Override
public String getArgument() {
return arg;
}
@Override
public String getUsage() {
return usage;
}
@Override
public Enum getDescription() {
return info;
}
@Override
public SubCommandExecutor getInstance() {
return instance;
}
@Override
public CustomCondition getCustomCondition() {
return condition;
}
}And that's all. You just have to register the subcommands (For example, in the main class):
// First, register the command...
SubCommandsRegisterer command = new SubCommandsRegisterer("mainCommand", "mc");
// and finally, it will register all the subcommands that you have created.
command.register(Arguments.class);How to integrate:
How to use: