Interface Argument<S extends CommandSource>
- All Superinterfaces:
DescriptionHolder,PermissionHolder
- All Known Subinterfaces:
AnnotatedArgument<S>,Command<S>,FlagArgument<S>,NumericArgument<S>
- All Known Implementing Classes:
AnnotationArgumentDecorator,FlagArgumentImpl,InputArgument,NumericArgumentDecorator
@AvailableSince("1.0.0")
public interface Argument<S extends CommandSource>
extends PermissionHolder, DescriptionHolder
Represents the command parameter required
by the usage of the command itself
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddValidator(@NotNull ArgValidator<S> validator) default AnnotatedArgument<S>Casts the parameter to a parameter with annotationsCasts the parameter to a subcommand/commandCasts the parameter to a flag parameterdefault NumericArgument<S>static <S extends CommandSource,T>
FlagArgumentBuilder<S,T> flag(String name, ArgumentType<S, T> inputType) static <S extends CommandSource>
FlagArgumentBuilder<S,Boolean> flagSwitch(String name) format()Formats the usage parameter, the default value is the name of the parameter@NotNull DefaultValueProvidergetName()int@Nullable SuggestionProvider<S>Fetches the suggestion resolver linked to this command parameter.@NotNull PriorityList<ArgValidator<S>>default intReturns the token limit for a greedy string argument.default booleandefault booleanbooleanisFlag()booleanisGreedy()booleandefault booleanbooleandefault booleanstatic <S extends CommandSource>
Command<S>static <S extends CommandSource,T>
Argument<S>of(String name, ArgumentType<S, T> type, @NotNull PermissionsData permission, Description description, boolean optional, boolean greedy, @NotNull DefaultValueProvider valueSupplier, @Nullable SuggestionProvider<S> suggestionProvider, List<ArgValidator<S>> validators) static <S extends CommandSource,T>
ArgumentBuilder<S,T> optional(String name, ArgumentType<S, T> type) static <S extends CommandSource>
ArgumentBuilder<S,Boolean> optionalBoolean(String name) static <S extends CommandSource>
ArgumentBuilder<S,Double> optionalDouble(String name) static <S extends CommandSource>
ArgumentBuilder<S,Float> optionalFloat(String name) static <S extends CommandSource>
ArgumentBuilder<S,String> optionalGreedy(String name) static <S extends CommandSource>
ArgumentBuilder<S,Integer> optionalInt(String name) static <S extends CommandSource>
ArgumentBuilder<S,Long> optionalLong(String name) static <S extends CommandSource>
ArgumentBuilder<S,String> optionalText(String name) static <S extends CommandSource,T>
ArgumentBuilder<S,T> required(String name, ArgumentType<S, T> type) static <S extends CommandSource>
ArgumentBuilder<S,Boolean> requiredBoolean(String name) static <S extends CommandSource>
ArgumentBuilder<S,Double> requiredDouble(String name) static <S extends CommandSource>
ArgumentBuilder<S,Float> requiredFloat(String name) static <S extends CommandSource>
ArgumentBuilder<S,String> requiredGreedy(String name) static <S extends CommandSource>
ArgumentBuilder<S,Integer> requiredInt(String name) static <S extends CommandSource>
ArgumentBuilder<S,Long> requiredLong(String name) static <S extends CommandSource>
ArgumentBuilder<S,String> requiredText(String name) voidSets a custom format for this parameter the default value is the name of the parametervoidSets parent command for a parametervoidsetPosition(int position) Sets the position of this parameter in a syntax DO NOT USE THIS FOR ANY REASON unless it's necessary to do soboolean@NotNull ArgumentType<S,?> type()Retrieves the parameter type associated with this command parameter.voidvalidate(ExecutionContext<S> context, ParsedArgument<S> parsedArgument) default TypeTypeWrap<?>Methods inherited from interface studio.mevera.imperat.command.DescriptionHolder
describe, describe, getDescriptionMethods inherited from interface studio.mevera.imperat.permissions.PermissionHolder
getPermissionsData, getPrimaryPermission, setPermissionData
-
Method Details
-
of
static <S extends CommandSource,T> Argument<S> of(String name, ArgumentType<S, T> type, @NotNull @NotNull PermissionsData permission, Description description, boolean optional, boolean greedy, @NotNull @NotNull DefaultValueProvider valueSupplier, @Nullable @Nullable SuggestionProvider<S> suggestionProvider, List<ArgValidator<S>> validators) -
required
static <S extends CommandSource,T> ArgumentBuilder<S,T> required(String name, ArgumentType<S, T> type) -
requiredInt
-
requiredLong
-
requiredDouble
-
requiredFloat
-
requiredBoolean
-
requiredText
-
requiredGreedy
-
optional
static <S extends CommandSource,T> ArgumentBuilder<S,T> optional(String name, ArgumentType<S, T> type) -
optionalInt
-
optionalLong
-
optionalDouble
-
optionalFloat
-
optionalBoolean
-
optionalText
-
optionalGreedy
-
flag
static <S extends CommandSource,T> FlagArgumentBuilder<S,T> flag(String name, ArgumentType<S, T> inputType) -
flagSwitch
-
literal
-
getName
String getName()- Returns:
- the name of the parameter
-
getParent
- Returns:
- the parent of this parameter
-
setParent
Sets parent command for a parameter- Parameters:
parentCommand- the parameter's owning command
-
getPosition
int getPosition()- Returns:
- the index of this parameter
-
setPosition
@Internal void setPosition(int position) Sets the position of this parameter in a syntax DO NOT USE THIS FOR ANY REASON unless it's necessary to do so- Parameters:
position- the position to set
-
wrappedType
TypeWrap<?> wrappedType()- Returns:
- the value valueType-token of this parameter
-
valueType
- Returns:
- the value valueType of this parameter
-
type
Retrieves the parameter type associated with this command parameter.- Returns:
- the
ArgumentTypeof the command parameter
-
getDefaultValueSupplier
- Returns:
- the default value if it's input is not present in case of the parameter being optional
-
isOptional
boolean isOptional()- Returns:
- whether this is an optional argument
-
isFlag
boolean isFlag()- Returns:
- checks whether this parameter is a flag
-
asFlagParameter
FlagArgument<S> asFlagParameter()Casts the parameter to a flag parameter- Returns:
- the parameter as a flag
-
isGreedy
boolean isGreedy()- Returns:
- checks whether this parameter consumes all the args input after it.
-
isGreedyString
boolean isGreedyString() -
greedyLimit
default int greedyLimit()Returns the token limit for a greedy string argument. Returns-1if the greedy argument has no limit (consumes all remaining tokens). Returns a positive value for a limited greedy. -
isCommand
default boolean isCommand()- Returns:
- checks whether this usage param is a command name
-
asCommand
Casts the parameter to a subcommand/command- Returns:
- the parameter as a command
-
isAnnotated
default boolean isAnnotated()- Returns:
- Whether this usage parameter has been constructed using the annotations through methods or not
-
asAnnotatedArgument
Casts the parameter to a parameter with annotations- Returns:
- the parameter as annotated one
- See Also:
-
getSuggestionResolver
Fetches the suggestion resolver linked to this command parameter.- Returns:
- the
SuggestionProviderfor a resolving suggestion
-
format
String format()Formats the usage parameter, the default value is the name of the parameter- Returns:
- the formatted parameter
- See Also:
-
setFormat
Sets a custom format for this parameter the default value is the name of the parameter- Parameters:
format- the format to set- See Also:
-
isNumeric
default boolean isNumeric() -
asNumeric
-
similarTo
Checks if this parameter has same name and valueType to the otherArgumentunlike `Argument#equals(Object)`, if both parameters are only different in their parentCommand, it would still return true- Parameters:
parameter- the parameter to compare to- Returns:
- Whether this parameter has same name and valueType to the other
Argumentor not
-
isRequired
default boolean isRequired() -
getValidators
-
addValidator
-
validate
void validate(ExecutionContext<S> context, ParsedArgument<S> parsedArgument) throws CommandException - Throws:
CommandException
-