Interface Commands

All Superinterfaces:
Registrar

@Experimental @NonExtendable public interface Commands extends Registrar
The registrar for custom commands. Supports Brigadier commands and BasicCommand.

An example of a command being registered is below


 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")
             );
         });
     }
 }
 

You can also register commands in PluginBootstrap by getting the LifecycleEventManager from BootstrapContext. Commands registered in the PluginBootstrap will be available for datapack's command function parsing. Note that commands registered via PluginBootstrap with the same literals as a vanilla command will override that command within all loaded datapacks.

The register methods that do not have PluginMeta as a parameter will implicitly use the PluginMeta for the plugin that the LifecycleEventHandler was registered with.

See Also: