Class EnumTypeParser<S>

java.lang.Object
dev.ua.theroer.magicutils.commands.parsers.EnumTypeParser<S>
Type Parameters:
S - sender type
All Implemented Interfaces:
TypeParser<S,Enum<?>>

public class EnumTypeParser<S> extends Object implements TypeParser<S,Enum<?>>
Generic enum parser to avoid registering a parser per enum type.
  • Constructor Details

    • EnumTypeParser

      public EnumTypeParser()
      Default constructor.
  • Method Details

    • canParse

      public boolean canParse(@NotNull @NotNull Class<?> type)
      Description copied from interface: TypeParser
      Checks if this parser can handle the given type.
      Specified by:
      canParse in interface TypeParser<S,Enum<?>>
      Parameters:
      type - the class type to check
      Returns:
      true if this parser can handle the type
    • parse

      public Enum<?> parse(@Nullable @Nullable String value, @NotNull @NotNull Class<Enum<?>> targetType, @NotNull S sender)
      Description copied from interface: TypeParser
      Parses the given value to the target type.
      Specified by:
      parse in interface TypeParser<S,Enum<?>>
      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
    • getSuggestions

      public List<String> getSuggestions(@NotNull S sender)
      Description copied from interface: TypeParser
      Gets suggestions for this type.
      Specified by:
      getSuggestions in interface TypeParser<S,Enum<?>>
      Parameters:
      sender - the command sender for context
      Returns:
      list of all possible suggestions
    • getSuggestions

      public List<String> getSuggestions(@NotNull S sender, @Nullable @Nullable CommandArgument argument)
      Description copied from interface: TypeParser
      Gets suggestions for this type with access to the argument metadata.
      Specified by:
      getSuggestions in interface TypeParser<S,Enum<?>>
      Parameters:
      sender - the command sender for context
      argument - the command argument (may be null)
      Returns:
      list of suggestions
    • canParseSuggestion

      public boolean canParseSuggestion(@NotNull @NotNull String source)
      Description copied from interface: TypeParser
      Checks if this parser can handle a special suggestion source. This allows parsers to handle special syntax like @players, @worlds, etc.
      Specified by:
      canParseSuggestion in interface TypeParser<S,Enum<?>>
      Parameters:
      source - the suggestion source to check
      Returns:
      true if this parser can handle the source
    • parseSuggestion

      public List<String> parseSuggestion(@NotNull @NotNull String source, @NotNull S sender)
      Description copied from interface: TypeParser
      Parses a special suggestion source and returns suggestions.
      Specified by:
      parseSuggestion in interface TypeParser<S,Enum<?>>
      Parameters:
      source - the suggestion source
      sender - the command sender for context
      Returns:
      list of suggestions from the source