Registering annotation-based commands

Registering annotation-based commands is really simple. To do this, we use the following method, where className is the name of a class with a @Command annotation:


Example: Registering a Warp command

Say we have a simple command /warp that is defined as follows:

public class WarpCommand {
    // List of warp names and their locations
    static Map<String, Location> warps = new HashMap<>();
    public static void warp(CommandSender sender) {
        sender.sendMessage("--- Warp help ---");
        sender.sendMessage("/warp - Show this help");
        sender.sendMessage("/warp <warp> - Teleport to <warp>");
        sender.sendMessage("/warp create <warpname> - Creates a warp at your current location");
    public static void warp(Player player, @AStringArgument String warpName) {
    public static void createWarp(Player player, @AStringArgument String warpName) {
        warps.put(warpName, player.getLocation());

We can register this in our onLoad() method so we can use this command from within Minecraft functions:

public class MyPlugin extends JavaPlugin {
    public void onLoad() {