An ArgumentType
that parses strings.
More...
An ArgumentType
that parses strings.
◆ escapeIfRequired()
static String com.mojang.brigadier.arguments.StringArgumentType.escapeIfRequired |
( |
final String |
input | ) |
|
|
static |
Converts a string to one that StringType#QUOTABLE_PHRASE
would match.
If the given string contains any character that does not match StringReader#isAllowedInUnquotedString(char)
, then it is wrapped in quotation marks and quotation marks and escaping characters within the string are escaped, otherwise the given string is returned unaltered.
Some sample in- and outputs:
-
hey
to hey
-
hey you
to "hey you"
-
"hello"
to "\"hello\""
-
\
to "\\"
- Parameters
-
- Returns
- the escaped output ready to be parsed by
StringType#QUOTABLE_PHRASE
◆ getString()
static String com.mojang.brigadier.arguments.StringArgumentType.getString |
( |
final CommandContext<?> |
context, |
|
|
final String |
name |
|
) |
| |
|
static |
Retrieves the argument with the given name from the context and casts it to a string.
- Parameters
-
- Returns
- the argument as a string
- See also
- CommandContext::getArgument
◆ getType()
StringType com.mojang.brigadier.arguments.StringArgumentType.getType |
( |
| ) |
|
The type of string this argument parses.
- Returns
- the
StringType
this argument parses
◆ greedyString()
static StringArgumentType com.mojang.brigadier.arguments.StringArgumentType.greedyString |
( |
| ) |
|
|
static |
A factory method that provides an instance of a greedy string argument.
This will parse the entire remaining input.
- Returns
- an instance of this argument type parsing everything until the end of the input
◆ listSuggestions()
Gets suggestions for a parsed input string on what comes next.
As it is ultimately up to custom argument types to provide suggestions, it may be an asynchronous operation, for example getting in-game data or player names etc. As such, this method returns a future and no guarantees are made to when or how the future completes.
The suggestions provided will be in the context of the end of the parsed input string, but may suggest new or replacement strings for earlier in the input string. For example, if the end of the string was foobar
but an argument preferred it to be minecraft:foobar
, it will suggest a replacement for that whole segment of the input.
- Parameters
-
context | the context to get them for |
builder | the suggestions builder to add them to |
- Returns
- a future that will eventually resolve into a
Suggestions
object @implSpec The default implementation simply returns an empty suggestions object
◆ string()
A factory method that provides an instance of a string argument.
If the string does not start with a quote, it will be interpreted like a word type string, else it will parse everything up until the next non-escaped quote.
- Returns
- an instance of this argument type parsing a word or quoted string
◆ word()
A factory method that provides an instance of a word type string argument.
Allowed are only characters where StringReader#isAllowedInUnquotedString(char)
would return true.
The parser stops parsing at the first character that is not allowed. Typically this needs to be a space.
- Returns
- an instance of this argument type parsing a single word