Skip to content

Commit

Permalink
Add an example of how to register
Browse files Browse the repository at this point in the history
  • Loading branch information
olijeffers0n committed May 11, 2024
1 parent 67ecd20 commit ffdc422
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/paper/dev/api/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Plugin> 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.

:::

0 comments on commit ffdc422

Please sign in to comment.