Context class represents the execution context of a command, providing access to the command sender, arguments, and utilities for parsing arguments with custom providers.
Overview
Every command method and provider receives aContext instance, which contains:
- The command sender who executed the command
- Raw string arguments passed to the command
- The command label that was used
- Access to the Blade instance
- Utilities for parsing arguments at specific indices
Class Definition
me.vaperion.blade.context
Core Methods
Accessing Arguments
Returns all provided arguments as a string array.
Returns the argument at the specified index, or
null if not present.The zero-based index of the argument
Parsing Arguments
The Context class provides several overloaded methods for parsing arguments with custom providers.Parses the argument at the specified index using the registered provider for the given class.Returns: The parsed argument, or
The zero-based index of the argument to parse
The target type to parse the argument into
null if not presentThrows:IllegalArgumentException- if no provider is registered for the classBladeParseError- if parsing failsBladeImplementationError- if the provider has implementation issues
Parses the argument at the specified index with a default value if not present.Returns: The parsed argument, or the parsed default value if not present
The zero-based index of the argument to parse
The target type to parse the argument into
The default value to use if the argument is not present
Parses the argument using a specific provider with a default value.Returns: The parsed argument, or the parsed default value if not present
The zero-based index of the argument to parse
The provider to use for parsing
The default value to use if the argument is not present
Accessing Context Properties
Returns the command label that was used to invoke the command.
Returns the Blade instance managing this command.
Sender Interface
TheSender<T> interface wraps platform-specific sender types.
Sender Methods
Returns the raw platform instance of the sender (e.g., Player, CommandSource).
Returns the name of the sender.
Checks if the sender has a specific permission.
The permission node to check
Attempts to convert the sender to the specified type.Returns: The converted sender if successful,
The target class to convert to
null otherwiseUsage in Providers
TheContext is commonly used in argument providers to access the command context:
Usage in Commands
Every command method receives aContext parameter:
Advanced: Manual Argument Parsing
You can manually parse arguments in commands using the parse methods:See Also
- InputArgument - Represents a single command argument
- ArgumentProvider - Interface for creating custom argument types
- Suggestions - Tab completion builders