Creating your first command

We will create our very first command

In this page, you will learn how to create commands using annotations.

  • We will be using the Bukkit platform, as it is the most widely used platform for Lamp. However, the same concepts apply to all other platforms.

A /greet command

public class GreetCommands {

    @Command("greet")
    public void greet(BukkitCommandActor actor) {
        actor.reply("Hello, " + actor.name() + "!");
    }
}

That's it! We have our own /greet command. Let's register it:

public final class TestPlugin extends JavaPlugin {

    @Override
    public void onEnable() {
        var lamp = BukkitLamp.builder(this).build();
        lamp.register(new GreetCommands());
    }
}

Let's see Lamp in action:

Great! Let's buff our command with more arguments.

We will add a target argument, which is a player. When executed, the target player will receive a welcome message.

public class GreetCommands {

    @Command("greet")
    public void greet(BukkitCommandActor actor, Player target) {
        target.sendMessage("Welcome, " + target.getName() + "!");
    }
}

Which will generate the following command:

Running it, we get:

Notice that by specifying the Player type, we automatically get tab completions for free! Also, if we try to input an invalid player, we get the following error message:

This is the beauty of Lamp! You describe the command and write the code that needs to be executed. Everything else, like auto-completions, validation, and parsing is done under the hood.

  • java.lang.String

  • long, int, short, byte, double, and float

  • boolean

  • java.util.UUID

  • Any enum type

The following platform-specific types are also supported:

  • org.bukkit.World

  • org.bukkit.entity.Player

  • org.bukkit.OfflinePlayer

  • EntitySelector<SomeEntityType>, which is a Lamp-provided type for matching @p, @r, @e[type=cow,distance=10], etc.

And, good news! For all the types above, you get List<T>, Set<T> and T[] types for free. The same applies for any parameter type you register, which we will do in the next tutorials.

Last updated