mirror of
https://github.com/aikar/commands.git
synced 2026-05-31 06:11:55 +00:00
Fix unregister of bukkit/bungee commands.
A RootCommand is shared between any BaseCommand that all use the same root. We should not unregister the root command until all sub commands are unregistered.
This commit is contained in:
@@ -182,13 +182,19 @@ public class BukkitCommandManager extends CommandManager<CommandSender, ChatColo
|
||||
public void unregisterCommand(BaseCommand command) {
|
||||
for (RootCommand rootcommand : command.registeredCommands.values()) {
|
||||
BukkitRootCommand bukkitCommand = (BukkitRootCommand) rootcommand;
|
||||
if (bukkitCommand.isRegistered) {
|
||||
bukkitCommand.getSubCommands().values().removeAll(command.subCommands.values());
|
||||
if (bukkitCommand.isRegistered && bukkitCommand.getSubCommands().isEmpty()) {
|
||||
unregisterCommand(bukkitCommand);
|
||||
bukkitCommand.isRegistered = false;
|
||||
}
|
||||
bukkitCommand.isRegistered = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use unregisterCommand(BaseCommand) - this will be visibility reduced later.
|
||||
* @param command
|
||||
*/
|
||||
@Deprecated
|
||||
public void unregisterCommand(BukkitRootCommand command) {
|
||||
final String plugin = this.plugin.getName().toLowerCase();
|
||||
command.unregister(commandMap);
|
||||
@@ -204,6 +210,7 @@ public class BukkitCommandManager extends CommandManager<CommandSender, ChatColo
|
||||
for (Map.Entry<String, BukkitRootCommand> entry : registeredCommands.entrySet()) {
|
||||
unregisterCommand(entry.getValue());
|
||||
}
|
||||
this.registeredCommands.clear();
|
||||
}
|
||||
|
||||
private class ACFBukkitListener implements Listener {
|
||||
|
||||
@@ -101,11 +101,12 @@ public class BungeeCommandManager extends CommandManager<CommandSender, ChatColo
|
||||
for (Map.Entry<String, RootCommand> entry : command.registeredCommands.entrySet()) {
|
||||
String commandName = entry.getKey().toLowerCase();
|
||||
BungeeRootCommand bungeeCommand = (BungeeRootCommand) entry.getValue();
|
||||
if (bungeeCommand.isRegistered) {
|
||||
bungeeCommand.getSubCommands().values().removeAll(command.subCommands.values());
|
||||
if (bungeeCommand.getSubCommands().isEmpty() && bungeeCommand.isRegistered) {
|
||||
unregisterCommand(bungeeCommand);
|
||||
bungeeCommand.isRegistered = false;
|
||||
registeredCommands.remove(commandName);
|
||||
}
|
||||
bungeeCommand.isRegistered = false;
|
||||
registeredCommands.remove(commandName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user