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
,EnumArgument
,FlagArgument
,FloatArgument
,IntegerArgument
,LongArgument
,ShortArgument
,StaticArgument
,StringArgument
,StringArrayArgument
,UUIDArgument
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 class
Mutable builder forCommandArgument
instancesstatic class
CommandArgument.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.int
compareTo(@NonNull CommandArgument<?,?> o)
@NonNull CommandArgument<C,T>
copy()
Create a copy of the command argumentboolean
@NonNull ArgumentDescription
Get the default description to use when registering and no other is provided.@NonNull String
Get the default valuegetKey()
Get the key that identifies this object.@NonNull String
getName()
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 type@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 valueboolean
Check if the argument has a default valueint
hashCode()
boolean
Check whether or not the argument has been used in a commandboolean
Check 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.void
Indicate that the argument has been associated with a commandvoid
setOwningCommand(@NonNull Command<C> owningCommand)
Set the owning command@NonNull String
toString()
-
Constructor Details
-
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 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
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
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 or not 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:CloudKeyHolder
Get the key that identifies this object.- Specified by:
getKey
in interfaceCloudKeyHolder<C>
- Returns:
- Identifying key.
-
isRequired
public boolean isRequired()Check whether or not the command argument is required- Returns:
true
if the argument is required,false
if 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 succeedingresults
that 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, atrue
result 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,@NonNull List<String>> getSuggestionsProvider()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:
compareTo
in interfaceComparable<C>
-
getDefaultValue
Get the default value- Returns:
- Default value
-
hasDefaultValue
public boolean hasDefaultValue()Check if the argument has a default value- Returns:
true
if the argument has a default value,false
if 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 or not the argument has been used in a command- Returns:
true
if the argument has been used in a command, elsefalse
-
setArgumentRegistered
public void setArgumentRegistered()Indicate that the argument has been associated with a command
-