Arguments
Argument Parsers
Argument parsers transform the input arguments (e.g. ["hello", "world]
) and usually combine them to form a single string that can be used by Argument Resolvers.
Default
By default if no annotation is specified, a method argument will map 1:1 with a single command argument. This means that if a command method's signature is void command(... sender, String s)
, the s
parameter will always map to the first command argument.
Join
The @Join
annotation simply combines all the rest of the arguments and joins with the specified delimiter (defaults to " ").
Additional parameters after an @Join
parameter may result in unexpected behaviour
And with the delimiter specified:
Argument Resolvers
Default
The default argument resolver simply attempts to convert an argument into an object using the Converter Registry.
Optional
The @Optional
annotation provides the exact same behaviour as Default, but returns null
if the argument is not present.
Converter Registry
The ConverterRegistry
is responsible for converting a string argument into an object usable by either a subcommand or default command method. It is open for extension so you can register your own converters or override existing ones:
To signal to Enchanted that the argument is invalid you can return an empty optional or throw an ArgumentParseException
to provide a custom message.
Default Converters
Every Enchanted implementation provides at least the following converters by default:
Type | Description |
---|---|
| Returns the input |
| Same as |
| Same as |
| Same as |
| Same as |
| Same as |
| Same as |
| Same as |
| If there is only character in the input, it returns it |
| |
| |
| |
| Same as |
| Same as |
| Same as |
Paper Converters
The Paper platform offers a ton of additional converters:
Type | Description |
---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| Same as |
| Same as |
| Same as |
| Gets a sound by namespaced key |
| Gets a material by namespaced key |
| |
| |
| Enum value + by id + by shorthand (s, c, a, sp) |
| Gets a player by name (case insensitive) |
| Gets a player by name or "console" to get the console sender |
| Gets a player by name, "console" to get the console or "*" to get the server |
| Gets a plugin by name |
| Gets a permission by name |
| Gets a datapack by name |
| Gets a world by namespaced key or id |
Last updated