From ffdc4225fbb7d2a3eaa4fba61e3d45a41eb141a6 Mon Sep 17 00:00:00 2001 From: olijeffers0n <69084614+olijeffers0n@users.noreply.github.com> Date: Sat, 11 May 2024 20:15:09 +0100 Subject: [PATCH] Add an example of how to register --- docs/paper/dev/api/commands.mdx | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/docs/paper/dev/api/commands.mdx b/docs/paper/dev/api/commands.mdx index f91bde77f..44d6088fd 100644 --- a/docs/paper/dev/api/commands.mdx +++ b/docs/paper/dev/api/commands.mdx @@ -13,3 +13,36 @@ powerful and flexible way to define commands and arguments. Paper's command system is still experimental and may change in the future. ::: + +## Defining a Command + +Commands can be easily defined within your plugin's onEnable method. This can be done like so: + +```java +class YourPluginClass extends JavaPlugin { + + @Override + public void onEnable() { + LifecycleEventManager manager = this.getLifecycleManager(); + manager.registerEventHandler(LifecycleEvents.COMMANDS, event -> { + final Commands commands = event.registrar(); + commands.register( + Commands.literal("new-command") + .executes(ctx -> { + ctx.getSource().getSender().sendPlainMessage("some message"); + return Command.SINGLE_SUCCESS; + }) + .build(), + "some bukkit help description string", + List.of("an-alias") + ); + }); + } +} +``` + +:::note + +This uses our `LifecycleEventManager` to register the command. See the [Lifecycle Events](/dev/lifecycle) (WIP) page for more information. + +:::