Skip to content

Commit

Permalink
Fix a bug in CommandTicTacToeAccept::onTabComplete
Browse files Browse the repository at this point in the history
Name recommendations would disappear after the first character was
entered
  • Loading branch information
lscgh committed Feb 9, 2024
1 parent d9054d3 commit 484b927
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ public List<String> onTabComplete(CommandSender sender, Command command, String

if(!(sender instanceof Player)) return new ArrayList<String>();

ArrayList<String> argList = CommandTicTacToeAccept.removeEmptyStringsBeforeStringFromList(args);
ArrayList<String> argList = CommandTicTacToeAccept.removeMeaninglessElements(args);

if(argList.size() >= CommandTicTacToeAccept.ARG_COUNT) return new ArrayList<String>();
if(argList.size() > CommandTicTacToeAccept.ARG_COUNT) return new ArrayList<String>();

ArrayList<String> completions = new ArrayList<String>();

for(Game queuedGame: Game.getRequestsTo((Player)sender)) {
completions.add(queuedGame.config.mainPlayer.getName());
}
Expand All @@ -87,11 +88,17 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
return filteredCompletions;
}

public static ArrayList<String> removeEmptyStringsBeforeStringFromList(String[] list) {
public static ArrayList<String> removeMeaninglessElements(String[] list) {
ArrayList<String> newList = new ArrayList<String>();
for(String arg: list) newList.add(arg);

newList.removeIf((item) -> item.isEmpty() && !CommandTicTacToeAccept.listContainsNonEmptyString(newList.subList(0, Math.max(0, newList.indexOf(item) - 1))));
int i = 0;
for(String element: list) {
if(!element.isEmpty() || (i == list.length - 1)) {
newList.add(element);
}

i++;
}

return newList;
}
Expand Down

0 comments on commit 484b927

Please sign in to comment.