Interface CommandExecuteCallback

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 CommandExecuteCallback
Called when a command is about to be executed.

This event fires before the command is dispatched, allowing listeners to:

  • Cancel the command execution entirely
  • Log command usage
  • Implement command cooldowns
  • Block specific commands in certain contexts (e.g., during a minigame)

This event is cancellable. If cancelled, the command will not be executed and no error message will be sent to the sender (you should send your own).

Example Usage


 // Log all command usage
 CommandExecuteCallback.EVENT.register((sender, command, input) -> {
   System.out.println(sender.getName() + " executed: /" + input);
   return EventResult.PASS;
 });

 // Block commands during a match
 CommandExecuteCallback.EVENT.register(EventPriority.HIGHEST, (sender, command, input) -> {
   if (isInMatch(sender) && !command.getName().equals("leave")) {
     sender.sendMessage("Commands are disabled during the match!");
     return EventResult.CANCEL;
   }
   return EventResult.PASS;
 });

 // Implement command cooldowns
 CommandExecuteCallback.EVENT.register((sender, command, input) -> {
   if (isOnCooldown(sender, command)) {
     sender.sendMessage("Please wait before using this command again!");
     return EventResult.CANCEL;
   }
   setCooldown(sender, command);
   return EventResult.PASS;
 });
 
  • Field Details

  • Method Details

    • onCommandExecute

      EventResult onCommandExecute(CommandSender sender, Command command, String input)
      Called when a command is about to be executed.
      Parameters:
      sender - the entity executing the command (player or console)
      command - the command being executed
      input - the full command input string (without leading slash)
      Returns:
      the event result - EventResult.CANCEL to prevent execution