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

public class KamiCommand extends Object implements Active, PluginIdentifiableCommand
  • Constructor Details

    • KamiCommand

      public KamiCommand()
  • Method Details

    • getAllInstances

      @Contract(pure=true) public static Set<KamiCommand> getAllInstances()
    • registerCommand

      public 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.
    • 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()
      Specified by:
      isActive in interface Active
    • setActive

      public void setActive(boolean active)
      Specified by:
      setActive in interface Active
    • setActivePlugin

      public void setActivePlugin(KamiPlugin activePlugin)
      Specified by:
      setActivePlugin in interface Active
    • getActivePlugin

      @NotNull public @NotNull KamiPlugin getActivePlugin()
      Specified by:
      getActivePlugin in interface Active
    • setActive

      public void setActive(@Nullable @Nullable KamiPlugin plugin)
      Specified by:
      setActive in interface Active
    • validateActiveAndRoot

      public void validateActiveAndRoot(Boolean active, Boolean root)
    • getPlugin

      @NotNull public @NotNull Plugin getPlugin()
      Specified by:
      getPlugin in interface PluginIdentifiableCommand
    • 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

      public List<KamiCommand> getVisibleChildren(CommandSender watcher)
    • getRoot

      public KamiCommand getRoot()
    • getParents

      public List<KamiCommand> getParents(boolean includeSelf)
      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

      public List<KamiCommand> getChain(boolean includeSelf)
      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

      @Contract(mutates="this,param1") public void setParent(KamiCommand parent)
    • addChild

      @Contract(mutates="this") public void addChild(KamiCommand child)
    • addChildAfter

      @Contract(mutates="this") public void addChildAfter(KamiCommand child, KamiCommand after)
    • replaceChild

      public int replaceChild(KamiCommand child, KamiCommand replaced)
    • removeChild

      public int removeChild(KamiCommand child)
    • addChild

      public void addChild(KamiCommand child, int index)
    • getHelpCommand

      public KamiCommandHelp getHelpCommand()
    • getChild

      public KamiCommand getChild(String token)
    • isRelevant

      protected boolean isRelevant(CommandSender sender)
    • setAliases

      @Contract(mutates="this") public void setAliases(Collection<String> aliases)
    • setAliases

      @Contract(mutates="this") public void setAliases(String @NotNull ... aliases)
    • addAliases

      @Contract(mutates="this") public void addAliases(Collection<String> aliases)
    • addAliases

      @Contract(mutates="this") public void addAliases(String @NotNull ... aliases)
    • getParameter

      public Parameter<?> getParameter(int index)
    • getParameterType

      public Type<?> getParameterType(int index)
    • setParameter

      public void setParameter(int index, Parameter<?> parameter)
    • hasParameterForIndex

      public boolean hasParameterForIndex(int index)
    • getPageParameterIndex

      public int getPageParameterIndex()
    • getParameterCount

      public int getParameterCount(CommandSender sender)
    • getParameterCountRequired

      public int getParameterCountRequired(CommandSender sender)
    • getParameterCountOptional

      public int getParameterCountOptional(CommandSender sender)
    • addParameter

      @Contract(mutates="this") @NotNull public <T> @NotNull Parameter<T> addParameter(@NotNull @NotNull Parameter<T> parameter)
    • 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

      @Contract(mutates="this") public void setRequirements(List<Requirement> requirements)
    • addRequirements

      @Contract(mutates="this") public void addRequirements(Collection<Requirement> requirements)
    • addRequirements

      @Contract(mutates="this") public void addRequirements(Requirement @NotNull ... requirements)
    • isRequirementsMet

      public boolean isRequirementsMet(@NotNull @NotNull CommandSender sender, boolean verbose)
    • getRequirementsError

      public String getRequirementsError(@NotNull @NotNull CommandSender sender, boolean verbose)
    • setDesc

      @Contract(mutates="this") public void setDesc(String desc)
    • getDesc

      public String getDesc()
    • getDescPermission

      public String getDescPermission()
    • isVisibleTo

      public boolean isVisibleTo(CommandSender sender)
    • 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

      public void perform(@NotNull @NotNull CommandContext context) throws KamiCommonException
      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

      @NotNull public @NotNull String getHelpCommandLine(@NotNull @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.
    • getCurrentTemplateChain

      @NotNull public @NotNull String 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

      @NotNull public @NotNull String 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

      public boolean isFullChainMet(CommandSender sender)
    • onUnmatchedArg

      public void onUnmatchedArg(@NotNull @NotNull CommandContext context)
    • getTemplateParameters

      @NotNull protected @NotNull List<String> getTemplateParameters(@Nullable @Nullable CommandSender sender)
    • getCommandLine

      public String getCommandLine(Iterable<String> args)
    • 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

      protected List<String> getTabCompletionsArg(List<String> args, CommandSender sender)
    • applyConcatenating

      public List<String> applyConcatenating(List<String> args)
    • argIsSet

      public boolean argIsSet(int idx)
    • argIsSet

      public boolean argIsSet()
    • readArg

      public <T> T readArg() throws KamiCommonException
      Throws:
      KamiCommonException
    • readArg

      public <T> T readArg(T defaultNotSet) throws KamiCommonException
      Throws:
      KamiCommonException
    • setHelpComments

      public void setHelpComments(@NotNull @NotNull List<KMessageSingle> helpComments)
    • setHelpComments

      public void setHelpComments(@NotNull @NotNull KMessageBlock block)
    • setBukkitCommandPermission

      public void setBukkitCommandPermission(@Nullable @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 to Command.setPermission(String)

      By default, the permission is derived from any RequirementHasPerm 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 no RequirementHasPerm requirements.
    • getBukkitCommandPermission

      @Nullable public @Nullable String 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 to Command.setPermission(String) when the command is registered)

      Set a custom permission using setBukkitCommandPermission(String).
      If no custom permission is set, then the permission is derived from the RequirementHasPerm requirements set on the command.
      (If no RequirementHasPerm requirements are found, this command will not require any permission to execute)