Class CommandManager

java.lang.Object
net.citizensnpcs.api.command.CommandManager
All Implemented Interfaces:
TabCompleter

public class CommandManager extends Object implements TabCompleter
  • Constructor Details

    • CommandManager

      public CommandManager()
  • Method Details

    • execute

      public void execute(Command command, String[] args, CommandSender sender, Object... methodArgs) throws CommandException
      Attempt to execute a command using the root Command given. A list of method arguments may be used when calling the command handler method. A command handler method should follow the form command(CommandContext args, CommandSender sender) where CommandSender can be replaced with Player to only accept players. The method parameters must include the method args given, if any.
      Parameters:
      command - The command to execute
      args - The arguments of the command
      sender - The sender of the command
      methodArgs - The method arguments to be used when calling the command handler
      Throws:
      CommandException - Any exceptions caused from execution of the command
    • executeSafe

      public boolean executeSafe(Command command, String[] args, CommandSender sender, Object... methodArgs)
      A safe version of execute(org.bukkit.command.Command, String[], CommandSender, Object...) which catches and logs all Exceptions that occur.
      Returns:
      Whether command usage should be printed
      See Also:
    • getClosestCommandModifier

      public String getClosestCommandModifier(String command, String modifier)
      Searches for the closest modifier using Levenshtein distance to the given top level command and modifier.
      Parameters:
      command - The top level command
      modifier - The modifier to use as the base
      Returns:
      The closest modifier, or empty
    • getCommand

      public CommandManager.CommandInfo getCommand(String... commandParts)
      Gets the CommandManager.CommandInfo for the given command parts, or null if not found.
      Parameters:
      commandParts - The parts of the command
      Returns:
      The command info for the command
    • getCommands

      public List<CommandManager.CommandInfo> getCommands(String topLevelCommand)
      Gets all modified and root commands from the given root level command. For example, if /npc look and /npc jump were defined, calling getCommands("npc") would return CommandManager.CommandInfos for both commands.
      Parameters:
      topLevelCommand - The root level command
      Returns:
      The list of CommandManager.CommandInfos
    • hasCommand

      public boolean hasCommand(Command cmd, String... modifier)
      Checks to see whether there is a command handler for the given command at the root level. This will check aliases as well.
      Parameters:
      cmd - The command to check
      modifier - The modifier to check (may be empty)
      Returns:
      Whether the command is handled
    • hasCommand

      public boolean hasCommand(String... parts)
      Checks to see whether there is a command handler for the given command parts at the root level. This will check aliases as well.
      Parameters:
      parts - The parts to check (must not be empty)
      Returns:
      Whether the command is handled
    • onTabComplete

      public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args)
      Specified by:
      onTabComplete in interface TabCompleter
    • register

      public void register(Class<?> clazz)
      Register a class that contains commands (methods annotated with Command). If no dependency Injector is specified, then only static methods of the class will be registered. Otherwise, new instances the command class will be created and instance methods will be called.
      Parameters:
      clazz - The class to scan
      See Also:
    • registerAnnotationProcessor

      public void registerAnnotationProcessor(CommandAnnotationProcessor processor)
      Registers an CommandAnnotationProcessor that can process annotations before a command is executed. Methods with the Command annotation will have the rest of their annotations scanned and stored if there is a matching CommandAnnotationProcessor. Annotations that do not have a processor are discarded. The scanning method uses annotations from the declaring class as a base before narrowing using the method's annotations.
      Parameters:
      processor - The annotation processor
    • registerTabCompletion

      public void registerTabCompletion(JavaPlugin plugin)
    • setDefaultDurationUnits

      public void setDefaultDurationUnits(TimeUnit unit)
    • setInjector

      public void setInjector(Injector injector)