8000 Update CommandAPIBukkit#registerCommandNode() · CommandAPI/CommandAPI@1ae6fc1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ae6fc1

Browse files
Update CommandAPIBukkit#registerCommandNode()
Co-authored-by: willkroboth <46540330+willkroboth@users.noreply.github.com>
1 parent 044a2d7 commit 1ae6fc1

File tree

1 file changed

+9
-13
lines changed
  • commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi

1 file changed

+9
-13
lines changed

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -566,31 +566,27 @@ private void registerCommand(RootCommandNode<Source> root, String name, String p
566566

567567
@Override
568568
public LiteralCommandNode<Source> registerCommandNode(LiteralArgumentBuilder<Source> node, String namespace) {
569+
RootCommandNode<Source> rootNode = getBrigadierDispatcher().getRoot();
569570
LiteralCommandNode<Source> builtNode = node.build();
570-
LiteralCommandNode<Source> customNamespaceNode = null;
571-
572571
String name = node.getLiteral();
573-
boolean namespaceEqualsMinecraft = namespace.equals("minecraft");
574-
if (namespaceEqualsMinecraft && namespacesToFix.contains("minecraft:" + name)) {
572+
if (namespace.equals("minecraft") && namespacesToFix.contains("minecraft:" + name)) {
575573
// This command wants to exist as `minecraft:name`
576574
// However, another command has requested that `minecraft:name` be removed
577575
// We'll keep track of everything that should be `minecraft:name` in
578576
// `minecraftCommandNamespaces` and fix this later in `#fixNamespaces`
579577
minecraftCommandNamespaces.addChild(CommandAPIHandler.getInstance().namespaceNode(builtNode, "minecraft"));
580-
} else if (!namespaceEqualsMinecraft) {
581-
// We should set up a custom namespace
582-
customNamespaceNode = CommandAPIHandler.getInstance().namespaceNode(builtNode, namespace);
578+
} else {
583579
// Make sure to remove the `minecraft:name` and
584580
// `minecraft:namespace:name` commands Bukkit will create
585581
fillNamespacesToFix(name, namespace + ":" + name);
582+
// Create the namespaced node
583+
rootNode.addChild(CommandAPIHandler.getInstance().namespaceNode(builtNode, namespace));
586584
}
587-
588-
// Add the nodes to the main dispatcher
589-
RootCommandNode<Source> rootNode = getBrigadierDispatcher().getRoot();
585+
// Add the main node to dispatcher
586+
// We needed to wait until after `fillNamespacesToFix` was called to do this, in case a previous
587+
// `minecraft:name` version of the command needed to be saved separately before this node was added
590588
rootNode.addChild(builtNode);
591-
if (customNamespaceNode != null) {
592-
rootNode.addChild(customNamespaceNode);
593-
}
589+
594590
return builtNode;
595591
}
596592

0 commit comments

Comments
 (0)
0