-
Notifications
You must be signed in to change notification settings - Fork 0
08 command system
github-actions[bot] edited this page May 5, 2026
·
1 revision
KLibrary provides a powerful, fluid wrapper over the Paper Command API (Mojang Brigadier mappings). This reduces the significant boilerplate associated with defining subcommands, tab completion, and permissions.
Extend KCommand to create a root command or a subcommand.
import io.github.kaivian.klibrary.command.api.KCommand;
import org.bukkit.command.CommandSender;
import java.util.List;
public class MyRootCommand extends KCommand {
public MyRootCommand() {
super("myplugin", "The main command for MyPlugin");
setPermission("myplugin.command.use");
setAliases("mp", "myplug");
// Register a subcommand
addSubCommand(new ReloadSubCommand());
}
@Override
public void execute(CommandSender sender, String[] args) {
sender.sendMessage("MyPlugin v1.0 - Use /myplugin help for info.");
}
}public class ReloadSubCommand extends KCommand {
public ReloadSubCommand() {
super("reload", "Reloads the plugin configuration");
setPermission("myplugin.command.reload");
}
@Override
public void execute(CommandSender sender, String[] args) {
// Reload logic here
sender.sendMessage("Configuration reloaded!");
}
}You can easily override the tabComplete method to return dynamic suggestions based on the context.
@Override
public List<String> tabComplete(CommandSender sender, String[] args) {
if (args.length == 1) {
return List.of("reload", "help", "give");
}
return List.of(); // Return empty list to stop suggesting player names
}To register your root command with the server, use the library's CommandManager (instantiated via your main plugin class).
// Inside your JavaPlugin onEnable
CommandManager commandManager = new CommandManager(this);
commandManager.registerCommand(new MyRootCommand());
KLibrary by Kaivian © 2026. All rights reserved.