Class KamiCommand
java.lang.Object
com.kamikazejam.kamicommon.command.KamiCommand
- All Implemented Interfaces:
Active
,PluginIdentifiableCommand
- Direct Known Subclasses:
CmdGetItem
,CmdItemDump
,CmdLoadItem
,CmdModules
,CmdNmsTest
,CmdNmsVersion
,CmdOpenMenu
,CmdReload
,CmdSaveItem
,CmdTestMsg
,KamiCommandHelp
,KamiCommandVersion
,KamiCommonCommand
,UnmatchedCommand
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Message and Color configuration for KamiCommand messages. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAliases
(String @NotNull ... aliases) void
addAliases
(Collection<String> aliases) void
addChild
(KamiCommand child) void
addChild
(KamiCommand child, int index) void
addChildAfter
(KamiCommand child, KamiCommand after) <T> @NotNull Parameter
<T> addParameter
(@NotNull Parameter<T> parameter) <T> @NotNull Parameter
<T> addParameter
(Parameter.Builder<T> parameter) void
addRequirements
(Requirement @NotNull ... requirements) void
addRequirements
(Collection<Requirement> requirements) applyConcatenating
(List<String> args) boolean
argIsSet()
boolean
argIsSet
(int idx) final void
execute
(@NotNull CommandSender sender, @NotNull String label, @NotNull List<String> args) @NotNull KamiPlugin
static Set
<KamiCommand> @Nullable String
NOTICE: This Method is only relevant if this command is used as a ROOT COMMAND.
Get the permission that should be used for this command in Bukkit.
(This is the permission sent toCommand.setPermission(String)
when the command is registered)
Set a custom permission usingsetBukkitCommandPermission(String)
.
If no custom permission is set, then the permission is derived from theRequirementHasPerm
requirements set on the command.
(If noRequirementHasPerm
requirements are found, this command will not require any permission to execute)getChain
(boolean includeSelf) Returns the chain of commands leading to this command, like a stack trace.
The first element will be the root command.getCommandLine
(Iterable<String> args) int
@NotNull String
Returns the current command ran by the player.@NotNull String
Returns the current template chain for this command.@NotNull String
getCurrentTemplateUsage
(@NotNull CommandSender sender, boolean addDesc) Returns the current template usage for this command.getDesc()
@NotNull String
getFullTemplate
(boolean addDesc, boolean onlyFirstAlias, boolean onlyOneSubAlias, @Nullable CommandSender sender) @NotNull KMessageSingle
getHelpClickable
(@NotNull KamiCommand child, @NotNull CommandSender sender) @NotNull String
getHelpCommandLine
(@NotNull KamiCommand child) Given a subcommand (a child of this command), returns a fully qualified command line that includes the current command chain and the suggested subcommand alias.int
Parameter
<?> getParameter
(int index) int
getParameterCount
(CommandSender sender) int
int
Type
<?> getParameterType
(int index) getParents
(boolean includeSelf) Returns all parents of this command, like a stack trace.
The first element will be this command.@NotNull Plugin
getRequirementsError
(@NotNull CommandSender sender, boolean verbose) getRoot()
@NotNull KMessageSingle
getSuggestionClickable
(@NotNull KamiCommand suggested, @NotNull String token, @NotNull CommandSender sender) @NotNull String
getSuggestionCommandLine
(@NotNull KamiCommand suggested, @NotNull String token) Given a suggested subcommand (a child of this command), returns a fully qualified command line that includes the current command chain and the suggested subcommand alias.
The subcommand alias is chosen based on the provided token, which is expected to be a prefix of the alias.getTabCompletions
(List<String> args, CommandSender sender) getTabCompletionsArg
(List<String> args, CommandSender sender) getTabCompletionsChild
(@NotNull List<String> args, CommandSender sender) getTemplateParameters
(@Nullable CommandSender sender) getVisibleChildren
(CommandSender watcher) boolean
boolean
hasParameterForIndex
(int index) boolean
boolean
isActive()
boolean
isChild()
boolean
isFullChainMet
(CommandSender sender) boolean
isLeaf()
boolean
isParent()
protected boolean
isRelevant
(CommandSender sender) boolean
isRequirementsMet
(@NotNull CommandSender sender, boolean verbose) boolean
isRoot()
boolean
isVisibleTo
(CommandSender sender) void
onUnmatchedArg
(@NotNull CommandContext context) void
perform
(@NotNull CommandContext context) <T> T
readArg()
<T> T
readArg
(T defaultNotSet) void
registerCommand
(KamiPlugin plugin) If you register a command after the server has started, you must call the following method:
KamiCommonCommandRegistration.updateRegistrations()
In order for the command to be added to the server.int
removeChild
(KamiCommand child) void
int
replaceChild
(KamiCommand child, KamiCommand replaced) void
setActive
(boolean active) void
setActive
(@Nullable KamiPlugin plugin) void
setActivePlugin
(KamiPlugin activePlugin) void
setAliases
(String @NotNull ... aliases) void
setAliases
(Collection<String> aliases) void
setBukkitCommandPermission
(@Nullable String permission) NOTICE: This Method is only relevant if this command is used as a ROOT COMMAND.
Override the default command permission parsing.
(The permission sent toCommand.setPermission(String)
By default, the permission is derived from anyRequirementHasPerm
requirements set on the command.
You can optionally set a custom permission to use instead of the derived one.
Note:
- Setting this to null will cause the derived permission to be used again
- The only way to get a 'permission-less' command is to ensure there are noRequirementHasPerm
requirements.void
setConcatenating
(boolean concatenating) void
void
setHelpComments
(@NotNull KMessageBlock block) void
setHelpComments
(@NotNull List<KMessageSingle> helpComments) void
setOverflowSensitive
(boolean overflowSensitive) void
setParameter
(int index, Parameter<?> parameter) void
setParent
(KamiCommand parent) void
setRequirements
(List<Requirement> requirements) void
setSwapping
(boolean swapping) void
setTokenizing
(boolean tokenizing) void
setUnsmart
(boolean unsmart) void
If you unregister a command after the server has started, you must call the following method:void
validateActiveAndRoot
(Boolean active, Boolean root)
-
Constructor Details
-
KamiCommand
public KamiCommand()
-
-
Method Details
-
getAllInstances
-
registerCommand
If you register a command after the server has started, you must call the following method:
KamiCommonCommandRegistration.updateRegistrations()
In order for the command to be added to the server. -
unregisterCommand
public void unregisterCommand()If you unregister a command after the server has started, you must call the following method:- See Also:
-
isActive
public boolean isActive() -
setActive
public void setActive(boolean active) -
setActivePlugin
- Specified by:
setActivePlugin
in interfaceActive
-
getActivePlugin
- Specified by:
getActivePlugin
in interfaceActive
-
setActive
-
validateActiveAndRoot
-
getPlugin
- Specified by:
getPlugin
in interfacePluginIdentifiableCommand
-
hasParent
public boolean hasParent() -
isChild
public boolean isChild() -
isRoot
public boolean isRoot() -
hasChildren
public boolean hasChildren() -
isParent
public boolean isParent() -
isLeaf
public boolean isLeaf() -
getVisibleChildren
-
getRoot
-
getParents
Returns all parents of this command, like a stack trace.
The first element will be this command. The root command is last in the list. -
getChain
Returns the chain of commands leading to this command, like a stack trace.
The first element will be the root command. This command is last in the list. -
removeParent
public void removeParent() -
setParent
-
addChild
-
addChildAfter
-
replaceChild
-
removeChild
-
addChild
-
getHelpCommand
-
getChild
-
isRelevant
-
setAliases
-
setAliases
-
addAliases
-
addAliases
-
getParameter
-
getParameterType
-
setParameter
-
hasParameterForIndex
public boolean hasParameterForIndex(int index) -
getPageParameterIndex
public int getPageParameterIndex() -
getParameterCount
-
getParameterCountRequired
-
getParameterCountOptional
-
addParameter
-
addParameter
@Contract(mutates="this") @NotNull public <T> @NotNull Parameter<T> addParameter(@NotNull Parameter.Builder<T> parameter) -
setTokenizing
@Contract(mutates="this") public void setTokenizing(boolean tokenizing) -
setUnsmart
@Contract(mutates="this") public void setUnsmart(boolean unsmart) -
setOverflowSensitive
@Contract(mutates="this") public void setOverflowSensitive(boolean overflowSensitive) -
setConcatenating
@Contract(mutates="this") public void setConcatenating(boolean concatenating) -
getConcatenationIndex
public int getConcatenationIndex() -
setSwapping
@Contract(mutates="this") public void setSwapping(boolean swapping) -
setRequirements
-
addRequirements
-
addRequirements
-
isRequirementsMet
-
getRequirementsError
-
setDesc
-
getDesc
-
getDescPermission
-
isVisibleTo
-
execute
public final void execute(@NotNull @NotNull CommandSender sender, @NotNull @NotNull String label, @NotNull @NotNull List<String> args) - Parameters:
label
- The specific label (or 'alias') used for this KamiCommand.
-
perform
- Throws:
KamiCommonException
-
getSuggestionClickable
@NotNull public @NotNull KMessageSingle getSuggestionClickable(@NotNull @NotNull KamiCommand suggested, @NotNull @NotNull String token, @NotNull @NotNull CommandSender sender) - Parameters:
suggested
- The command that should be suggested to the user. (subcommand of this command)token
- The token used that triggered this possible suggestion. (likely a partial alias)
-
getSuggestionCommandLine
@NotNull public @NotNull String getSuggestionCommandLine(@NotNull @NotNull KamiCommand suggested, @NotNull @NotNull String token) Given a suggested subcommand (a child of this command), returns a fully qualified command line that includes the current command chain and the suggested subcommand alias.
The subcommand alias is chosen based on the provided token, which is expected to be a prefix of the alias. -
getHelpClickable
@NotNull public @NotNull KMessageSingle getHelpClickable(@NotNull @NotNull KamiCommand child, @NotNull @NotNull CommandSender sender) - Parameters:
child
- The command that should be suggested to the user. (subcommand of this command)
-
getHelpCommandLine
Given a subcommand (a child of this command), returns a fully qualified command line that includes the current command chain and the suggested subcommand alias. -
getCurrentTemplateChain
Returns the current template chain for this command. Requires an active command instance with non-null context.
The chain is the color coded concatenation of all command labels thus far (no parameters or descriptions). -
getCurrentTemplateUsage
@NotNull public @NotNull String getCurrentTemplateUsage(@NotNull @NotNull CommandSender sender, boolean addDesc) Returns the current template usage for this command. Requires an active command instance with non-null context.
The usage is the color coded concatenation of all command labels thus far, followed by parameters and description. -
getCurrentCommandLine
Returns the current command ran by the player. Requires an active command instance with non-null context.
Includes a leading slash. -
getFullTemplate
@NotNull public @NotNull String getFullTemplate(boolean addDesc, boolean onlyFirstAlias, boolean onlyOneSubAlias, @Nullable @Nullable CommandSender sender) -
isFullChainMet
-
onUnmatchedArg
-
getTemplateParameters
@NotNull protected @NotNull List<String> getTemplateParameters(@Nullable @Nullable CommandSender sender) -
getCommandLine
-
getTabCompletions
@Contract("null, _ -> fail; !null, null -> fail") public List<String> getTabCompletions(List<String> args, CommandSender sender) -
getTabCompletionsChild
protected List<String> getTabCompletionsChild(@NotNull @NotNull List<String> args, CommandSender sender) -
getTabCompletionsArg
-
applyConcatenating
-
argIsSet
public boolean argIsSet(int idx) -
argIsSet
public boolean argIsSet() -
readArg
- Throws:
KamiCommonException
-
readArg
- Throws:
KamiCommonException
-
setHelpComments
-
setHelpComments
-
setBukkitCommandPermission
NOTICE: This Method is only relevant if this command is used as a ROOT COMMAND.
Override the default command permission parsing.
(The permission sent toCommand.setPermission(String)
By default, the permission is derived from anyRequirementHasPerm
requirements set on the command.
You can optionally set a custom permission to use instead of the derived one.
Note:
- Setting this to null will cause the derived permission to be used again
- The only way to get a 'permission-less' command is to ensure there are noRequirementHasPerm
requirements. -
getBukkitCommandPermission
NOTICE: This Method is only relevant if this command is used as a ROOT COMMAND.
Get the permission that should be used for this command in Bukkit.
(This is the permission sent toCommand.setPermission(String)
when the command is registered)
Set a custom permission usingsetBukkitCommandPermission(String)
.
If no custom permission is set, then the permission is derived from theRequirementHasPerm
requirements set on the command.
(If noRequirementHasPerm
requirements are found, this command will not require any permission to execute)
-