Skip to content

Your first command

mario edited this page Mar 29, 2026 · 1 revision

Your First Command

1. Set up the handler

Before registering commands, tell the framework which plugin instance it's working with. The easiest way is to scan an entire package — the framework will find and register every @Command method automatically.

public class MyPlugin extends JavaPlugin {
    @Override
    public void onEnable() {
        BukkitCommandHandler.registerCommands("me.myplugin.commands", this);
    }
}

2. Write a command

Create a class in that package and annotate a method with @Command.

public class MyCommands {
    @Command(names = {"hello"}, playerOnly = true)
    public void helloCommand(Player sender) {
        sender.sendMessage(ChatColor.GREEN + "Hello, " + sender.getName() + "!");
    }
}

3. Add a parameter

@Command(names = {"greet"}, playerOnly = true)
public void greetCommand(Player sender, @Param(name = "target") Player target) {
    sender.sendMessage(ChatColor.GREEN + "Hello, " + target.getName() + "!");
}

That's it. Tab completion, usage messages, and player resolution are all handled automatically.

Next steps

Clone this wiki locally