Interface TypeParser<S,T>

Type Parameters:
S - sender type
T - the type that this parser handles
All Known Implementing Classes:
BooleanTypeParser, DiagnosticSuiteNameTypeParser, EnumTypeParser, ListTypeParser, NumberTypeParser, StringTypeParser

public interface TypeParser<S,T>
Unified interface for parsing command arguments and providing suggestions. Combines functionality of ArgumentTypeParser and SuggestionParser.
  • Method Details

    • canParse

      boolean canParse(@NotNull @NotNull Class<?> type)
      Checks if this parser can handle the given type.
      Parameters:
      type - the class type to check
      Returns:
      true if this parser can handle the type
    • parse

      @Nullable T parse(@Nullable @Nullable String value, @NotNull @NotNull Class<T> targetType, @NotNull S sender)
      Parses the given value to the target type.
      Parameters:
      value - the string value to parse
      targetType - the target class type
      sender - the command sender (for context like @sender)
      Returns:
      the parsed object or null if parsing failed
    • parseDetailed

      @NotNull default @NotNull TypeParseResult<T> parseDetailed(@Nullable @Nullable String value, @NotNull @NotNull Class<T> targetType, @NotNull S sender)
      Parses the given value with a detailed outcome.

      This preserves the legacy parse(String, Class, Object) contract while allowing command binding to distinguish omitted input from invalid user input.

      Parameters:
      value - the string value to parse
      targetType - the target class type
      sender - the command sender
      Returns:
      detailed parse result
    • getSuggestions

      @NotNull @NotNull List<String> getSuggestions(@NotNull S sender)
      Gets suggestions for this type.
      Parameters:
      sender - the command sender for context
      Returns:
      list of all possible suggestions
    • getSuggestions

      @NotNull default @NotNull List<String> getSuggestions(@NotNull S sender, @Nullable @Nullable CommandArgument argument)
      Gets suggestions for this type with access to the argument metadata.
      Parameters:
      sender - the command sender for context
      argument - the command argument (may be null)
      Returns:
      list of suggestions
    • getSuggestions

      @NotNull default @NotNull List<String> getSuggestions(@NotNull S sender, @Nullable @Nullable CommandArgument argument, @NotNull @NotNull Map<String,Object> previousParsedArguments, @Nullable @Nullable String currentInput)
      Gets suggestions for this type with access to the argument metadata and previously parsed arguments.
      Parameters:
      sender - the command sender for context
      argument - the command argument (may be null)
      previousParsedArguments - a map of argument names to their parsed values that appeared before this argument.
      currentInput - the current user input for filtering (optional)
      Returns:
      list of suggestions
    • getSuggestionsFiltered

      @NotNull default @NotNull List<String> getSuggestionsFiltered(@Nullable @Nullable String currentInput, @NotNull S sender, @Nullable @Nullable CommandArgument argument)
      Gets filtered suggestions based on current input.
      Parameters:
      currentInput - the current user input for filtering
      sender - the command sender for context
      argument - the command argument for context
      Returns:
      filtered list of suggestions
    • canParseSuggestion

      default boolean canParseSuggestion(@NotNull @NotNull String source)
      Checks if this parser can handle a special suggestion source. This allows parsers to handle special syntax like @players, @worlds, etc.
      Parameters:
      source - the suggestion source to check
      Returns:
      true if this parser can handle the source
    • parseSuggestion

      @NotNull default @NotNull List<String> parseSuggestion(@NotNull @NotNull String source, @NotNull S sender)
      Parses a special suggestion source and returns suggestions.
      Parameters:
      source - the suggestion source
      sender - the command sender for context
      Returns:
      list of suggestions from the source
    • isEqual

      default boolean isEqual(@NotNull S sender, @Nullable @Nullable Object first, @Nullable @Nullable Object second, @NotNull @NotNull CompareMode mode)
      Compare two values under a given mode (parsers may override).
      Parameters:
      sender - command sender
      first - first value
      second - second value
      mode - compare strategy
      Returns:
      true if equal under mode
    • isSender

      default boolean isSender(@NotNull S sender, @Nullable @Nullable Object value, @NotNull @NotNull CompareMode mode)
      Check if value refers to the sender (parsers may override).
      Parameters:
      sender - command sender
      value - candidate value
      mode - compare strategy
      Returns:
      true if represents sender
    • getPriority

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