Package cloud.commandframework.arguments
Class CommandArgument<C,T>
java.lang.Object
cloud.commandframework.arguments.CommandArgument<C,T>
- Type Parameters:
C- Command sender typeT- The type that the argument parses into
- All Implemented Interfaces:
CloudKeyHolder<T>,Comparable<CommandArgument<?,?>>
- Direct Known Subclasses:
BooleanArgument,ByteArgument,CharArgument,CompoundArgument,DoubleArgument,DurationArgument,EnumArgument,FlagArgument,FloatArgument,IntegerArgument,LongArgument,ShortArgument,StaticArgument,StringArgument,StringArrayArgument,UUIDArgument
@API(status=STABLE)
public class CommandArgument<C,T>
extends Object
implements Comparable<CommandArgument<?,?>>, CloudKeyHolder<T>
A argument that belongs to a command
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classMutable builder forCommandArgumentinstancesstatic classCommandArgument.TypedBuilder<C,T, B extends CommandArgument.Builder<C, T>> A variant of builders designed for subclassing, that returns a self type. -
Constructor Summary
ConstructorsConstructorDescriptionCommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C, T> parser, @NonNull Class<T> valueType) Construct a new command argumentCommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C, T> parser, @NonNull String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) Construct a new command argumentCommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C, T> parser, @NonNull String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider, @NonNull ArgumentDescription defaultDescription) Construct a new command argumentCommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C, T> parser, @NonNull String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider, @NonNull ArgumentDescription defaultDescription, @NonNull Collection<@NonNull BiFunction<@NonNull CommandContext<C>, @NonNull Queue<@NonNull String>, @NonNull ArgumentParseResult<Boolean>>> argumentPreprocessors) Construct a new command argumentCommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C, T> parser, @NonNull String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider, @NonNull Collection<@NonNull BiFunction<@NonNull CommandContext<C>, @NonNull Queue<@NonNull String>, @NonNull ArgumentParseResult<Boolean>>> argumentPreprocessors) Construct a new command argumentCommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C, T> parser, @NonNull String defaultValue, @NonNull Class<T> valueType, @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String, @NonNull List<@NonNull String>> suggestionsProvider) Construct a new command argumentCommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C, T> parser, @NonNull String defaultValue, @NonNull Class<T> valueType, @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String, @NonNull List<@NonNull String>> suggestionsProvider, @NonNull ArgumentDescription defaultDescription) Construct a new command argument -
Method Summary
Modifier and TypeMethodDescription@NonNull CommandArgument<C,T> addPreprocessor(@NonNull BiFunction<@NonNull CommandContext<C>, @NonNull Queue<String>, @NonNull ArgumentParseResult<Boolean>> preprocessor) Register a new preprocessor.final intcompareTo(@NonNull CommandArgument<?, ?> o) @NonNull CommandArgument<C,T> copy()Create a copy of the command argumentfinal booleanfinal @NonNull ArgumentDescriptionGet the default description to use when registering and no other is provided.@NonNull StringGet the default valuegetKey()Get the key that identifies this object.@NonNull StringgetName()Get the command argument name;Get the owning command@NonNull ArgumentParser<C,T> Get the parser that is used to parse the command input into the corresponding command typefinal @NonNull BiFunction<@NonNull CommandContext<C>,@NonNull String, @NonNull List<String>> Get the argument suggestions provider@NonNull io.leangen.geantyref.TypeToken<T>Get the type of this argument's valuebooleanCheck if the argument has a default valuefinal inthashCode()booleanCheck whether the argument has been used in a commandbooleanCheck whether or not the command argument is requiredstatic <C,T> @NonNull CommandArgument.Builder<C, T> Create a new command argumentstatic <C,T> @NonNull CommandArgument.Builder<@NonNull C, @NonNull T> Create a new command argument@NonNull ArgumentParseResult<Boolean>preprocess(@NonNull CommandContext<C> context, @NonNull Queue<String> input) Preprocess command input.voidIndicate that the argument has been associated with a commandvoidsetOwningCommand(@NonNull Command<C> owningCommand) Set the owning commandfinal @NonNull StringtoString()
-
Constructor Details
-
CommandArgument
@API(status=STABLE, since="1.4.0") public CommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C, T> parser, @NonNull String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider, @NonNull ArgumentDescription defaultDescription, @NonNull Collection<@NonNull BiFunction<@NonNull CommandContext<C>, @NonNull Queue<@NonNull String>, @NonNull ArgumentParseResult<Boolean>>> argumentPreprocessors) Construct a new command argument- Parameters:
required- Whether or not the argument is requiredname- The argument nameparser- The argument parserdefaultValue- Default value used when no value is provided by the command sendervalueType- Type produced by the parsersuggestionsProvider- Suggestions providerdefaultDescription- Default description to use when registeringargumentPreprocessors- Argument preprocessors- Since:
- 1.4.0
-
CommandArgument
public CommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C, T> parser, @NonNull String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider, @NonNull Collection<@NonNull BiFunction<@NonNull CommandContext<C>, @NonNull Queue<@NonNull String>, @NonNull ArgumentParseResult<Boolean>>> argumentPreprocessors) Construct a new command argument- Parameters:
required- Whether or not the argument is requiredname- The argument nameparser- The argument parserdefaultValue- Default value used when no value is provided by the command sendervalueType- Type produced by the parsersuggestionsProvider- Suggestions providerargumentPreprocessors- Argument preprocessors
-
CommandArgument
public CommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C, T> parser, @NonNull String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) Construct a new command argument- Parameters:
required- Whether or not the argument is requiredname- The argument nameparser- The argument parserdefaultValue- Default value used when no value is provided by the command sendervalueType- Type produced by the parsersuggestionsProvider- Suggestions provider
-
CommandArgument
@API(status=STABLE, since="1.4.0") public CommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C, T> parser, @NonNull String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider, @NonNull ArgumentDescription defaultDescription) Construct a new command argument- Parameters:
required- Whether or not the argument is requiredname- The argument nameparser- The argument parserdefaultValue- Default value used when no value is provided by the command sendervalueType- Type produced by the parsersuggestionsProvider- Suggestions providerdefaultDescription- Default description to use when registering- Since:
- 1.4.0
-
CommandArgument
public CommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C, T> parser, @NonNull String defaultValue, @NonNull Class<T> valueType, @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String, @NonNull List<@NonNull String>> suggestionsProvider) Construct a new command argument- Parameters:
required- Whether or not the argument is requiredname- The argument nameparser- The argument parserdefaultValue- Default value used when no value is provided by the command sendervalueType- Type produced by the parsersuggestionsProvider- Suggestions provider
-
CommandArgument
@API(status=STABLE, since="1.4.0") public CommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C, T> parser, @NonNull String defaultValue, @NonNull Class<T> valueType, @Nullable BiFunction<@NonNull CommandContext<C>, @NonNull String, @NonNull List<@NonNull String>> suggestionsProvider, @NonNull ArgumentDescription defaultDescription) Construct a new command argument- Parameters:
required- Whether or not the argument is requiredname- The argument nameparser- The argument parserdefaultValue- Default value used when no value is provided by the command sendervalueType- Type produced by the parsersuggestionsProvider- Suggestions providerdefaultDescription- Default description to use when registering- Since:
- 1.4.0
-
CommandArgument
public CommandArgument(boolean required, @NonNull String name, @NonNull ArgumentParser<C, T> parser, @NonNull Class<T> valueType) Construct a new command argument- Parameters:
required- Whether the argument is requiredname- The argument nameparser- The argument parservalueType- Type produced by the parser
-
-
Method Details
-
ofType
public static <C,T> @NonNull CommandArgument.Builder<C,T> ofType(@NonNull io.leangen.geantyref.TypeToken<T> clazz, @NonNull String name) Create a new command argument- Type Parameters:
C- Command sender typeT- Argument Type. Used to make the compiler happy.- Parameters:
clazz- Argument classname- Argument name- Returns:
- Argument builder
-
ofType
public static <C,T> @NonNull CommandArgument.Builder<@NonNull C,@NonNull T> ofType(@NonNull Class<T> clazz, @NonNull String name) Create a new command argument- Type Parameters:
C- Command sender typeT- Argument Type. Used to make the compiler happy.- Parameters:
clazz- Argument classname- Argument name- Returns:
- Argument builder
-
getKey
Description copied from interface:CloudKeyHolderGet the key that identifies this object.- Specified by:
getKeyin interfaceCloudKeyHolder<C>- Returns:
- Identifying key.
-
isRequired
public boolean isRequired()Check whether or not the command argument is required- Returns:
trueif the argument is required,falseif not
-
getName
Get the command argument name;- Returns:
- Argument name
-
getParser
Get the parser that is used to parse the command input into the corresponding command type- Returns:
- Command parser
-
toString
-
addPreprocessor
public @NonNull CommandArgument<C,T> addPreprocessor(@NonNull BiFunction<@NonNull CommandContext<C>, @NonNull Queue<String>, @NonNull ArgumentParseResult<Boolean>> preprocessor) Register a new preprocessor. If all preprocessor has succeedingresultsthat all returntrue, the argument 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 @NonNull ArgumentParseResult<Boolean> preprocess(@NonNull CommandContext<C> context, @NonNull Queue<String> input) Preprocess command input. This will immediately forward any failed argument parse results. If none fails, atrueresult will be returned- Parameters:
context- Command contextinput- Remaining command input. None will be popped- Returns:
- Parsing error, or argument containing
true
-
getOwningCommand
Get the owning command- Returns:
- Owning command
-
setOwningCommand
Set the owning command- Parameters:
owningCommand- Owning command
-
getSuggestionsProvider
public final @NonNull BiFunction<@NonNull CommandContext<C>,@NonNull String, getSuggestionsProvider()@NonNull List<String>> Get the argument suggestions provider- Returns:
- Suggestions provider
-
getDefaultDescription
Get the default description to use when registering and no other is provided.- Returns:
- the default description
-
equals
-
hashCode
public final int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<C>
-
getDefaultValue
Get the default value- Returns:
- Default value
-
hasDefaultValue
public boolean hasDefaultValue()Check if the argument has a default value- Returns:
trueif the argument has a default value,falseif not
-
getValueType
Get the type of this argument's value- Returns:
- Value type
-
copy
Create a copy of the command argument- Returns:
- Copied argument
-
isArgumentRegistered
public boolean isArgumentRegistered()Check whether the argument has been used in a command- Returns:
trueif the argument has been used in a command, elsefalse
-
setArgumentRegistered
public void setArgumentRegistered()Indicate that the argument has been associated with a command
-