VitalCommand
Use this class to define your own custom command. A command defines n-amount of entry points for user-input, that can perform actions and produce a result.
Each command may have n-amount of arguments, each argument may also have n-amount of argument-exception-handlers, mapped to them to handle exceptions during argument execution.
You can also define global exception handlers, which can handle exceptions globally, not tied to any specific argument.
Each argument is defined as a function using the VitalCommand.Arg annotation. An argument may be a list of strings separated by spaces, containing the hard-coded static arguments, and variable ones with either %NAME% or
Each argument handler supports automatic parameter injection for the following parameters:
CommandSender or Player
String for the actual executed argument
VitalCommand.Arg for the matched command argument annotation, you have defined within your class.
Array of String for arguments, that have defined variables using either %NAME% or
.
Any command related operation is executed in the following order:
Look for and execute (if found) argument function based on the user-input.
If not exception occurs during this command execution, return.
If an exception occurs during execution within the argument, look for and execute (if found) an argument exception handler matching the executed argument and exception type.
If no argument exception handler was found during argument execution, look for and execute (if found) a global exception handler for the thrown exception type.
If no global exception handler was found for the exception type, fall back to onCommandError.
@VitalCommand.Info(
name = "mycommand",
description = "description"
)
public class MyCommand extends VitalCommand.Spigot {
// This will define a valid argument a player or command sender can execute
@Arg(name = "static %dynamic% <dynamic> arg")
public ReturnState onSomeArgument(CommandSender sender, String executedArg, Arg commandArg, String[] values) {
// If the command sender executes "/mycommand static 123 456 arg", this function will be called.
// the "values" parameter will have the following values: ["123", "456"]
return ReturnState.SUCCESS;
}
}Inheritors
Types
Marks the annotated class to be used as a global command exception handler. This class may define multiple VitalCommand.GlobalExceptionHandler annotated functions to handle exceptions during command execution.
Defines the argument of a VitalCommand.ArgHandler annotated function.
Marks the annotated function as a valid entry-point for when exception occur during the execution of a VitalCommand.ArgHandler annotated function.
Defines the context required to execute a VitalCommand.ArgExceptionHandler annotated function.
Marks the annotated function as a valid argument entry-point within a VitalCommand.
Defines the context required to execute a VitalCommand.ArgHandler annotated function.
Marks the annotated function as a global exception handler. This function will be called when an exception is thrown within the execution of an VitalCommand.ArgHandler annotated function, and is not caught by an underlying VitalCommand.ArgExceptionHandler annotated function.
Defines the context required to execute a VitalCommand.GlobalExceptionHandler annotated function.
Defines the possible VitalCommand return states of a VitalCommand.ArgHandler annotated function.
Defines the context required to execute tab completion on a VitalCommand.
Properties
The Throwable (type of exception) and their VitalCommand.ArgExceptionHandlerContext mapped by their VitalCommand.Arg.
The VitalCommand.ArgHandlerContext mapped by their VitalCommand.Arg.
The arguments of the command, mapped from Pattern to VitalCommand.Arg.
Functions
Internal function used to get the names of all currently connected players.
Internal function used to get all arg exception handler functions annotated with ArgExceptionHandler and map them to their appropriate Arg and specified Annotation. This function returns a Map of all mapped arg exception handlers and will later be used during command execution to correctly call arg exception handlers when an exception occurs during command execution.
Internal function used to get the internal arg handler context for all functions annotated with ArgHandler. This arg handler context will later be used during command execution to call the annotated arg handler function with the correct parameters.
Internal function used to Get all functions annotated with ArgHandler and map them to their given Arg.name as a Pattern. These mapped args are later used during command execution to find out which arg was actually executed by a command sender.
Internal function used to check if the given commandSender has the given permission.
Internal function used to check if the given commandSender is a player.
Internal function used to provide automatic tab-completions for the given command execution. Additionally, implementers can add their own tab-completions by overriding the onCommandTabComplete lifecycle function.