From 4f1b5fed0001c123d2277ce0bff6f795b59c6030 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Thu, 11 Jan 2024 19:45:38 -0700 Subject: [PATCH] Use BrigadierUtil --- .../NeoForgeCommandRegistrationHandler.java | 39 +------------------ 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/src/main/java/cloud/commandframework/neoforge/NeoForgeCommandRegistrationHandler.java b/src/main/java/cloud/commandframework/neoforge/NeoForgeCommandRegistrationHandler.java index 70141d15..6d0ca096 100644 --- a/src/main/java/cloud/commandframework/neoforge/NeoForgeCommandRegistrationHandler.java +++ b/src/main/java/cloud/commandframework/neoforge/NeoForgeCommandRegistrationHandler.java @@ -28,9 +28,7 @@ import cloud.commandframework.brigadier.CloudBrigadierCommand; import cloud.commandframework.internal.CommandRegistrationHandler; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.tree.CommandNode; -import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.RootCommandNode; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -47,6 +45,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.NonNull; +import static cloud.commandframework.brigadier.util.BrigadierUtil.buildRedirect; + /** * A registration handler for NeoForge. * @@ -86,41 +86,6 @@ protected final void registerCommand(final Command command, final CommandDisp } } - /** - * Returns a literal node that redirects its execution to - * the given destination node. - * - *

This method is taken from MIT licensed code in the Velocity project, see - * - * Velocity's BrigadierUtils class

- * - * @param alias the command alias - * @param destination the destination node - * @param brig sender type - * @return the built node - */ - private static LiteralCommandNode buildRedirect( - final @NonNull String alias, - final @NonNull CommandNode destination - ) { - // Redirects only work for nodes with children, but break the top argument-less command. - // Manually adding the root command after setting the redirect doesn't fix it. - // (See https://github.com/Mojang/brigadier/issues/46) Manually clone the node instead. - final LiteralArgumentBuilder builder = LiteralArgumentBuilder - .literal(alias) - .requires(destination.getRequirement()) - .forward( - destination.getRedirect(), - destination.getRedirectModifier(), - destination.isFork() - ) - .executes(destination.getCommand()); - for (final CommandNode child : destination.getChildren()) { - builder.then(child); - } - return builder.build(); - } - static class Client extends NeoForgeCommandRegistrationHandler { private final Set> registeredCommands = ConcurrentHashMap.newKeySet();