Skip to content

bukkit annotations

rawr edited this page Feb 10, 2022 · 1 revision

Initial Setup

It is recommended to follow the gradle or maven build tool guide.

Setting up the Platform

override fun onEnable()
{
    Platforms
        .usePlatform<BukkitCommandPlatform> {
            this.fallback = "hors" // this is the fallback prefix, in minecraft this is placed before the command.
        }
        .useWrapper<AnnotationCommandWrapper>() // it is required to call this after usePlatform. this class uses the platform to do certain things
}

After setting up the platform you are able to register the commands through the same Platforms class, view example beneath.

Platforms.registerCommand(TestCommand)

Basic Command Examples

Basic parent-subcommand command

@Command("name|alias1|alias2")
class TestCommand
{
    @Default // parent command, uses @Command parameter of parent class.
    @CommandPermission("permission")
    fun default(player: Player, amount: Int)
    {
        for (i in 0..amount)
        {
            player.sendMessage("iteration $amount")
        }
    }

    @Command("subcommand|subcommandalias1") // subcommand of parent command
    @CommandPermission("permission")
    fun subcommand(player: Player, message: Array<String>)
    {
        player.sendMessage(message.joinToString(" "))
    }
}

Basic multi-parent command class

class TestCommand
{
    @Command("name|alias1|alias2") // first parent command
    @CommandPermission("permission")
    fun command1(player: Player, amount: Int)
    {
        for (i in 0..amount)
        {
            player.sendMessage("iteration $amount")
        }
    }

    @Command("command2name|command2alias") // other parent command
    @CommandPermission("permission")
    fun command2(player: Player, message: Array<String>)
    {
        player.sendMessage(message.joinToString(" "))
    }
}

Utilizing the automatic help generation

@Command("hey|how|test")
object TestCommand
{
    @Help
    @Default
    @HelpDescription("Show this menu")
    @CommandPermission("hello.test")
    fun test()
    {
        println("called test() body") // this won't print!
    }

    @Command("bye")
    @HelpDescription("Broadcast a message.")
    fun bye(lol: Array<String>)
    {
        Bukkit.broadcastMessage(lol.joinToString(" "))
    }

    @Command("yo")
    @HelpDescription("Broadcast your name.")
    fun yo(player: Player, @Value("1") amount: Int)
    {
        for (i in 0..amount)
        {
            Bukkit.broadcastMessage(player.name)
        }
    }
}

Clone this wiki locally