Permalink
Browse files

Add unregister method for JDA (#174)

This PR is to allow users to unregister commands from the `JDACommandManager`

Currently slightly flawed, needs research. When re-registering it spits out a load of messages like so:
```
SEVERE: [ACF] ACF Error: settings registered subcommand boss role for root command settings - but it is already defined in settings
Sep 20, 2018 3:58:31 AM com.algorithmjunkie.freelance.gachapon.acf.JDACommandManager log
SEVERE: [ACF] 2 subcommands of the same prefix may not be spread over 2 different classes. Ignoring this.
```

Not sure if this is just for me, or if it's for all.
  • Loading branch information...
simpleauthority authored and aikar committed Oct 23, 2018
1 parent 01d1496 commit aa6fa281cc6252ca4791e0ec63e13ab129854316
Showing with 12 additions and 0 deletions.
  1. +12 −0 jda/src/main/java/co/aikar/commands/JDACommandManager.java
@@ -161,6 +161,18 @@ public void registerCommand(BaseCommand command) {
}
}
public void unregisterCommand(BaseCommand command) {
for (Map.Entry<String, RootCommand> entry : command.registeredCommands.entrySet()) {
String jdaCommandName = entry.getKey().toLowerCase();
JDARootCommand jdaCommand = (JDARootCommand) entry.getValue();
jdaCommand.getSubCommands().values().removeAll(command.subCommands.values());
if (jdaCommand.isRegistered && jdaCommand.getSubCommands().isEmpty()) {
jdaCommand.isRegistered = false;
commands.remove(jdaCommandName);
}
}
}
@Override
public boolean hasRegisteredCommands() {
return !this.commands.isEmpty();

0 comments on commit aa6fa28

Please sign in to comment.