Add support for command tab completion in the console. Adds BUKKIT-4168

This commit corrects tab-completion logic to consider non-player command
senders.
This commit is contained in:
Phillip Schichtel
2013-08-17 18:51:10 -06:00
committed by Nate Mortensen
parent eaf0265f5b
commit 6ae876a38c
2 changed files with 8 additions and 5 deletions

View File

@@ -78,18 +78,18 @@ public abstract class Command {
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (!(sender instanceof Player) || args.length == 0) {
if (args.length == 0) {
return ImmutableList.of();
}
String lastWord = args[args.length - 1];
Player senderPlayer = (Player) sender;
Player senderPlayer = sender instanceof Player ? (Player) sender : null;
ArrayList<String> matchedPlayers = new ArrayList<String>();
for (Player player : sender.getServer().getOnlinePlayers()) {
String name = player.getName();
if (senderPlayer.canSee(player) && StringUtil.startsWithIgnoreCase(name, lastWord)) {
if ((senderPlayer == null || senderPlayer.canSee(player)) && StringUtil.startsWithIgnoreCase(name, lastWord)) {
matchedPlayers.add(name);
}
}