Skip to content

Commit

Permalink
SubCommandHandler: Fix tab complete handling
Browse files Browse the repository at this point in the history
  • Loading branch information
xDec0de committed Nov 2, 2024
1 parent b7de8e3 commit 3cd85bb
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,7 +39,18 @@ public boolean onCommand(@NotNull MCCommand<P, S> mainCmd, @NotNull S sender, @N
}

public List<String> onTab(@NotNull MCCommand<P, S> 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<String> cmdTabs = cmd.onTab(sender, newArgs);
final List<String> tabs = new ArrayList<>(subCommands.size() + cmdTabs.size());
tabs.addAll(cmdTabs);
for (MCCommand<P, S> subCmd : subCommands) {
tabs.add(subCmd.getName());
tabs.addAll(subCmd.getAliases());
}
return tabs;
}, List.of(), false);
}

@SafeVarargs
Expand Down

0 comments on commit 3cd85bb

Please sign in to comment.