CommandAPI 9.7.0
An API for the command UI introduced in Minecraft 1.13
|
A mutable implementation of an ImmutableStringReader
, that allows moving the cursor.
More...
Public Member Functions | |
StringReader (final StringReader other) | |
StringReader (final String string) | |
String | getString () |
Returns the full input string. More... | |
void | setCursor (final int cursor) |
Sets the cursor index position. More... | |
int | getRemainingLength () |
Returns the remaining length, so the distance from the cursor to the end of the input. More... | |
int | getTotalLength () |
Returns the total length of the input. More... | |
int | getCursor () |
Returns the current cursor position. More... | |
String | getRead () |
Returns the part of the input that was already read. More... | |
String | getRemaining () |
Returns the part of the input that was not yet read. More... | |
boolean | canRead (final int length) |
Checks if the reader has enough input to read length more characters. More... | |
boolean | canRead () |
Checks if the reader can read at least one more character. More... | |
char | peek () |
Returns the next character but without consuming it (so the cursor stays at its current position). More... | |
char | peek (final int offset) |
Returns the character offset places from the cursor position without consuming it (so the cursor stays at its current position). More... | |
char | read () |
Reads the next character. More... | |
void | skip () |
Skips a single character. | |
void | skipWhitespace () |
Skips all following whitespace characters as determined by Character#isWhitespace(char) . | |
int | readInt () throws CommandSyntaxException |
Reads an integer. More... | |
long | readLong () throws CommandSyntaxException |
Reads a long. More... | |
double | readDouble () throws CommandSyntaxException |
Reads a double. More... | |
float | readFloat () throws CommandSyntaxException |
Reads a float. More... | |
String | readUnquotedString () |
Reads an unquoted string, i.e. for as long as isAllowedInUnquotedString(char) returns true. More... | |
String | readQuotedString () throws CommandSyntaxException |
Returns a quoted string. More... | |
String | readStringUntil (char terminator) throws CommandSyntaxException |
String | readString () throws CommandSyntaxException |
Reads a string, deciding between readQuotedString and readUnquotedString based on whether the next character is a quote. More... | |
boolean | readBoolean () throws CommandSyntaxException |
Reads a single boolean. More... | |
void | expect (final char c) throws CommandSyntaxException |
Peeks at the next char and consumes it, if it is the expected character. If not, it throws an exception. More... | |
Static Public Member Functions | |
static boolean | isAllowedNumber (final char c) |
Checks if the character is allowed in a number. More... | |
static boolean | isQuotedStringStart (char c) |
Checks if the character is a allowed as the start of a quoted string. More... | |
static boolean | isAllowedInUnquotedString (final char c) |
Checks if a character is allowed in an unquoted string or needs to be escaped. More... | |
A mutable implementation of an ImmutableStringReader
, that allows moving the cursor.
This is done by calling some of the methods that consume some part of the input string (like readInt
), as they advance the cursor behind the input they have read.
This class also provides methods to freely set the cursor.
boolean com.mojang.brigadier.StringReader.canRead | ( | ) |
Checks if the reader can read at least one more character.
Implements com.mojang.brigadier.ImmutableStringReader.
boolean com.mojang.brigadier.StringReader.canRead | ( | final int | length | ) |
Checks if the reader has enough input to read length
more characters.
length | the amount of characters to read |
length
more characters Implements com.mojang.brigadier.ImmutableStringReader.
void com.mojang.brigadier.StringReader.expect | ( | final char | c | ) | throws CommandSyntaxException |
Peeks at the next char and consumes it, if it is the expected character. If not, it throws an exception.
c | the character that is expected to occur next |
CommandSyntaxException | if the character was not the expected character or the end of the input was reached |
int com.mojang.brigadier.StringReader.getCursor | ( | ) |
Returns the current cursor position.
Implements com.mojang.brigadier.ImmutableStringReader.
String com.mojang.brigadier.StringReader.getRead | ( | ) |
Returns the part of the input that was already read.
Implements com.mojang.brigadier.ImmutableStringReader.
String com.mojang.brigadier.StringReader.getRemaining | ( | ) |
Returns the part of the input that was not yet read.
Implements com.mojang.brigadier.ImmutableStringReader.
int com.mojang.brigadier.StringReader.getRemainingLength | ( | ) |
Returns the remaining length, so the distance from the cursor to the end of the input.
Implements com.mojang.brigadier.ImmutableStringReader.
String com.mojang.brigadier.StringReader.getString | ( | ) |
Returns the full input string.
Implements com.mojang.brigadier.ImmutableStringReader.
int com.mojang.brigadier.StringReader.getTotalLength | ( | ) |
Returns the total length of the input.
Implements com.mojang.brigadier.ImmutableStringReader.
|
static |
Checks if a character is allowed in an unquoted string or needs to be escaped.
Currently allowed characters are:
[0-9A-Za-z_\-.+]
(as a regular expression set)
c | the character to check |
|
static |
Checks if the character is allowed in a number.
c | the character to check |
|
static |
Checks if the character is a allowed as the start of a quoted string.
Currently allowed characters are:
["'"]
(as a regular expression set)
c | the character to check |
char com.mojang.brigadier.StringReader.peek | ( | ) |
Returns the next character but without consuming it (so the cursor stays at its current position).
Implements com.mojang.brigadier.ImmutableStringReader.
char com.mojang.brigadier.StringReader.peek | ( | final int | offset | ) |
Returns the character offset
places from the cursor position without consuming it (so the cursor stays at its current position).
offset | the offset of the character to peek at |
offset
places from the current cursor position Implements com.mojang.brigadier.ImmutableStringReader.
char com.mojang.brigadier.StringReader.read | ( | ) |
Reads the next character.
Same as peek()
, but also consumes the character.
boolean com.mojang.brigadier.StringReader.readBoolean | ( | ) | throws CommandSyntaxException |
Reads a single boolean.
A boolean can be either true
or false
and is case sensitive.
CommandSyntaxException | if the input was empty or the read string is not a valid boolean |
double com.mojang.brigadier.StringReader.readDouble | ( | ) | throws CommandSyntaxException |
Reads a double.
The double may only contain characters that match isAllowedNumber(char)
.
CommandSyntaxException | if the command is no proper double |
float com.mojang.brigadier.StringReader.readFloat | ( | ) | throws CommandSyntaxException |
Reads a float.
The float may only contain characters that match isAllowedNumber(char)
.
CommandSyntaxException | if the command is no proper float |
int com.mojang.brigadier.StringReader.readInt | ( | ) | throws CommandSyntaxException |
Reads an integer.
The integer may only contain characters that match isAllowedNumber(char)
.
CommandSyntaxException | if the command is no proper int |
long com.mojang.brigadier.StringReader.readLong | ( | ) | throws CommandSyntaxException |
Reads a long.
The long may only contain characters that match isAllowedNumber(char)
.
CommandSyntaxException | if the command is no proper long |
String com.mojang.brigadier.StringReader.readQuotedString | ( | ) | throws CommandSyntaxException |
Returns a quoted string.
The format of a quoted string is as follows:
"
(quotation mark) \
(backslash) has to be used for quotation marks and literal escape characters within the string canRead
is false CommandSyntaxException | if the next character is not a quote, an invalid escape character is encountered or the closing quote was not found |
String com.mojang.brigadier.StringReader.readString | ( | ) | throws CommandSyntaxException |
Reads a string, deciding between readQuotedString
and readUnquotedString
based on whether the next character is a quote.
CommandSyntaxException | if an error occurs parsing the string |
String com.mojang.brigadier.StringReader.readUnquotedString | ( | ) |
Reads an unquoted string, i.e. for as long as isAllowedInUnquotedString(char)
returns true.
void com.mojang.brigadier.StringReader.setCursor | ( | final int | cursor | ) |
Sets the cursor index position.
cursor | the new cursor position |