diff --git a/src/main/java/com/marcusslover/plus/lib/command/CommandManager.java b/src/main/java/com/marcusslover/plus/lib/command/CommandManager.java index f59723f..6a84bf6 100644 --- a/src/main/java/com/marcusslover/plus/lib/command/CommandManager.java +++ b/src/main/java/com/marcusslover/plus/lib/command/CommandManager.java @@ -77,6 +77,28 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab return this; } + /** + * Unregister a command. + * @param command the command + */ + public void unregister(@NotNull ICommand command) { + Command commandAnnotation = this.getCommandAnnotation(command); + if (commandAnnotation == null) { + return; + } + String name = commandAnnotation.name(); + CommandMap commandMap = Bukkit.getCommandMap(); + List keys = new ArrayList<>(); + commandMap.getKnownCommands().forEach((key, value) -> { + if (value.getName().equals(name)) { + keys.add(key); + } + }); + for (String key : keys) { + commandMap.getKnownCommands().remove(key); + } + } + @NotNull public Set getCommands() { return this.commandSet;