A lightweight, annotation-based command framework for Spigot/Bukkit plugins.
- Annotation-driven: Define commands and execution logic with
@Commandand@Execute. - Flexible Parameters: Supports various method signatures for command execution.
- Automatic Registration: Easily register all command classes.
- Permission Handling: Use
@Permissionto enforce command permissions. - Subcommands: Easily handle subcommands by specifying a name in
@Execute. - Tab Completion: Use
@TabCompleteto provide tab completions, including support for subcommands. - Type Safety: Automatically checks if the sender (e.g., Player vs Console) matches the method signature.
Annotate your class with @Command and your method with @Execute.
@Command(
name = "heal",
description = "Heals the player",
usage = "/heal",
aliases = {"h", "health"}
)
@Permission("myplugin.heal")
public class HealCommand {
@Execute
public void onCommand(Player player, String[] args) {
player.setHealth(20);
player.sendMessage("§aYou have been healed!");
}
}In your main plugin class (e.g., onEnable), use the CommandRegister builder.
@Override
public void onEnable() {
new CommandRegister.RegisterBuilder()
.setPlugin(this)
.addCommand(HealCommand.class)
.build()
.register();
}You can define subcommands by adding a name to the @Execute annotation.
@Command(name = "clan")
public class ClanCommand {
@Execute // Default executor: /clan
public void info(Player player) {
player.sendMessage("Clan Info...");
}
@Execute(name = "create") // Subcommand: /clan create <name>
public void create(Player player, String[] args) {
if (args.length > 0) {
player.sendMessage("Created clan: " + args[0]);
}
}
@TabComplete(name = "create")
public List<String> createTabComplete(CommandSender sender, String[] args) {
return List.of("Name1", "Name2");
}
}name: The name of the command (required).description: Description of the command.usage: Usage message.aliases: Array of aliases.
Marks the method to be invoked when the command is run.
name: The name of the subcommand (optional). If empty, it serves as the default executor.
Supported signatures:
void method(SenderType sender, String[] args)void method(SenderType sender)void method()
Where SenderType can be CommandSender, Player, ConsoleCommandSender, etc.
Marks the method used for tab completion.
name: The name of the subcommand to provide completions for (optional).
value: The permission node string.message: Custom no-permission message (optional).
The library is published to GitHub Packages. Add the repository to your build.gradle:
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/Touchie771/MinecraftCommands")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("TOKEN")
}
}
}
dependencies {
implementation 'me.touchie771:minecraftcommands:1.0.1'
}Alternatively, you can copy the me.touchie771.minecraftCommands.api package into your project.
This library was originally created for personal use, but anyone is welcome to use it in their projects.