Fix command unregistering
This commit is contained in:
parent
1e4088991f
commit
709202574a
2 changed files with 14 additions and 3 deletions
|
|
@ -2,6 +2,7 @@ package org.zhdev.varioutil;
|
|||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.Listener;
|
||||
|
|
@ -171,6 +172,8 @@ public abstract class BukkitPreparedPlugin extends BukkitPlugin implements Liste
|
|||
if (singleThreadExecutor != null) {
|
||||
singleThreadExecutor.shutdownNow();
|
||||
}
|
||||
|
||||
BukkitUtils.unregisterCommandIf(command -> command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) command).getPlugin() == this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -36,12 +36,20 @@ public class BukkitUtils {
|
|||
COMMAND_MAP.register(label, fallbackPrefix, command);
|
||||
}
|
||||
|
||||
public static void unregisterCommand(String label) {
|
||||
KNOWN_COMMANDS.remove(label);
|
||||
public static Command unregisterCommand(String label) {
|
||||
Command command = KNOWN_COMMANDS.remove(label);
|
||||
if (command != null) command.unregister(COMMAND_MAP);
|
||||
return command;
|
||||
}
|
||||
|
||||
public static void unregisterCommandIf(Predicate<Command> predicate) {
|
||||
KNOWN_COMMANDS.values().removeIf(predicate);
|
||||
KNOWN_COMMANDS.values().removeIf(command -> {
|
||||
if (predicate.test(command)) {
|
||||
command.unregister(COMMAND_MAP);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
public static void setSkullTexture(SkullMeta meta, String base64) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue