Interface ValueParser<T>

All Known Subinterfaces:
ResourceKeyedValueParameter<T>, ValueParameter<T>, ValueParameter.Simple<T>
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ValueParser<T>
Defines how a parameter should be parsed.
  • Method Details

    • parseValue

      Optional<? extends T> parseValue(Parameter.Key<? super T> parameterKey, ArgumentReader.Mutable reader, CommandContext.Builder context) throws ArgumentParseException
      Gets the value for the parameter. This may return more than one value by adding additional values to the supplied CommandContext.Builder.

      This should have no side effects on anything except on the state of the ArgumentReader and, in rare cases, the CommandContext.Builder.

      This element may return nothing in the form of an empty optional. This indicates that a parse succeeded, but no meaningful value was returned, for example, the argument must be passed but it's not necessary for the associated CommandExecutor to know what the result of the parse was. The CommandContext.Builder may be updated in this case.

      While the CommandContext.Builder is provided, in general, you do not need to add the parsed value to it yourself, instead preferring to return your parsed value. It is permissible, however, to add additional information to the context should it be required.

      The Cause of this parse is provided in the CommandContext.Builder.

      Parameters:
      parameterKey - The Parameter.Key of the parameter being parsed
      reader - The ArgumentReader that contains the unparsed arguments
      context - The CommandContext containing the state about this command
      Returns:
      Returns the value(s)
      Throws:
      ArgumentParseException - if a parameter could not be parsed
    • clientCompletionType

      default List<ClientCompletionType> clientCompletionType()
      Provides a hint to the client completion engine what sort of input(s) the client should expect.

      Multiple elements can be placed here for multi part parsers - that is, parsers that call parse methods on the ArgumentReader.Mutable more than once. However, it is recommended that you consider splitting your parsers up to consume one element at any time, any completions you provide may not be provided to the client if you do so.

      Returning an empty list does not infer that the element will not be displayed, rather, an empty list infers that the command system will decide. Custom parsers will default to a single ClientCompletionTypes.STRING. Be aware, providing a non-string type here may cause your completions to be ignored.

      If you wish to hide this element from client completion completely, return a List with a single ClientCompletionTypes.NONE.

      Remember that anything supplied here is a hint. It is possible that this hint will be ignored in some scenarios, particularly if this parser is one of many supplied to Parameter.Value.

      Returns:
      The ClientCompletionTypes to use on the client.