diff --git a/velocity/src/main/java/revxrsal/commands/velocity/hooks/VelocityCommandHooks.java b/velocity/src/main/java/revxrsal/commands/velocity/hooks/VelocityCommandHooks.java index d82099c0..2a976331 100644 --- a/velocity/src/main/java/revxrsal/commands/velocity/hooks/VelocityCommandHooks.java +++ b/velocity/src/main/java/revxrsal/commands/velocity/hooks/VelocityCommandHooks.java @@ -24,9 +24,13 @@ package revxrsal.commands.velocity.hooks; import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.LiteralCommandNode; +import com.mojang.brigadier.tree.RootCommandNode; import com.velocitypowered.api.command.BrigadierCommand; import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import org.jetbrains.annotations.NotNull; import revxrsal.commands.Lamp; import revxrsal.commands.brigadier.BrigadierConverter; @@ -38,9 +42,6 @@ import revxrsal.commands.velocity.VelocityLampConfig; import revxrsal.commands.velocity.actor.VelocityCommandActor; -import java.util.HashSet; -import java.util.Set; - /** * A hook that registers Lamp commands into Velocity * @@ -51,22 +52,26 @@ public final class VelocityCommandHooks implemen /** * Tracks the commands we registered */ - private final Set registeredRootNames = new HashSet<>(); + private final RootCommandNode root = new RootCommandNode<>(); private final VelocityLampConfig config; private final BrigadierParser parser = new BrigadierParser<>(this); public VelocityCommandHooks(VelocityLampConfig config) { this.config = config; + config.server().getEventManager().register(config.plugin(), this); } @Override public void onRegistered(@NotNull ExecutableCommand command, @NotNull CancelHandle cancelHandle) { - String name = command.firstNode().name(); - if (registeredRootNames.add(name)) { - // command wasn't registered before. register it. - LiteralCommandNode node = parser.createNode(command); - BrigadierCommand brigadierCommand = new BrigadierCommand(node); + LiteralCommandNode node = parser.createNode(command); + root.addChild(node); + } + + @Subscribe + public void onProxyInitialize(ProxyInitializeEvent event) { + for (CommandNode node : root.getChildren()) { + BrigadierCommand brigadierCommand = new BrigadierCommand((LiteralCommandNode) node); config.server().getCommandManager().register(brigadierCommand); } }