Command API

Register root commands and manage subcommands with permissions and tab-complete.

Examples

import io.github.chi2l3s.nextlib.api.command.CommandRegistry;
import io.github.chi2l3s.nextlib.api.command.LongCommandExecutor;
import io.github.chi2l3s.nextlib.api.command.SubCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.java.JavaPlugin;

public class MyPlugin extends JavaPlugin {
  @Override
  public void onEnable() {
    new CommandRegistry(this).registerCommand("example", new ExampleCommand());
  }

  static class ExampleCommand extends LongCommandExecutor {
    public ExampleCommand() {
      addSubCommand(new SubCommand() {
        @Override public void onExecute(CommandSender sender, String[] args) {
          sender.sendMessage("Hello from subcommand!");
        }
        @Override public java.util.List<String> onTabComplete(CommandSender s, String[] a) {
          return java.util.List.of("one", "two", "three");
        }
      }, new String[]{"test", "t"}, new Permission("example.use"));
    }
  }
}

plugin.yml

commands:
  example:
    description: Example root command
    permission: example.use
    permission-message: "No permission"

Features

  • Subcommands with aliases
  • Permission check per subcommand
  • Automatic first-arg tab completion