Interface CommandRegisterCallback

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface CommandRegisterCallback
Called when commands should be registered.

This event is fired during server startup to allow plugins to register their commands. The provided CommandRegistry should be used to register all commands.

Example Usage


 CommandRegisterCallback.EVENT.register(registry -> {
     // Register a simple command
     registry.register(Command.builder("hello")
         .description("Says hello to the player")
         .executes(ctx -> {
             ctx.getSender().sendMessage("Hello, " + ctx.getSender().getName() + "!");
             return CommandResult.SUCCESS;
         })
         .build());

     // Register a command with arguments
     registry.register(Command.builder("greet")
         .description("Greets a player")
         .permission("server.greet")
         .then(Command.argument("player", StringArgumentType.word())
             .suggests(SuggestionProvider.of("Steve", "Alex"))
             .executes(ctx -> {
                 String player = ctx.getArgument("player", String.class);
                 ctx.getSender().sendMessage("Hello, " + player + "!");
                 return CommandResult.SUCCESS;
             }))
         .build());

     // Register a command with subcommands
     registry.register(Command.builder("gamemode")
         .aliases("gm")
         .permission("server.gamemode")
         .then(Command.literal("survival").executes(ctx -> {
             ctx.getSender().sendMessage("Switching to survival");
             return CommandResult.SUCCESS;
         }))
         .then(Command.literal("creative").executes(ctx -> {
             ctx.getSender().sendMessage("Switching to creative");
             return CommandResult.SUCCESS;
         }))
         .build());
 });
 
  • Field Details

  • Method Details

    • onRegisterCommands

      void onRegisterCommands(CommandRegistry registry)
      Called when commands should be registered.
      Parameters:
      registry - the command registry to register commands with