Skip to content

Commit

Permalink
Changed tab complete behavior: Only commands that the player has acce…
Browse files Browse the repository at this point in the history
…ss to are shown
  • Loading branch information
aleksilassila committed Oct 21, 2020
1 parent 41c146a commit 2b285dd
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,22 @@ public List<String> onTabComplete(CommandSender sender, Command command, String

Player player = (Player) sender;

List<String> avalableArgs = new ArrayList<>();
List<String> availableArgs = new ArrayList<>();

if (args.length == 1) {
for (Subcommand subcommand : subcommands) {
avalableArgs.add(subcommand.getName());
if (subcommand.getPermission() == null || player.hasPermission(subcommand.getPermission()))
availableArgs.add(subcommand.getName());
}
} else if (args.length > 1) {
Subcommand currentSubcommand = getSubcommand(args[0]);
if (currentSubcommand == null) return null;

avalableArgs = currentSubcommand.onTabComplete(player, Arrays.copyOfRange(args, 1, args.length));
if (currentSubcommand.getPermission() == null || player.hasPermission(currentSubcommand.getPermission()))
availableArgs = currentSubcommand.onTabComplete(player, Arrays.copyOfRange(args, 1, args.length));
}

return avalableArgs;
return availableArgs;
}

public static class Utils {
Expand Down

0 comments on commit 2b285dd

Please sign in to comment.