Class CommandManager
命令管理器
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<UltiToolsPlugin, List<org.bukkit.command.Command>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Unregister all commands.private org.bukkit.command.PluginCommandgetCommand(String name, org.bukkit.plugin.Plugin plugin) private org.bukkit.command.CommandMapgetPluginByCommand(org.bukkit.command.Command command) Get the plugin instance by command.voidregister(UltiToolsPlugin plugin, Class<? extends org.bukkit.command.CommandExecutor> clazz) Manually register a command.voidregister(UltiToolsPlugin plugin, Class<? extends org.bukkit.command.CommandExecutor> clazz, String permission, String description, String... aliases) Manually register a command.private voidregister(UltiToolsPlugin plugin, org.bukkit.command.CommandExecutor commandExecutor) Manually register a command, will not be managed by the container.private voidregister(UltiToolsPlugin plugin, org.bukkit.command.CommandExecutor commandExecutor, String permission, String description, String... aliases) Manually register a command, will not be managed by the container.voidregister(org.bukkit.command.CommandExecutor commandExecutor) Deprecated, for removal: This API element is subject to removal in a future version.voidregister(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.voidregisterAll(UltiToolsPlugin plugin) Register all classes annotated with @CmdExecutor in the specified package.voidregisterAll(UltiToolsPlugin plugin, String packageName) Deprecated, for removal: This API element is subject to removal in a future version.This overload casts every scanned class toAbstractCommandExecutor, which is itself scheduled for removal in 6.3.0.voidregisterAllExternal(ExternalPluginAdapter adapter) Register all @CmdExecutor commands from an external plugin's IoC container.voidregisterCoreCommand(org.bukkit.command.CommandExecutor commandExecutor) Register command for core UltiTools commands that don't belong to a specific plugin module.private voidregisterExternalCommand(String pluginName, org.bukkit.command.CommandExecutor executor, CmdExecutor annotation) voidunregister(String name) voidunregisterAll(UltiToolsPlugin plugin) voidunregisterAllExternal(String pluginName) Unregister all commands for an external plugin.
-
Field Details
-
commandListMap
-
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
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 toAbstractCommandExecutor, which is itself scheduled for removal in 6.3.0. A command class written against the currentBaseCommandExecutordoes not extend that type, so the cast throwsClassCastException— and the surrounding catch lists only the four reflective checked exceptions, so it escapes. UseregisterAll(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
Register all classes annotated with @CmdExecutor in the specified package. Dependencies will be injected automatically.- Parameters:
plugin- UltiTools Plugin instance
模块实例
-
getPluginByCommand
Get the plugin instance by command.通过命令获取模块实例
- Parameters:
command- Command
命令- Returns:
- UltiTools plugin
模块实例
-
unregister
- Parameters:
name- Command name
命令名
-
unregisterAll
- 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, useregister(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.Useregister(UltiToolsPlugin, Class)instead.Don't use this method to register commands, useregister(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
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
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
-
getCommandMap
private org.bukkit.command.CommandMap getCommandMap()
-
register(UltiToolsPlugin, Class)instead.