🛖
Fox Hut
  • Introduction
    • Setting up
    • CommandActor, @Command and @Subcommand
    • Creating your first command
    • Improving our greet command
  • Platforms
    • Bukkit / Spigot / Paper
    • BungeeCord
    • Velocity
    • Sponge
    • Fabric
    • Brigadier
    • Minestom
    • JDA
    • Command line
  • How-to
    • Creating variants of /teleport
    • Custom parameter types
    • Suggestions and auto-completion
    • Context parameters
    • Command permissions
    • Parameter validators
    • Command conditions
    • Response handlers
    • Cooldowns
    • Help commands
    • Annotation replacers
    • Orphan command
    • Exception handling
    • Hooks
    • Dependency injection
    • Visitors
    • Customizing the dispatcher and failure behavior
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Introduction

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() + "!");
    }
}
class GreetCommands {
    
    @Command("greet")
    fun greet(actor: BukkitCommandActor) {
        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());
    }
}
class TestPlugin : JavaPlugin() {

    override fun onEnable() {
        val lamp = BukkitLamp.builder(this).build()
        lamp.register(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() + "!");
    }
}
class GreetCommands {

    @Command("greet")
    fun greet(actor: BukkitCommandActor, target: Player) {
        target.sendMessage("Welcome, ${target.name}!")
    }
}

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.

PreviousCommandActor, @Command and @SubcommandNextImproving our greet command

Last updated 4 months ago

Was this helpful?

It may seem like magic that Lamp knows how to parse the org.bukkit.entity.Player type. Not much magic is involved, though! Lamp has built-in support for the following types:

💡
/greet in Minecraft (PaperSpigot 1.21)
Executing /greet Revxrsal