Package dev.polv.taleapi.command
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.
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiononCommandExecute(CommandSender sender, Command command, String input) Called when a command is about to be executed.
-
Field Details
-
EVENT
The event instance. Use this to register listeners and fire the event.
-
-
Method Details
-
onCommandExecute
Called when a command is about to be executed.- Parameters:
sender- the entity executing the command (player or console)command- the command being executedinput- the full command input string (without leading slash)- Returns:
- the event result -
EventResult.CANCELto prevent execution
-