From ca906236b937c8dbed891a8501805e29a57b98fe Mon Sep 17 00:00:00 2001 From: NgLoader Date: Fri, 15 Jul 2022 23:49:32 +0200 Subject: [PATCH] feat: added unregister by node name --- .../com/mojang/brigadier/CommandDispatcher.java | 15 ++++++++++++--- .../com/mojang/brigadier/tree/CommandNode.java | 4 +--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/mojang/brigadier/CommandDispatcher.java b/src/main/java/com/mojang/brigadier/CommandDispatcher.java index 1d1484d..586c80b 100644 --- a/src/main/java/com/mojang/brigadier/CommandDispatcher.java +++ b/src/main/java/com/mojang/brigadier/CommandDispatcher.java @@ -100,12 +100,21 @@ public class CommandDispatcher { } /** - * Utility method from unregister a command + * This method unregisteres a previously declared command * - * @param command node from register function + * @param The name of the command to remove + */ + public void unregister(final String name) { + this.root.removeChild(name); + } + + /** + * This method unregisteres a previously declared command + * + * @param An previously added node */ public void unregister(final LiteralCommandNode node) { - this.root.removeChild(node); + this.unregister(node.getName()); } /** diff --git a/src/main/java/com/mojang/brigadier/tree/CommandNode.java b/src/main/java/com/mojang/brigadier/tree/CommandNode.java index 0ac365c..ec232ba 100644 --- a/src/main/java/com/mojang/brigadier/tree/CommandNode.java +++ b/src/main/java/com/mojang/brigadier/tree/CommandNode.java @@ -89,9 +89,7 @@ public abstract class CommandNode implements Comparable> { } } - public void removeChild(final CommandNode node) { - String name = node.getName(); - + public void removeChild(String name) { this.children.remove(name); this.literals.remove(name); this.arguments.remove(name);