Реєстрація субкоманд
Перший спосіб
TestCommand класс
import com.jodexindustries.donatecase.api.data.subcommand.SubCommandExecutor;
import com.jodexindustries.donatecase.api.data.subcommand.SubCommandTabCompleter;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class TestCommand implements SubCommandExecutor<CommandSender>, SubCommandTabCompleter<CommandSender> {
@Override
public void execute(CommandSender sender, @NotNull String label, String[] args) {
sender.sendMessage("Bukkit command");
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String label, String[] args) {
return new ArrayList<>();
}
}
Реєстрація
SubCommandManager<CommandSender> subCommandManager = api.getSubCommandManager();
TestCommand executor = new TestCommand();
SubCommand subCommand = subCommandManager.builder("test")
.permission("donatecase.player")
.executor(executor)
.tabCompleter(executor)
.args(new String[]{"(test)", "(test2)"})
.description("This is cool command!")
.build();
subCommandManager.registerSubCommand(subCommand);
Другий спосіб
SecondCommand класс
import com.jodexindustries.donatecase.api.addon.Addon;
import com.jodexindustries.donatecase.api.data.subcommand.SubCommand;
import com.jodexindustries.donatecase.api.data.subcommand.SubCommandExecutor;
import com.jodexindustries.donatecase.api.data.subcommand.SubCommandTabCompleter;
import com.jodexindustries.donatecase.api.data.subcommand.SubCommandType;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
public class SecondCommand extends SubCommand<CommandSender> {
public SecondCommand(String name, Addon addon) {
super(name, addon);
}
@Override
public String getDescription() {
return "This is a second command";
}
@Override
public String getPermission() {
return SubCommandType.PLAYER.permission;
}
@Override
public String[] getArgs() {
return new String[]{"(test)", "(test2)"};
}
@Override
public SubCommandExecutor<CommandSender> getExecutor() {
return (sender, label, args) -> sender.sendMessage("Second command");
}
@Override
public SubCommandTabCompleter<CommandSender> getTabCompleter() {
return (sender, label, args) -> new ArrayList<>();
}
}
Реєстрація
SubCommandManager<CommandSender> subCommandManager = api.getSubCommandManager();
SecondCommand second = new SecondCommand("test2", api.getAddon());
subCommandManager.registerSubCommand(second);