-
- All Implemented Interfaces:
public interface CommandListener
Provides an interface to listen for command execution, with the option to intercept the command and execute your own code instead. Listeners are registered in
data/console/command_listeners.csv
.Important performance note:CommandListeners are persistent through the entire game session, so be careful with your memory management!
-
-
Method Summary
Modifier and Type Method Description abstract boolean
onPreExecute(@NotNull() String command, @NotNull() String args, @NotNull() BaseCommand.CommandContext context, boolean alreadyIntercepted)
Called before a console command is executed, and gives the listener a chance to intercept execution and run its own code. abstract BaseCommand.CommandResult
execute(@NotNull() String command, @NotNull() String args, @NotNull() BaseCommand.CommandContext context)
Called when your CommandListener declares that it wants to take over execution of a command. abstract void
onPostExecute(@NotNull() String command, @NotNull() String args, @NotNull() BaseCommand.CommandResult result, @NotNull() BaseCommand.CommandContext context, @Nullable() CommandListener interceptedBy)
Called after a command is run, regardless of whether execution was intercepted by a CommandListener or not. -
-
Method Detail
-
onPreExecute
abstract boolean onPreExecute(@NotNull() String command, @NotNull() String args, @NotNull() BaseCommand.CommandContext context, boolean alreadyIntercepted)
Called before a console command is executed, and gives the listener a chance to intercept execution and run its own code.
- Parameters:
command
- The command that is about to be run.args
- The arguments passed into the command.context
- The current console CommandContext.alreadyIntercepted
- Whether another, higher-priority CommandListener has already declared they will intercept execution for this command.
-
execute
abstract BaseCommand.CommandResult execute(@NotNull() String command, @NotNull() String args, @NotNull() BaseCommand.CommandContext context)
Called when your CommandListener declares that it wants to take over execution of a command.
This is only called if your listener returned
true
during onPreExecute and was the highest priority listener to do so.- Parameters:
command
- The command to be executed.args
- The arguments passed into the command.context
- The current console CommandContext.
-
onPostExecute
abstract void onPostExecute(@NotNull() String command, @NotNull() String args, @NotNull() BaseCommand.CommandResult result, @NotNull() BaseCommand.CommandContext context, @Nullable() CommandListener interceptedBy)
Called after a command is run, regardless of whether execution was intercepted by a CommandListener or not.
- Parameters:
command
- The command that was executed.args
- The arguments passed into the command.result
- The result of the command's execution.context
- The current console CommandContext.interceptedBy
- The CommandListener that intercepted the commands execution, if any.
-
-
-
-