|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: derklaro < [email protected]> |
| 3 | +Date: Wed, 24 Aug 2022 10:14:50 +0200 |
| 4 | +Subject: [PATCH] fix root command unregister |
| 5 | + |
| 6 | +Unregistering a root command which has an argument with the same name |
| 7 | +as another root command causes the other root command to be |
| 8 | +unregistered as well. Instead of checking if the command tree contains |
| 9 | +a root command with the same name as the child node, we now just pass |
| 10 | +in a boolean which indicates if a command is a root command or a child |
| 11 | +node of a root command. |
| 12 | + |
| 13 | +diff --git a/cloud-core/src/main/java/cloud/commandframework/CommandManager.java b/cloud-core/src/main/java/cloud/commandframework/CommandManager.java |
| 14 | +index 96ca0acad15b9044d6677bc33eb23c4cfa72d789..b5be42364ae050e5adab58f5a8a70dffc960f1ec 100644 |
| 15 | +--- a/cloud-core/src/main/java/cloud/commandframework/CommandManager.java |
| 16 | ++++ b/cloud-core/src/main/java/cloud/commandframework/CommandManager.java |
| 17 | +@@ -545,7 +545,7 @@ public abstract class CommandManager<C> { |
| 18 | + this.commandRegistrationHandler.unregisterRootCommand((StaticArgument<?>) node.getValue()); |
| 19 | + |
| 20 | + // We then delete it from the tree. |
| 21 | +- this.commandTree.deleteRecursively(node); |
| 22 | ++ this.commandTree.deleteRecursively(node, true); // cloudnet |
| 23 | + |
| 24 | + // And lastly we re-build the entire tree. |
| 25 | + this.commandTree.verifyAndRegister(); |
| 26 | +diff --git a/cloud-core/src/main/java/cloud/commandframework/CommandTree.java b/cloud-core/src/main/java/cloud/commandframework/CommandTree.java |
| 27 | +index dcc6a990a12b2bec74c70696e906a419855cc422..de9fa8684d18242c1548e88514dc44e516827581 100644 |
| 28 | +--- a/cloud-core/src/main/java/cloud/commandframework/CommandTree.java |
| 29 | ++++ b/cloud-core/src/main/java/cloud/commandframework/CommandTree.java |
| 30 | +@@ -996,17 +996,17 @@ public final class CommandTree<C> { |
| 31 | + return null; |
| 32 | + } |
| 33 | + |
| 34 | +- void deleteRecursively(final @NonNull Node<@Nullable CommandArgument<C, ?>> node) { |
| 35 | ++ void deleteRecursively(final @NonNull Node<@Nullable CommandArgument<C, ?>> node, final boolean root) { // cloudnet |
| 36 | + for (final Node<@Nullable CommandArgument<C, ?>> child : new ArrayList<>(node.children)) { |
| 37 | +- this.deleteRecursively(child); |
| 38 | ++ this.deleteRecursively(child, false); // cloudnet |
| 39 | + } |
| 40 | + |
| 41 | + // We need to remove it from the tree. |
| 42 | +- this.removeNode(node); |
| 43 | ++ this.removeNode(node, root); // cloudnet |
| 44 | + } |
| 45 | + |
| 46 | +- private boolean removeNode(final @NonNull Node<@Nullable CommandArgument<C, ?>> node) { |
| 47 | +- if (this.getRootNodes().contains(node)) { |
| 48 | ++ private boolean removeNode(final @NonNull Node<@Nullable CommandArgument<C, ?>> node, final boolean root) { // cloudnet |
| 49 | ++ if (root) { // cloudnet |
| 50 | + this.internalTree.removeChild(node); |
| 51 | + } else { |
| 52 | + return node.getParent().removeChild(node); |
0 commit comments