Package de.dytanic.cloudnet.command.sub
Class SubCommand
- java.lang.Object
-
- de.dytanic.cloudnet.command.sub.SubCommand
-
- All Implemented Interfaces:
SubCommandExecutor
public abstract class SubCommand extends java.lang.Object implements SubCommandExecutor
Represents a sub command of any command.If neither minArgs nor maxArgs is set
-
-
Constructor Summary
Constructors Constructor Description SubCommand(int minArgs, int exactArgs, int maxArgs, QuestionAnswerType<?>[] requiredArguments)SubCommand(int exactArgs, QuestionAnswerType<?>[] requiredArguments)SubCommand(QuestionAnswerType<?>... requiredArguments)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendUsage(java.lang.String usage)Appends the given usage to the usage of this command with a space before the new usage.SubCommandasync()Enables that theSubCommandExecutor.execute(SubCommand, ICommandSender, String, SubCommandArgumentWrapper, String, Properties, Map)method will be called asynchronously to the console threadbooleancheckValidArgsLength(int length)Checks whether the input length of arguments is valid according to the exact, min and max length of arguments specified for this command.SubCommanddisableMinArgsIndicator()Disables the "..." in thegetArgsAsString()methodSubCommandenableProperties()Allows extra properties for this sub commandjava.lang.StringgetArgsAsString()Gets all arguments of this sub command as a string.
Static strings (SubCommandArgumentTypes.exactString(String)SubCommandArgumentTypes.anyString(String...)or the ignore case methods) are never wrapped with brackets.
Dynamic strings (any otherQuestionAnswerType) are wrapped with "<>" if they are required and with "[]" if they are optional (this can be set with thesetMinArgs(int)andsetMaxArgs(int)methods).java.lang.StringgetDescription()intgetExactArgs()java.lang.StringgetExtendedUsage()de.dytanic.cloudnet.common.collection.Pair<java.lang.String,java.lang.Integer>getInvalidArgumentMessage(java.lang.String[] args)intgetMaxArgs()intgetMinArgs()java.util.Collection<java.lang.String>getNextPossibleArgumentAnswers(java.lang.String[] args)Gets the possible answers for the next argument by the given args array for auto completion.java.lang.StringgetPermission()QuestionAnswerType<?>[]getRequiredArguments()booleanisAsync()booleanisOnlyConsole()booleanmayLastArgContainSpaces()SubCommandonlyConsole()Disallows any execution of this command that is not from aConsoleCommandSender.SubCommandArgument<?>[]parseArgs(java.lang.String[] args)SubCommandArgument<?>[]parseArgsIgnoreLength(java.lang.String[] args)de.dytanic.cloudnet.common.PropertiesparseProperties(java.lang.String[] args)booleanrequiresExactArgs()Checks whether this command requires the exact length of input arguments or not.booleanrequiresMaxArgs()Checks whether this command requires a maximum length of input arguments.booleanrequiresMinArgs()Checks whether this command requires a minimal length of input argument.SubCommandsetExactArgs(int exactArgs)SubCommandsetMaxArgs(int maxArgs)SubCommandsetMinArgs(int minArgs)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.dytanic.cloudnet.command.sub.SubCommandExecutor
execute
-
-
-
-
Constructor Detail
-
SubCommand
public SubCommand(int exactArgs, QuestionAnswerType<?>[] requiredArguments)
-
SubCommand
public SubCommand(int minArgs, int exactArgs, int maxArgs, QuestionAnswerType<?>[] requiredArguments)
-
SubCommand
public SubCommand(QuestionAnswerType<?>... requiredArguments)
-
-
Method Detail
-
onlyConsole
public SubCommand onlyConsole()
Disallows any execution of this command that is not from aConsoleCommandSender.- Returns:
this
-
async
public SubCommand async()
Enables that theSubCommandExecutor.execute(SubCommand, ICommandSender, String, SubCommandArgumentWrapper, String, Properties, Map)method will be called asynchronously to the console thread- Returns:
this
-
disableMinArgsIndicator
public SubCommand disableMinArgsIndicator()
Disables the "..." in thegetArgsAsString()method- Returns:
this
-
enableProperties
public SubCommand enableProperties()
Allows extra properties for this sub command- Returns:
this
-
appendUsage
public void appendUsage(java.lang.String usage)
Appends the given usage to the usage of this command with a space before the new usage.- Parameters:
usage- the usage to be appended
-
requiresExactArgs
public boolean requiresExactArgs()
Checks whether this command requires the exact length of input arguments or not.- Returns:
trueif this command requires it orfalseif not
-
requiresMinArgs
public boolean requiresMinArgs()
Checks whether this command requires a minimal length of input argument.- Returns:
trueif this command requires it orfalseif not
-
mayLastArgContainSpaces
public boolean mayLastArgContainSpaces()
-
requiresMaxArgs
public boolean requiresMaxArgs()
Checks whether this command requires a maximum length of input arguments.- Returns:
trueif this command requires it orfalseif not
-
checkValidArgsLength
public boolean checkValidArgsLength(int length)
Checks whether the input length of arguments is valid according to the exact, min and max length of arguments specified for this command.- Parameters:
length- the input arguments length- Returns:
trueif the length matches orfalseif not- See Also:
requiresExactArgs(),requiresMinArgs(),requiresMaxArgs()
-
getInvalidArgumentMessage
public de.dytanic.cloudnet.common.collection.Pair<java.lang.String,java.lang.Integer> getInvalidArgumentMessage(java.lang.String[] args)
-
parseArgs
public SubCommandArgument<?>[] parseArgs(java.lang.String[] args)
-
parseArgsIgnoreLength
public SubCommandArgument<?>[] parseArgsIgnoreLength(java.lang.String[] args)
-
parseProperties
public de.dytanic.cloudnet.common.Properties parseProperties(java.lang.String[] args)
-
getNextPossibleArgumentAnswers
public java.util.Collection<java.lang.String> getNextPossibleArgumentAnswers(java.lang.String[] args)
Gets the possible answers for the next argument by the given args array for auto completion. All arguments in the array have to match to get any response.- Parameters:
args- the current args to get the next argument from- Returns:
- a list containing all possible answers or null, if no argument was found or the next argument doesn't have any answers defined
-
getArgsAsString
public java.lang.String getArgsAsString()
Gets all arguments of this sub command as a string.
Static strings (SubCommandArgumentTypes.exactString(String)SubCommandArgumentTypes.anyString(String...)or the ignore case methods) are never wrapped with brackets.
Dynamic strings (any otherQuestionAnswerType) are wrapped with "<>" if they are required and with "[]" if they are optional (this can be set with thesetMinArgs(int)andsetMaxArgs(int)methods).- Returns:
- the arguments as a string split by spaces (the argument
-
isOnlyConsole
public boolean isOnlyConsole()
-
isAsync
public boolean isAsync()
-
getPermission
public java.lang.String getPermission()
-
getDescription
public java.lang.String getDescription()
-
getExtendedUsage
public java.lang.String getExtendedUsage()
-
getMinArgs
public int getMinArgs()
-
setMinArgs
public SubCommand setMinArgs(int minArgs)
-
getExactArgs
public int getExactArgs()
-
setExactArgs
public SubCommand setExactArgs(int exactArgs)
-
getMaxArgs
public int getMaxArgs()
-
setMaxArgs
public SubCommand setMaxArgs(int maxArgs)
-
getRequiredArguments
public QuestionAnswerType<?>[] getRequiredArguments()
-
-