Interface TypeParser<T>

Type Parameters:
T - the target type to parse into
All Known Implementing Classes:
EnchantmentParser, GameModeParser, LocationParser, TypeParserRegistry.SimpleTypeParser, WorldParser

public interface TypeParser<T>
Interface for parsing command argument strings into specific types. Implementations should be thread-safe and stateless.
Since:
6.2.0
Version:
2.0.0
Author:
wisdomme
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the primary type this parser handles.
    default int
    Gets the priority of this parser.
    Gets all types this parser can handle, including array types.
    parse(String value)
    Parses a string value into the target type.
    default T[]
    parseArray(String[] values)
    Parses multiple string values into an array of the target type.
    default boolean
    supports(Class<?> type)
    Checks if this parser can handle the specified type.
  • Method Details

    • getPrimaryType

      Class<T> getPrimaryType()
      Gets the primary type this parser handles.
      Returns:
      the primary type class
    • getSupportedTypes

      List<Class<?>> getSupportedTypes()
      Gets all types this parser can handle, including array types.
      Returns:
      list of supported types
    • parse

      @Nullable T parse(String value) throws TypeParseException
      Parses a string value into the target type.
      Parameters:
      value - the string value to parse
      Returns:
      the parsed value, or null if parsing fails
      Throws:
      TypeParseException - if parsing fails with an error
    • parseArray

      default T[] parseArray(String[] values) throws TypeParseException
      Parses multiple string values into an array of the target type. Default implementation calls parse() for each value.
      Parameters:
      values - the string values to parse
      Returns:
      the parsed array
      Throws:
      TypeParseException - if parsing fails with an error
    • supports

      default boolean supports(Class<?> type)
      Checks if this parser can handle the specified type.
      Parameters:
      type - the type to check
      Returns:
      true if this parser can handle the type
    • getPriority

      default int getPriority()
      Gets the priority of this parser. Higher priority parsers are checked first. Default priority is 0.
      Returns:
      the parser priority