From ec976dfb6ce48aeedda21ba971188b8de9152064 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Sat, 15 Jun 2024 20:51:24 +0200 Subject: [PATCH] Add method to remove sub commands from command handler (#3941) --- .../viaversion/api/command/ViaVersionCommand.java | 7 +++++++ .../viaversion/viaversion/commands/ViaCommandHandler.java | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/api/src/main/java/com/viaversion/viaversion/api/command/ViaVersionCommand.java b/api/src/main/java/com/viaversion/viaversion/api/command/ViaVersionCommand.java index 361faf866..368fc8fb8 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/command/ViaVersionCommand.java +++ b/api/src/main/java/com/viaversion/viaversion/api/command/ViaVersionCommand.java @@ -34,6 +34,13 @@ public interface ViaVersionCommand { */ void registerSubCommand(ViaSubCommand command); + /** + * Removes a subcommand by name, can be used to unload default subcommands which are not supported + * on the platform. + * @param name Subcommand name + */ + void removeSubCommand(String name); + /** * Check if a subcommand is registered. * diff --git a/common/src/main/java/com/viaversion/viaversion/commands/ViaCommandHandler.java b/common/src/main/java/com/viaversion/viaversion/commands/ViaCommandHandler.java index bc7bd4ff8..0076f8e6c 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/ViaCommandHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/ViaCommandHandler.java @@ -57,6 +57,11 @@ public abstract class ViaCommandHandler implements ViaVersionCommand { commandMap.put(command.name().toLowerCase(Locale.ROOT), command); } + @Override + public void removeSubCommand(final String name) { + commandMap.remove(name.toLowerCase(Locale.ROOT)); + } + @Override public boolean hasSubCommand(String name) { return commandMap.containsKey(name.toLowerCase(Locale.ROOT));