Allow non-PluginCommand's to be unloaded
This commit is contained in:
parent
b51ff445dd
commit
b83da96cac
2 changed files with 32 additions and 8 deletions
|
|
@ -117,23 +117,37 @@ public class ServerUtils extends JavaPlugin implements CommandExecutor {
|
|||
commandManager.registerCommand(commandPlugins, true);
|
||||
}
|
||||
|
||||
getPlugin().getTaskManager().runTask(() -> BukkitPluginManager.unregisterCommands(getDisabledCommands()));
|
||||
getPlugin().getTaskManager().runTask(() -> BukkitPluginManager.unregisterExactCommands(getDisabledCommands()));
|
||||
}
|
||||
|
||||
private List<PluginCommand> getDisabledCommands() {
|
||||
List<PluginCommand> commands = new ArrayList<>();
|
||||
private List<Command> getDisabledCommands() {
|
||||
List<Command> commands = new ArrayList<>();
|
||||
for (String cmd : Config.getInstance().getConfig().getStringList("disabled-commands")) {
|
||||
String[] split = cmd.split(":");
|
||||
|
||||
PluginCommand command;
|
||||
Command command;
|
||||
if (split.length > 1) {
|
||||
command = Bukkit.getPluginCommand(StringUtils.join(":", split, 1));
|
||||
String commandString = StringUtils.join(":", split, 1);
|
||||
PluginCommand pluginCommand = Bukkit.getPluginCommand(commandString);
|
||||
|
||||
Plugin plugin = getPlugin().getPluginManager().getPlugin(split[0]);
|
||||
if (plugin == null || command == null) continue;
|
||||
if (!plugin.getName().equalsIgnoreCase(command.getPlugin().getName())) continue;
|
||||
if (plugin == null) {
|
||||
getLogger().warning("Unknown plugin '" + split[0] + "' in disabled-commands!");
|
||||
continue;
|
||||
} else if (pluginCommand == null) {
|
||||
getLogger().warning("Unknown command '" + commandString + "' in disabled-commands!");
|
||||
continue;
|
||||
} else if (!plugin.getName().equalsIgnoreCase(pluginCommand.getPlugin().getName())) {
|
||||
// No output here, plugin didn't match!
|
||||
continue;
|
||||
}
|
||||
command = pluginCommand;
|
||||
} else {
|
||||
command = Bukkit.getPluginCommand(split[0]);
|
||||
command = BukkitPluginManager.getCommand(split[0]);
|
||||
if (command == null) {
|
||||
getLogger().warning("Unknown command '" + split[0] + "' in disabled-commands!");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
commands.add(command);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -306,6 +306,16 @@ public class BukkitPluginManager extends AbstractPluginManager<Plugin> {
|
|||
RCraftServer.syncCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters all specified commands exactly.
|
||||
* @param commands The commands to unregister.
|
||||
*/
|
||||
public static void unregisterExactCommands(Collection<? extends Command> commands) {
|
||||
Map<String, Command> knownCommands = getKnownCommands();
|
||||
if (knownCommands == null) return;
|
||||
knownCommands.values().removeAll(commands);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a command from the command map.
|
||||
* @param command The command string.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue