Interface CommandParameter<S extends Source>
- All Superinterfaces:
DescriptionHolder,PermissionHolder
- All Known Subinterfaces:
AnnotatedParameter<S>,Command<S>,FlagParameter<S>,NumericParameter<S>
- All Known Implementing Classes:
AnnotationParameterDecorator,FlagCommandParameter,InputParameter,NumericParameterDecorator
@AvailableSince("1.0.0")
public interface CommandParameter<S extends Source>
extends PermissionHolder, DescriptionHolder
Represents the command parameter required
by the usage of the command itself
-
Method Summary
Modifier and TypeMethodDescriptiondefault AnnotatedParameter<S>Casts the parameter to a parameter with annotationsCasts the parameter to a subcommand/commandCasts the parameter to a flag parameterdefault NumericParameter<S>copyWithDifferentPosition(int newPosition) Creates a copy of this parameter with a different position.static <S extends Source,T>
FlagBuilder<S,T> flag(String name, ParameterType<S, T> inputType) static <S extends Source>
FlagBuilder<S,Boolean> flagSwitch(String name) format()Formats the usage parameter, the default value is the name of the parameter@NotNull OptionalValueSupplier@Nullable StringFor parameters, ONLY one permission is allowed for each parameter.@Nullable SuggestionResolver<S>Fetches the suggestion resolver linked to this command parameter.default booleandefault booleanbooleanisFlag()booleanisGreedy()booleandefault booleanbooleandefault booleanstatic <S extends Source>
CommandParameter<S>name()static <S extends Source,T>
CommandParameter<S>of(String name, ParameterType<S, T> type, @Nullable String permission, Description description, boolean optional, boolean greedy, @NotNull OptionalValueSupplier valueSupplier, @Nullable SuggestionResolver<S> suggestionResolver) static <S extends Source,T>
ParameterBuilder<S,T> optional(String name, ParameterType<S, T> token) static <S extends Source>
ParameterBuilder<S,Boolean> optionalBoolean(String name) static <S extends Source>
ParameterBuilder<S,Double> optionalDouble(String name) static <S extends Source>
ParameterBuilder<S,Float> optionalFloat(String name) static <S extends Source>
ParameterBuilder<S,String> optionalGreedy(String name) static <S extends Source>
ParameterBuilder<S,Integer> optionalInt(String name) static <S extends Source>
ParameterBuilder<S,Long> optionalLong(String name) static <S extends Source>
ParameterBuilder<S,String> optionalText(String name) parent()voidSets parent command for a parameterintposition()voidposition(int position) Sets the position of this parameter in a syntax DO NOT USE THIS FOR ANY REASON unless it's necessary to do sostatic <S extends Source,T>
ParameterBuilder<S,T> required(String name, ParameterType<S, T> type) static <S extends Source>
ParameterBuilder<S,Boolean> requiredBoolean(String name) static <S extends Source>
ParameterBuilder<S,Double> requiredDouble(String name) static <S extends Source>
ParameterBuilder<S,Float> requiredFloat(String name) static <S extends Source>
ParameterBuilder<S,String> requiredGreedy(String name) static <S extends Source>
ParameterBuilder<S,Integer> requiredInt(String name) static <S extends Source>
ParameterBuilder<S,Long> requiredLong(String name) static <S extends Source>
ParameterBuilder<S,String> requiredText(String name) voidSets a custom format for this parameter the default value is the name of the parameterdefault voidsetSinglePermission(String permission) booleansimilarTo(CommandParameter<?> parameter) Checks if this parameter has same name and valueType to the otherCommandParameterunlike `CommandParameter#equals(Object)`, if both parameters are only different in their parentCommand, it would still return true@NotNull ParameterType<S,?> type()Retrieves the parameter type associated with this command parameter.default TypeTypeWrap<?>Methods inherited from interface studio.mevera.imperat.command.DescriptionHolder
describe, describe, descriptionMethods inherited from interface studio.mevera.imperat.command.PermissionHolder
addPermission, getPermissions, hasPermission
-
Method Details
-
of
static <S extends Source,T> CommandParameter<S> of(String name, ParameterType<S, T> type, @Nullable @Nullable String permission, Description description, boolean optional, boolean greedy, @NotNull @NotNull OptionalValueSupplier valueSupplier, @Nullable @Nullable SuggestionResolver<S> suggestionResolver) -
required
-
requiredInt
-
requiredLong
-
requiredDouble
-
requiredFloat
-
requiredBoolean
-
requiredText
-
requiredGreedy
-
optional
-
optionalInt
-
optionalLong
-
optionalDouble
-
optionalFloat
-
optionalBoolean
-
optionalText
-
optionalGreedy
-
flag
-
flagSwitch
-
literal
-
name
String name()- Returns:
- the name of the parameter
-
parent
- Returns:
- the parent of this parameter
-
parent
Sets parent command for a parameter- Parameters:
parentCommand- the parameter's owning command
-
position
int position()- Returns:
- the index of this parameter
-
position
@Internal void position(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
-
getSinglePermission
For parameters, ONLY one permission is allowed for each parameter.- Returns:
- the single permission for this parameter.
-
setSinglePermission
-
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
ParameterTypeof 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
FlagParameter<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() -
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
-
asAnnotated
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
SuggestionResolverfor 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 otherCommandParameterunlike `CommandParameter#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
CommandParameteror not
-
isRequired
default boolean isRequired() -
copyWithDifferentPosition
Creates a copy of this parameter with a different position. Useful for commands that have multiple syntaxes.- Parameters:
newPosition- the new position to set- Returns:
- a copy of this parameter with the new position
-