From 3cd85bbe70062148b2614a163f948793922fb7c8 Mon Sep 17 00:00:00 2001 From: xDec0de_ Date: Sat, 2 Nov 2024 08:08:23 +0100 Subject: [PATCH] SubCommandHandler: Fix tab complete handling --- .../codersky/mcutils/cmd/SubCommandHandler.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/shared/src/main/java/net/codersky/mcutils/cmd/SubCommandHandler.java b/shared/src/main/java/net/codersky/mcutils/cmd/SubCommandHandler.java index 612ceee..343d0cc 100644 --- a/shared/src/main/java/net/codersky/mcutils/cmd/SubCommandHandler.java +++ b/shared/src/main/java/net/codersky/mcutils/cmd/SubCommandHandler.java @@ -2,6 +2,7 @@ import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -38,7 +39,18 @@ public boolean onCommand(@NotNull MCCommand mainCmd, @NotNull S sender, @N } public List onTab(@NotNull MCCommand mainCommand, @NotNull S sender, @NotNull String[] args) { - return onUsedCommand(mainCommand, sender, args, (cmd, newArgs) -> cmd.onTab(sender, newArgs), List.of(), false); + return onUsedCommand(mainCommand, sender, args, (cmd, newArgs) -> { + if (subCommands.isEmpty() || args.length > 1) + return cmd.onTab(sender, newArgs); + final List cmdTabs = cmd.onTab(sender, newArgs); + final List tabs = new ArrayList<>(subCommands.size() + cmdTabs.size()); + tabs.addAll(cmdTabs); + for (MCCommand subCmd : subCommands) { + tabs.add(subCmd.getName()); + tabs.addAll(subCmd.getAliases()); + } + return tabs; + }, List.of(), false); } @SafeVarargs