Class CommandManager

java.lang.Object
com.ultikits.ultitools.manager.CommandManager

public class CommandManager extends Object
Command manager.

命令管理器

  • Field Details

    • commandListMap

      private final Map<UltiToolsPlugin,List<org.bukkit.command.Command>> commandListMap
    • externalCommandMap

      private final Map<String,List<org.bukkit.command.Command>> externalCommandMap
  • Constructor Details

    • CommandManager

      public CommandManager()
  • Method Details

    • register

      public void register(UltiToolsPlugin plugin, Class<? extends org.bukkit.command.CommandExecutor> clazz, String permission, String description, String... aliases)
      Manually register a command. Only used to register classes annotated with @CmdExecutor. Dependencies will be injected automatically.

      手动注册一个命令。仅用于注册被@CmdExecutor注解的类。会自动注入依赖。

      Parameters:
      plugin - UltiTools Plugin instance
      模块实例
      clazz - Command executor class
      命令执行器类
      permission - Permission
      权限
      description - Description
      描述
      aliases - Aliases
      别名
    • register

      private void register(UltiToolsPlugin plugin, org.bukkit.command.CommandExecutor commandExecutor, String permission, String description, String... aliases)
      Manually register a command, will not be managed by the container. Dependencies will not be injected automatically.

      手动注册一个命令,不会被容器管理。不会自动注入依赖。

      Parameters:
      plugin - UltiTools Plugin instance
      模块实例
      commandExecutor - Command executor instance
      命令执行器实例
      permission - Permission
      权限
      description - Description
      描述
      aliases - Aliases
      别名
    • register

      public void register(UltiToolsPlugin plugin, Class<? extends org.bukkit.command.CommandExecutor> clazz)
      Manually register a command. Only used to register classes annotated with @CmdExecutor. Dependencies will be injected automatically.

      手动注册一个命令。仅用于注册被@CmdExecutor注解的类。会自动注入依赖。

      Parameters:
      plugin - UltiTools Plugin instance
      模块实例
      clazz - Command executor class
      命令执行器类
    • register

      private void register(UltiToolsPlugin plugin, org.bukkit.command.CommandExecutor commandExecutor)
      Manually register a command, will not be managed by the container. Dependencies will not be injected automatically.

      手动注册一个命令,不会被容器管理。不会自动注入依赖。

      Parameters:
      plugin - UltiTools Plugin instance
      模块实例
      commandExecutor - Command executor instance
      命令执行器实例
    • registerAll

      @Deprecated(since="6.2.5", forRemoval=true) public void registerAll(UltiToolsPlugin plugin, String packageName)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This overload casts every scanned class to AbstractCommandExecutor, which is itself scheduled for removal in 6.3.0. A command class written against the current BaseCommandExecutor does not extend that type, so the cast throws ClassCastException — and the surrounding catch lists only the four reflective checked exceptions, so it escapes. Use registerAll(UltiToolsPlugin), which resolves command classes as beans from the plugin's container and performs no cast. See issue #272.

      这个重载把扫描到的每个类都强转为 AbstractCommandExecutor, 而后者本身已计划在 6.3.0 移除。按当前推荐写法继承 BaseCommandExecutor 的命令类不属于那个类型,强转必抛 ClassCastException, 且外层 catch 只列了四个反射类受检异常,异常会逃出去。 请改用 registerAll(UltiToolsPlugin) —— 它从模块容器里按 bean 解析命令类,不做强转。见 issue #272。

      Register all classes annotated with @CmdExecutor in the specified package. Dependencies will be injected automatically.

      注册指定包下所有被@CmdExecutor注解的类。会自动注入依赖。

      Parameters:
      plugin - UltiTools Plugin instance
      模块实例
      packageName - Package name
      包名
    • registerAll

      public void registerAll(UltiToolsPlugin plugin)
      Register all classes annotated with @CmdExecutor in the specified package. Dependencies will be injected automatically.

      Parameters:
      plugin - UltiTools Plugin instance
      模块实例
    • getPluginByCommand

      public UltiToolsPlugin getPluginByCommand(org.bukkit.command.Command command)
      Get the plugin instance by command.

      通过命令获取模块实例

      Parameters:
      command - Command
      命令
      Returns:
      UltiTools plugin
      模块实例
    • unregister

      public void unregister(String name)
      Parameters:
      name - Command name
      命令名
    • unregisterAll

      public void unregisterAll(UltiToolsPlugin plugin)
      Parameters:
      plugin - UltiTools Plugin instance
      模块实例
    • close

      public void close()
      Unregister all commands.
    • register

      @Deprecated(since="6.0.5", forRemoval=true) public void register(org.bukkit.command.CommandExecutor commandExecutor, String permission, String description, String... aliases)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Don't use this method to register commands, use register(UltiToolsPlugin, Class, String, String, String...) instead.

      不要使用此方法注册命令,使用register(UltiToolsPlugin, Class, String, String, String...)代替。

      Parameters:
      commandExecutor - Command executor instance
      命令执行器实例
      permission - Permission
      权限
      description - Description
      描述
      aliases - Aliases
      别名
    • register

      @Deprecated(since="6.0.5", forRemoval=true) public void register(org.bukkit.command.CommandExecutor commandExecutor)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Don't use this method to register commands, use register(UltiToolsPlugin, Class) instead.

      不要使用此方法注册命令,使用register(UltiToolsPlugin, Class)代替。

      Parameters:
      commandExecutor - Command executor instance
      命令执行器实例
    • registerCoreCommand

      public void registerCoreCommand(org.bukkit.command.CommandExecutor commandExecutor)
      Register command for core UltiTools commands that don't belong to a specific plugin module. This method is specifically for commands that are part of the main UltiTools plugin.

      为不属于特定插件模块的核心UltiTools命令注册命令。 此方法专门用于主UltiTools插件的命令。

      Parameters:
      commandExecutor - Command executor instance
      命令执行器实例
    • registerAllExternal

      public void registerAllExternal(ExternalPluginAdapter adapter)
      Register all @CmdExecutor commands from an external plugin's IoC container. Uses raw description (no i18n) since external plugins don't have UltiTools i18n.

      注册外部插件 IoC 容器中所有 @CmdExecutor 命令。

      Parameters:
      adapter - the external plugin adapter
      Since:
      6.2.2
    • unregisterAllExternal

      public void unregisterAllExternal(String pluginName)
      Unregister all commands for an external plugin.

      注销外部插件的所有命令。

      Parameters:
      pluginName - the external plugin name
      Since:
      6.2.2
    • registerExternalCommand

      private void registerExternalCommand(String pluginName, org.bukkit.command.CommandExecutor executor, CmdExecutor annotation)
    • getCommand

      private org.bukkit.command.PluginCommand getCommand(String name, org.bukkit.plugin.Plugin plugin)
    • getCommandMap

      private org.bukkit.command.CommandMap getCommandMap()