Class CommandComponent<C>

java.lang.Object
org.incendo.cloud.component.CommandComponent<C>
Type Parameters:
C - command sender type
All Implemented Interfaces:
Comparable<CommandComponent<C>>, PreprocessorHolder<C>, Describable
Direct Known Subclasses:
TypedCommandComponent

@API(status=STABLE) public class CommandComponent<C> extends Object implements Comparable<CommandComponent<C>>, PreprocessorHolder<C>, Describable
A single literal or argument component of a command

This class does not preserve the type of the underlying parser. If you need access to the underlying types, use TypedCommandComponent.

  • Method Details

    • builder

      public static <C, T> @NonNull CommandComponent.Builder<C,T> builder()
      Creates a new mutable builder.

      The builder returns a TypedCommandComponent which can be used to retrieve parsed values from the CommandContext.

      Type Parameters:
      C - command sender type
      T - component value type
      Returns:
      the builder
    • builder

      public static <C, T> @NonNull CommandComponent.Builder<C,T> builder(@NonNull String name, @NonNull ParserDescriptor<? super C,T> parserDescriptor)
      Creates a new mutable builder.

      The builder returns a TypedCommandComponent which can be used to retrieve parsed values from the CommandContext.

      Type Parameters:
      C - command sender type
      T - component value type
      Parameters:
      name - component name
      parserDescriptor - parser descriptor
      Returns:
      the builder
    • builder

      public static <C, T> @NonNull CommandComponent.Builder<C,T> builder(@NonNull CloudKey<T> name, @NonNull ParserDescriptor<? super C,T> parserDescriptor)
      Creates a new mutable builder.

      The builder returns a TypedCommandComponent which can be used to retrieve parsed values from the CommandContext.

      Type Parameters:
      C - command sender type
      T - component value type
      Parameters:
      name - component name
      parserDescriptor - parser descriptor
      Returns:
      the builder
    • ofType

      public static <C, T> @NonNull CommandComponent.Builder<C,T> ofType(@NonNull Class<T> clazz, @NonNull String name)
      Creates a new mutable builder.

      The builder returns a TypedCommandComponent which can be used to retrieve parsed values from the CommandContext.

      Type Parameters:
      C - command sender type
      T - component value type
      Parameters:
      clazz - type of the component
      name - name of the component
      Returns:
      the builder
    • valueType

      public @NonNull TypeToken<?> valueType()
      Returns the type of the values produced by the parser().
      Returns:
      the types of the values produced by the parser
    • parser

      public @NonNull ArgumentParser<C,?> parser()
      Returns the parser.
      Returns:
      the parser
    • name

      public final @NonNull String name()
      Returns the name of the component.
      Returns:
      the component name
    • aliases

      public final @NonNull Collection<@NonNull String> aliases()
      Returns the aliases, if relevant.

      Only literal components may have aliases. If this is a non-literal component then an empty collection is returned.

      Returns:
      unmodifiable view of the aliases
    • alternativeAliases

      public final @NonNull Collection<@NonNull String> alternativeAliases()
      Returns the aliases excluding the name, if relevant.

      Only literal components may have aliases. If this is a non-literal component then an empty collection is returned.

      Returns:
      unmodifiable view of the aliases
    • description

      public final @NonNull Description description()
      Description copied from interface: Describable
      Returns the description that describes this object.

      This will never return null, and will instead return Description.empty() in the case that no description is present. You may check for emptiness by using Description.isEmpty().

      Specified by:
      description in interface Describable
      Returns:
      the description
    • required

      public final boolean required()
      Returns whether the argument is required.

      This always returns the opposite of optional().

      Returns:
      whether the argument is required
    • optional

      public final boolean optional()
      Returns whether the argument is optional.

      This always returns the opposite of required().

      Returns:
      whether the argument is optional
    • type

      Returns the type of the component.
      Returns:
      the component type
    • defaultValue

      public @Nullable DefaultValue<C,?> defaultValue()
      Returns the default value, if specified.

      This should always return null if required() is true.

      Returns:
      the default value if specified, else null
    • hasDefaultValue

      public final boolean hasDefaultValue()
      Returns whether this component has a default value.
      Returns:
      true if the component has a default value, else false
    • suggestionProvider

      public final @NonNull SuggestionProvider<C> suggestionProvider()
      Returns the suggestion provider for this argument.
      Returns:
      the suggestion provider
    • addPreprocessor

      public final @NonNull CommandComponent<C> addPreprocessor(@NonNull ComponentPreprocessor<C> preprocessor)
      Registers a new preprocessor.

      If all preprocessor has succeeding results that all return true, the component will be passed onto the parser.

      It is important that the preprocessor doesn't pop any input. Instead, it should only peek.

      Parameters:
      preprocessor - Preprocessor
      Returns:
      this
    • preprocess

      public final @NonNull ArgumentParseResult<Boolean> preprocess(@NonNull CommandContext<C> context, @NonNull CommandInput input)
      Preprocess command input.

      This will immediately forward any failed component parse results. If none fails, a true result will be returned.

      Parameters:
      context - Command context
      input - Remaining command input. None will be popped
      Returns:
      parsing error, or argument containing true
    • preprocessors

      public final @NonNull Collection<@NonNull ComponentPreprocessor<C>> preprocessors()
      Description copied from interface: PreprocessorHolder
      Returns an unmodifiable collection of preprocessors.
      Specified by:
      preprocessors in interface PreprocessorHolder<C>
      Returns:
      the preprocessors
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public final boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public final @NonNull String toString()
      Overrides:
      toString in class Object
    • compareTo

      public final int compareTo(@NonNull CommandComponent<C> other)
      Specified by:
      compareTo in interface Comparable<C>