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.private StringnamespacedKey(String label) Builds the namespaced known-commands key (fallbackPrefix:label) thatregisterCommandDirect(CommandExecutor, String, String, String...)'sCommandMap.register(String, Command)call always populates forlabel, regardless of whether the bare label slot was won or lost to a bare-label conflict.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.voidregisterAll(UltiToolsPlugin plugin) Register all classes annotated with @CmdExecutor in the specified package.voidregisterAllExternal(ExternalPluginAdapter adapter) Register all @CmdExecutor commands from an external plugin's IoC container.private voidregisterCommandDirect(org.bukkit.command.CommandExecutor commandExecutor) ResolvescommandExecutor's@CmdExecutorannotation (if present) and dispatches toregisterCommandDirect(CommandExecutor, String, String, String...); logs and does nothing otherwise.private org.bukkit.command.PluginCommandregisterCommandDirect(org.bukkit.command.CommandExecutor commandExecutor, String permission, String description, String... aliases) RegisterscommandExecutorwith Bukkit's command map directly, with no plugin container involvement -- the primitive behindregisterCoreCommand(CommandExecutor),registerExternalCommand(String, CommandExecutor, CmdExecutor), and the unannotated-class fallback inregister(UltiToolsPlugin, CommandExecutor).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) private voidremoveFromKnownCommands(org.bukkit.command.CommandMap commandMap, org.bukkit.command.Command command) Removes every entry fromcommandMap's known-commands table whose value is exactlycommand(reference identity, not key/label text matching).voidunregister(String name) Unregisters the live command labellednamefrom Bukkit, including its entries in the command map's known-commands table.voidunregisterAll(UltiToolsPlugin plugin) Unregisters every command this framework registered forplugin, using the actual registeredCommandinstances tracked incommandListMap(seeregister(UltiToolsPlugin, CommandExecutor, String, String, String...)) -- not a name-based relookup, which could mis-resolve a different module's command if two modules share a primary alias under this framework's shared fallback prefix.voidunregisterAllExternal(String pluginName) Unregister all commands for an external plugin, using the actual registeredCommandinstances tracked inexternalCommandMap(seeregisterExternalCommand(String, CommandExecutor, CmdExecutor)) -- not a name-based relookup, for the same reason asunregisterAll(UltiToolsPlugin).private voidunregisterCommand(org.bukkit.command.CommandMap commandMap, org.bukkit.command.Command command) Unregisters the exactcommandinstance from Bukkit: purges its entries from the command map's known-commands table, then clears its own registration state.
-
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.- Parameters:
plugin- UltiTools Plugin instanceclazz- Command executor classpermission- Permissiondescription- Descriptionaliases- 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 instancecommandExecutor- Command executor instancepermission- Permissiondescription- Descriptionaliases- 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.- Parameters:
plugin- UltiTools Plugin instanceclazz- 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 instancecommandExecutor- Command executor instance
-
registerCommandDirect
private org.bukkit.command.PluginCommand registerCommandDirect(org.bukkit.command.CommandExecutor commandExecutor, String permission, String description, String... aliases) RegisterscommandExecutorwith Bukkit's command map directly, with no plugin container involvement -- the primitive behindregisterCoreCommand(CommandExecutor),registerExternalCommand(String, CommandExecutor, CmdExecutor), and the unannotated-class fallback inregister(UltiToolsPlugin, CommandExecutor).Returns the exact
PluginCommandinstance handed toCommandMap.register(String, Command)so callers that need to unregister it later (e.g.register(UltiToolsPlugin, CommandExecutor, String, String, String...),registerExternalCommand(String, CommandExecutor, CmdExecutor)) can store and unregister THAT instance directly, rather than reconstructing a separategetCommand(String, Plugin)decoy that was never actually registered (Codex review on PR #457, plan 16-02: a name/namespaced-key relookup at unregister time can resolve a DIFFERENT module's command if two modules share both the framework's fallback prefix and the same primary alias).- Parameters:
commandExecutor- Command executor instancepermission- Permissiondescription- Descriptionaliases- Aliases- Returns:
- the actual registered
PluginCommandinstance
-
registerCommandDirect
private void registerCommandDirect(org.bukkit.command.CommandExecutor commandExecutor) ResolvescommandExecutor's@CmdExecutorannotation (if present) and dispatches toregisterCommandDirect(CommandExecutor, String, String, String...); logs and does nothing otherwise. The registered command is not tracked for later unregistration -- this is the core-command path (registerCoreCommand(CommandExecutor)), whose commands live for the whole plugin lifetime.- Parameters:
commandExecutor- Command executor instance
-
registerAll
Register all classes annotated with @CmdExecutor in the specified package. Dependencies will be injected automatically.Beans are enumerated by name, so an executor bound under several names (a
@Bean(name = {primary, alias})product) is reached once per name; it is registered with Bukkit once, on the first name (C50).- Parameters:
plugin- UltiTools Plugin instance
-
getPluginByCommand
Get the plugin instance by command.- Parameters:
command- Command- Returns:
- UltiTools plugin
-
unregister
Unregisters the live command labellednamefrom Bukkit, including its entries in the command map's known-commands table.This name-only overload is a best-effort public entry point for callers that hold nothing but a label (no
Commandreference to hand back). It resolves the actual currently-registeredCommandvia its namespaced key (fallbackPrefix:name) rather than the barename--SimpleCommandMap.registerlets a later, overridable registration steal the bare-label slot, sogetCommand(name)could resolve a different plugin's command after such a takeover, while the namespaced key is put unconditionally regardless of any bare-label conflict.That said, the namespaced key is only unique to this framework's own registrations: two different UltiTools modules sharing the same primary alias also share this framework's fallback prefix, so
fallbackPrefix:namecollides between them too, and this overload cannot tell them apart (Codex review on PR #457, plan 16-02).unregisterAll(UltiToolsPlugin)andunregisterAllExternal(String)do not have this ambiguity -- they hold the actual registeredCommandinstance fromcommandListMap/externalCommandMapand unregister it directly viaunregisterCommand(CommandMap, Command), bypassing name resolution entirely.- Parameters:
name- Command name
-
unregisterCommand
private void unregisterCommand(org.bukkit.command.CommandMap commandMap, org.bukkit.command.Command command) Unregisters the exactcommandinstance from Bukkit: purges its entries from the command map's known-commands table, then clears its own registration state.This is the airtight form -- no name or key resolution is involved, so it cannot mis-resolve a different module's command the way
unregister(String)'s namespaced-key lookup can when two modules share both the framework's fallback prefix and a primary alias.- Parameters:
commandMap- the live Bukkit command mapcommand- the specific, already-resolved command instance to unregister
-
namespacedKey
Builds the namespaced known-commands key (fallbackPrefix:label) thatregisterCommandDirect(CommandExecutor, String, String, String...)'sCommandMap.register(String, Command)call always populates forlabel, regardless of whether the bare label slot was won or lost to a bare-label conflict. The fallback prefix mirrorsregisterCommandDirect's own:UltiTools.getInstance().getDescription().getName().- Parameters:
label- the command's bare label or alias- Returns:
- the namespaced key that uniquely identifies this framework's own registration
-
removeFromKnownCommands
private void removeFromKnownCommands(org.bukkit.command.CommandMap commandMap, org.bukkit.command.Command command) Removes every entry fromcommandMap's known-commands table whose value is exactlycommand(reference identity, not key/label text matching).Command.unregister(CommandMap)only clears the command's owncommandMap/label/activeAliasesfields (verified by reading its bytecode against this Paper version) -- it never touchesCommandMap.getKnownCommands().SimpleCommandMap.register(String, String, Command)puts a command under FOUR kinds of keys pointing at the same instance: the bare label, every bare alias,fallbackPrefix:label, andfallbackPrefix:aliasfor each alias. Left alone, every one of those keys keeps resolving to the unregistered module's executor after unload (measured on a real Paper 1.21.11 server:/upm uninstallfollowed by the module's own command still executing -- PR #457 real-machine UAT, plan 16-02).Matching by reference identity rather than by key text is deliberate: Bukkit allows a later-registered overridable command to take over an earlier command's bare label slot, in which case that key's VALUE is a different
Commandinstance and must be left untouched -- only entries whose value iscommanditself are removed.- Parameters:
commandMap- the live Bukkit command mapcommand- the specific command instance to purge
-
unregisterAll
Unregisters every command this framework registered forplugin, using the actual registeredCommandinstances tracked incommandListMap(seeregister(UltiToolsPlugin, CommandExecutor, String, String, String...)) -- not a name-based relookup, which could mis-resolve a different module's command if two modules share a primary alias under this framework's shared fallback prefix.Once those commands are released,
pluginis no longer tracked: this manager then references neither the unloaded module nor its command objects, andgetPluginByCommand(Command)can no longer return it. A later registration for the same instance starts a new list.- Parameters:
plugin- UltiTools Plugin instance
-
close
public void close()Unregister all commands. -
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.- 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. An executor bound under several names is registered once (C50), as inregisterAll(UltiToolsPlugin).- Parameters:
adapter- the external plugin adapter- Since:
- 6.2.2
-
unregisterAllExternal
Unregister all commands for an external plugin, using the actual registeredCommandinstances tracked inexternalCommandMap(seeregisterExternalCommand(String, CommandExecutor, CmdExecutor)) -- not a name-based relookup, for the same reason asunregisterAll(UltiToolsPlugin).- 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()
-