Interface ArgumentReader.Mutable

All Superinterfaces:
ArgumentReader
Enclosing interface:
ArgumentReader

public static interface ArgumentReader.Mutable extends ArgumentReader
Represents a ArgumentReader where the cursor may move.
  • Method Details

    • skipWhitespace

      void skipWhitespace()
      Moves the cursor to the next non-whitespace character. The cursor will not advance if it already refers to a non-whitespace character.
    • parseChar

      char parseChar()
      Reads a character and advances the cursor by one
      Returns:
      The character
    • parseInt

      int parseInt() throws ArgumentParseException
      Attempts to read an int from the input starting at the cursor position. The cursor will advance until it finds a non-number and will return an int based on the consumed string.

      Numbers may begin with "-" to indicate a negative number

      When using this in your parser, you should set ValueParser.clientCompletionType() to ClientCompletionTypes.WHOLE_NUMBER to tell the client that the client completion should be an integer.

      Returns:
      The integer
      Throws:
      ArgumentParseException - if the cursor is not at a number character
    • parseDouble

      double parseDouble() throws ArgumentParseException
      Attempts to read a double from the input starting at the cursor position. The cursor will advance until it finds a non-number and will return a double based on the consumed string.

      Numbers may begin with "-" to indicate a negative number, and one period (".") may be present in the string.

      When using this in your parser, you should set ValueParser.clientCompletionType() to ClientCompletionTypes.DECIMAL_NUMBER to tell the client that the client completion should be a floating point number.

      Returns:
      The double
      Throws:
      ArgumentParseException - if the cursor is not at a number character
    • parseFloat

      float parseFloat() throws ArgumentParseException
      Attempts to read a float from the input starting at the cursor position. The cursor will advance until it finds a non-number and will return a float based on the consumed string.

      Numbers may begin with "-" to indicate a negative number, and one period (".") may be present in the string.

      When using this in your parser, you should set ValueParser.clientCompletionType() to ClientCompletionTypes.DECIMAL_NUMBER to tell the client that the client completion should be a floating point number.

      Returns:
      The double
      Throws:
      ArgumentParseException - if the cursor is not at a number character
    • parseResourceKey

      ResourceKey parseResourceKey() throws ArgumentParseException
      Attempts to read a string that is in a ResourceKey format, which is namespace:identifier.

      This parser is a strict parser. If the input is not of the format specified above, this will fail. If you are potentially expecting a non-namespaced key, but would like to accept such strings with a default namespace, use parseResourceKey(String)

      When using this in your parser, you should set ValueParser.clientCompletionType() to ClientCompletionTypes.RESOURCE_KEY to tell the client that the client completion should be a ResourceKey, so that your users will not be told to put their argument in quotation marks.

      Returns:
      The ResourceKey
      Throws:
      ArgumentParseException - if a key could not be parsed
    • parseResourceKey

      ResourceKey parseResourceKey(String defaultNamespace) throws ArgumentParseException
      Attempts to read a string that is in a ResourceKey format, which is namespace:identifier.

      If no colon is encountered, the default namespace defined below will be used as the namespace.

      When using this in your parser, you should set ValueParser.clientCompletionType() to ClientCompletionTypes.RESOURCE_KEY to tell the client that the client completion should be a ResourceKey, so that your users will not be told to put their argument in quotation marks.

      Parameters:
      defaultNamespace - The default namespace to use when parsing a string that does not contain a colon.
      Returns:
      The ResourceKey
      Throws:
      ArgumentParseException - if a key could not be parsed
    • parseUnquotedString

      String parseUnquotedString() throws ArgumentParseException
      Gets the next word in the input from the position of the cursor. This will return a string that contains the characters up to, but excluding, whitespace. The cursor will then be moved to the whitespace after the word.

      As an example, if the input string is eggs bacon spam and the cursor is at position zero (at the beginning), after this operation, the cursor will be at the whitespace between "eggs" and "bacon".

      In general, you will likely wish to use parseString() instead unless you are expecting a double quote mark at the beginning of your string and this is part of the argument you wish to return.

      The following characters will be parsed as part of a valid string without the need for quotation marks.

      • Alphanumeric symbols
      • Underscores (_)
      • Hyphens (-)
      • Periods (.)
      • Plus signs (+)

      If you require other symbols, use parseString() and ensure that users are aware they need to surround their inputs with double quotation marks. Alternatively, consider whether other parse types are suitable (for example, if you are expecting a ResourceKey, use parseResourceKey() or parseResourceKey(String).

      Returns:
      The parsed String
      Throws:
      ArgumentParseException - if a String could not be read
    • parseString

      String parseString() throws ArgumentParseException
      Gets a String from the position of the cursor. The parsing of the argument depends on whether a double quote mark is the next character to be consumed.
      • If a double quote is at the beginning of the string , the parser will read characters until a second quotation mark is found and return the string between the two marks. The cursor will then be set to the position after the second mark.
      • If the first character is not a double quote , parseUnquotedString() will parse the string

      If part of the string is quoted, such as "eggs bacon" spam, this method will return eggs bacon on first invocation, then (after running skipWhitespace(), spam on the second.

      Returns:
      The parsed String
      Throws:
      ArgumentParseException - if a String could not be read
    • peekString

      String peekString() throws ArgumentParseException
      Returns the next String but does not advance the reader.

      This call will return the same result as parseString(). Calling this multiple times in succession will return the same result each time until another parse* method or setState(ArgumentReader) is called.

      Returns:
      The next string to be read
      Throws:
      ArgumentParseException - if a String could not be read
    • parseBoolean

      boolean parseBoolean() throws ArgumentParseException
      Parses "true" or "false", else throws an exception.
      Returns:
      A boolean
      Throws:
      ArgumentParseException - if a boolean could not be read
    • parseNBTString

      String parseNBTString() throws ArgumentParseException
      Parses a SNBT string, returning that string.

      When using this in your parser, you should set ValueParser.clientCompletionType() to ClientCompletionTypes.SNBT to tell the client that the client completion should be a SNBT string.

      Returns:
      The string
      Throws:
      ArgumentParseException - if a SNBT string could not be read
    • parseDataContainer

      DataContainer parseDataContainer() throws ArgumentParseException
      Parses a DataContainer, from a SNBT string, else throws an exception.

      When using this in your parser, you should set ValueParser.clientCompletionType() to ClientCompletionTypes.SNBT to tell the client that the client completion should be a string in Mojang's SNBT format.

      Returns:
      A JsonObject
      Throws:
      ArgumentParseException - if a JsonObject could not be read
    • immutable

      Returns a immutable copy of the ArgumentReader. This can be used to get and restore the state of this reader when coupled with setState(ArgumentReader).
      Returns:
      An ArgumentReader.Immutable
    • setState

      void setState(ArgumentReader state) throws IllegalArgumentException
      Attempts to reset the state of this ArgumentReader.Mutable to the state that the provided ArgumentReader is in. This is generally used with immutable().

      If the provided state does not have the same ArgumentReader.input(), this will throw a IllegalArgumentException

      Parameters:
      state - The state to restore this to
      Throws:
      IllegalArgumentException