Skip to content

Commit

Permalink
Fix tab complete
Browse files Browse the repository at this point in the history
  • Loading branch information
lscgh committed Feb 6, 2024
1 parent e9bc566 commit d3e2574
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,19 @@ public List<String> onTabComplete(CommandSender sender, Command command, String

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

ArrayList<String> argList = new ArrayList<String>();
for(String arg: args) argList.add(arg);
argList.removeIf((arg) -> arg.isEmpty());

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

boolean playerIsCurrentlyInAGame = Game.runningGames.containsKey((Player)sender);
if(playerIsCurrentlyInAGame) {
if(args.length == CommandTicTacToe.OPPONENT_ARG_INDEX + 1) {
if(argList.size() == CommandTicTacToe.OPPONENT_ARG_INDEX + 1) {
completions.add("cancel");
}
} else {
if(args.length == CommandTicTacToe.OPPONENT_ARG_INDEX + 1) {
if(argList.size() == CommandTicTacToe.OPPONENT_ARG_INDEX + 1) {

for(Player player: this.plugin.getServer().getOnlinePlayers()) {
if(player.getName().equals(sender.getName())) continue;
Expand All @@ -163,17 +167,17 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
}

if(completions.isEmpty()) completions.add("(no available players)");
} else if(args.length == CommandTicTacToe.WIN_REQUIRED_AMOUNT_ARG_INDEX + 1) {
int integerArgs[] = CommandTicTacToe.extractIntegerArgs(args);
} else if(argList.size() == CommandTicTacToe.WIN_REQUIRED_AMOUNT_ARG_INDEX + 1) {
int integerArgs[] = CommandTicTacToe.extractIntegerArgs((String[])argList.toArray());
int maxDimension = Math.max(integerArgs[0], Math.max(integerArgs[1], integerArgs[2]));
completions.add("" + maxDimension);
} else if(args.length <= CommandTicTacToe.MAX_VALID_ARG_COUNT) {
completions.add(args.length == (CommandTicTacToe.Y_SIZE_ARG_INDEX + 1) ? "1" : "3");
} else if(argList.size() <= CommandTicTacToe.MAX_VALID_ARG_COUNT) {
completions.add(argList.size() == (CommandTicTacToe.Y_SIZE_ARG_INDEX + 1) ? "1" : "3");
}
}

ArrayList<String> filteredCompletions = new ArrayList<String>();
StringUtil.copyPartialMatches(args[args.length - 1], completions, filteredCompletions);
StringUtil.copyPartialMatches(argList.getLast(), completions, filteredCompletions);

return filteredCompletions;
}
Expand Down

0 comments on commit d3e2574

Please sign in to comment.