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:
java.lang.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 java.lang.Object implements java.lang.Comparable<CommandArgument<?,?>>
A argument that belongs to a command
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CommandArgument.Builder<C,T>
Mutable builder forCommandArgument
instances
-
Constructor Summary
Constructors Constructor Description CommandArgument(boolean required, @NonNull java.lang.String name, @NonNull ArgumentParser<C,T> parser, @NonNull java.lang.Class<T> valueType)
Construct a new command argumentCommandArgument(boolean required, @NonNull java.lang.String name, @NonNull ArgumentParser<C,T> parser, @NonNull java.lang.String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable java.util.function.BiFunction<CommandContext<C>,java.lang.String,java.util.List<java.lang.String>> suggestionsProvider)
Construct a new command argumentCommandArgument(boolean required, @NonNull java.lang.String name, @NonNull ArgumentParser<C,T> parser, @NonNull java.lang.String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable java.util.function.BiFunction<CommandContext<C>,java.lang.String,java.util.List<java.lang.String>> suggestionsProvider, @NonNull java.util.Collection<@NonNull java.util.function.BiFunction<@NonNull CommandContext<C>,@NonNull java.util.Queue<@NonNull java.lang.String>,@NonNull ArgumentParseResult<java.lang.Boolean>>> argumentPreprocessors)
Construct a new command argumentCommandArgument(boolean required, @NonNull java.lang.String name, @NonNull ArgumentParser<C,T> parser, @NonNull java.lang.String defaultValue, @NonNull java.lang.Class<T> valueType, @Nullable java.util.function.BiFunction<@NonNull CommandContext<C>,@NonNull java.lang.String,@NonNull java.util.List<@NonNull java.lang.String>> suggestionsProvider)
Construct a new command argument
-
Method Summary
Modifier and Type Method Description @NonNull CommandArgument<C,T>
addPreprocessor(@NonNull java.util.function.BiFunction<@NonNull CommandContext<C>,@NonNull java.util.Queue<java.lang.String>,@NonNull ArgumentParseResult<java.lang.Boolean>> preprocessor)
Register a new preprocessor.int
compareTo(@NonNull CommandArgument<?,?> o)
@NonNull CommandArgument<C,T>
copy()
Create a copy of the command argumentboolean
equals(java.lang.Object o)
@NonNull java.lang.String
getDefaultValue()
Get the default value@NonNull java.lang.String
getName()
Get the command argument name;@Nullable Command<C>
getOwningCommand()
Get the owning command@NonNull ArgumentParser<C,T>
getParser()
Get the parser that is used to parse the command input into the corresponding command type@NonNull java.util.function.BiFunction<@NonNull CommandContext<C>,@NonNull java.lang.String,@NonNull java.util.List<java.lang.String>>
getSuggestionsProvider()
Get the argument suggestions provider@NonNull io.leangen.geantyref.TypeToken<T>
getValueType()
Get the type of this argument's valueboolean
hasDefaultValue()
Check if the argument has a default valueint
hashCode()
boolean
isArgumentRegistered()
Check whether or not the argument has been used in a commandboolean
isRequired()
Check whether or not the command argument is requiredstatic <C,T>
@NonNull CommandArgument.Builder<C,T>ofType(@NonNull io.leangen.geantyref.TypeToken<T> clazz, @NonNull java.lang.String name)
Create a new command argumentstatic <C,T>
@NonNull CommandArgument.Builder<@NonNull C,@NonNull T>ofType(@NonNull java.lang.Class<T> clazz, @NonNull java.lang.String name)
Create a new command argument@NonNull ArgumentParseResult<java.lang.Boolean>
preprocess(@NonNull CommandContext<C> context, @NonNull java.util.Queue<java.lang.String> input)
Preprocess command input.void
setArgumentRegistered()
Indicate that the argument has been associated with a commandvoid
setOwningCommand(@NonNull Command<C> owningCommand)
Set the owning command@NonNull java.lang.String
toString()
-
-
-
Constructor Detail
-
CommandArgument
public CommandArgument(boolean required, @NonNull java.lang.String name, @NonNull ArgumentParser<C,T> parser, @NonNull java.lang.String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable java.util.function.BiFunction<CommandContext<C>,java.lang.String,java.util.List<java.lang.String>> suggestionsProvider, @NonNull java.util.Collection<@NonNull java.util.function.BiFunction<@NonNull CommandContext<C>,@NonNull java.util.Queue<@NonNull java.lang.String>,@NonNull ArgumentParseResult<java.lang.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 java.lang.String name, @NonNull ArgumentParser<C,T> parser, @NonNull java.lang.String defaultValue, @NonNull io.leangen.geantyref.TypeToken<T> valueType, @Nullable java.util.function.BiFunction<CommandContext<C>,java.lang.String,java.util.List<java.lang.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 java.lang.String name, @NonNull ArgumentParser<C,T> parser, @NonNull java.lang.String defaultValue, @NonNull java.lang.Class<T> valueType, @Nullable java.util.function.BiFunction<@NonNull CommandContext<C>,@NonNull java.lang.String,@NonNull java.util.List<@NonNull java.lang.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 java.lang.String name, @NonNull ArgumentParser<C,T> parser, @NonNull java.lang.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 Detail
-
ofType
public static <C,T> @NonNull CommandArgument.Builder<C,T> ofType(@NonNull io.leangen.geantyref.TypeToken<T> clazz, @NonNull java.lang.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 java.lang.Class<T> clazz, @NonNull java.lang.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
-
isRequired
public boolean isRequired()
Check whether or not the command argument is required- Returns:
true
if the argument is required,false
if not
-
getName
public @NonNull java.lang.String getName()
Get the command argument name;- Returns:
- Argument name
-
getParser
public @NonNull ArgumentParser<C,T> getParser()
Get the parser that is used to parse the command input into the corresponding command type- Returns:
- Command parser
-
toString
public final @NonNull java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
addPreprocessor
public @NonNull CommandArgument<C,T> addPreprocessor(@NonNull java.util.function.BiFunction<@NonNull CommandContext<C>,@NonNull java.util.Queue<java.lang.String>,@NonNull ArgumentParseResult<java.lang.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<java.lang.Boolean> preprocess(@NonNull CommandContext<C> context, @NonNull java.util.Queue<java.lang.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
public @Nullable Command<C> getOwningCommand()
Get the owning command- Returns:
- Owning command
-
setOwningCommand
public void setOwningCommand(@NonNull Command<C> owningCommand)
Set the owning command- Parameters:
owningCommand
- Owning command
-
getSuggestionsProvider
public final @NonNull java.util.function.BiFunction<@NonNull CommandContext<C>,@NonNull java.lang.String,@NonNull java.util.List<java.lang.String>> getSuggestionsProvider()
Get the argument suggestions provider- Returns:
- Suggestions provider
-
equals
public final boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
compareTo
public final int compareTo(@NonNull CommandArgument<?,?> o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<C>
-
getDefaultValue
public @NonNull java.lang.String 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
public @NonNull io.leangen.geantyref.TypeToken<T> getValueType()
Get the type of this argument's value- Returns:
- Value type
-
copy
public @NonNull CommandArgument<C,T> 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
-
-