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

This commit corrects tab-completion logic to consider non-player command
senders.

By: Phillip Schichtel <quick_wango@code-infection.de>
This commit is contained in:
Bukkit/Spigot
2013-08-17 18:51:10 -06:00
parent 5462a33b20
commit f60d6710d5
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);
}
}