Class CommandComponent<C>
- Type Parameters:
C- command sender type
- All Implemented Interfaces:
Comparable<CommandComponent<C>>,PreprocessorHolder<C>,Describable
- Direct Known Subclasses:
TypedCommandComponent
This class does not preserve the type of the underlying parser.
If you need access to the underlying types, use TypedCommandComponent.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic enum -
Method Summary
Modifier and TypeMethodDescriptionfinal @NonNull CommandComponent<C> addPreprocessor(@NonNull ComponentPreprocessor<C> preprocessor) Registers a new preprocessor.final @NonNull Collection<@NonNull String> aliases()Returns the aliases, if relevant.final @NonNull Collection<@NonNull String> Returns the aliases excluding thename, if relevant.static <C,T> @NonNull CommandComponent.Builder <C, T> builder()Creates a new mutable builder.static <C,T> @NonNull CommandComponent.Builder <C, T> builder(@NonNull String name, @NonNull ParserDescriptor<? super C, T> parserDescriptor) Creates a new mutable builder.static <C,T> @NonNull CommandComponent.Builder <C, T> builder(@NonNull CloudKey<T> name, @NonNull ParserDescriptor<? super C, T> parserDescriptor) Creates a new mutable builder.final intcompareTo(@NonNull CommandComponent<C> other) Returns the default value, if specified.final @NonNull DescriptionReturns the description that describes this object.final booleanfinal booleanReturns whether this component has a default value.final inthashCode()name()Returns the name of the component.static <C,T> @NonNull CommandComponent.Builder <C, T> Creates a new mutable builder.final booleanoptional()Returns whether the argument is optional.parser()Returns the parser.final @NonNull ArgumentParseResult<Boolean> preprocess(@NonNull CommandContext<C> context, @NonNull CommandInput input) Preprocess command input.final @NonNull Collection<@NonNull ComponentPreprocessor<C>> Returns an unmodifiable collection of preprocessors.final booleanrequired()Returns whether the argument is required.final @NonNull SuggestionProvider<C> Returns the suggestion provider for this argument.toString()type()Returns the type of the component.Returns the type of the values produced by theparser().
-
Method Details
-
builder
Creates a new mutable builder.The builder returns a
TypedCommandComponentwhich can be used to retrieve parsed values from theCommandContext.- Type Parameters:
C- command sender typeT- 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
TypedCommandComponentwhich can be used to retrieve parsed values from theCommandContext.- Type Parameters:
C- command sender typeT- component value type- Parameters:
name- component nameparserDescriptor- 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
TypedCommandComponentwhich can be used to retrieve parsed values from theCommandContext.- Type Parameters:
C- command sender typeT- component value type- Parameters:
name- component nameparserDescriptor- 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
TypedCommandComponentwhich can be used to retrieve parsed values from theCommandContext.- Type Parameters:
C- command sender typeT- component value type- Parameters:
clazz- type of the componentname- name of the component- Returns:
- the builder
-
valueType
Returns the type of the values produced by theparser().- Returns:
- the types of the values produced by the parser
-
parser
Returns the parser.- Returns:
- the parser
-
name
Returns the name of the component.- Returns:
- the component name
-
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
Returns the aliases excluding thename, 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
Description copied from interface:DescribableReturns the description that describes this object.This will never return
null, and will instead returnDescription.empty()in the case that no description is present. You may check for emptiness by usingDescription.isEmpty().- Specified by:
descriptionin interfaceDescribable- 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
Returns the default value, if specified.This should always return
nullifrequired()istrue.- Returns:
- the default value if specified, else
null
-
hasDefaultValue
public final boolean hasDefaultValue()Returns whether this component has a default value.- Returns:
trueif the component has a default value, elsefalse
-
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
resultsthat all returntrue, 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
trueresult will be returned.- Parameters:
context- Command contextinput- Remaining command input. None will be popped- Returns:
- parsing error, or argument containing
true
-
preprocessors
Description copied from interface:PreprocessorHolderReturns an unmodifiable collection of preprocessors.- Specified by:
preprocessorsin interfacePreprocessorHolder<C>- Returns:
- the preprocessors
-
hashCode
public final int hashCode() -
equals
-
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<C>
-