diff options
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/command/Command.java | 6 | ||||
-rw-r--r-- | src/main/java/org/bukkit/command/SimpleCommandMap.java | 7 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java index 5416c71d..a04c8701 100644 --- a/src/main/java/org/bukkit/command/Command.java +++ b/src/main/java/org/bukkit/command/Command.java @@ -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); } } diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java index f567dc0e..f7167824 100644 --- a/src/main/java/org/bukkit/command/SimpleCommandMap.java +++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java @@ -16,6 +16,7 @@ import java.util.regex.Pattern; import org.apache.commons.lang.Validate; import org.bukkit.Server; import org.bukkit.command.defaults.*; +import org.bukkit.entity.Player; import org.bukkit.util.StringUtil; public class SimpleCommandMap implements CommandMap { @@ -226,6 +227,8 @@ public class SimpleCommandMap implements CommandMap { ArrayList<String> completions = new ArrayList<String>(); Map<String, Command> knownCommands = this.knownCommands; + final String prefix = (sender instanceof Player ? "/" : ""); + for (VanillaCommand command : fallbackCommands) { String name = command.getName(); @@ -241,7 +244,7 @@ public class SimpleCommandMap implements CommandMap { continue; } - completions.add('/' + name); + completions.add(prefix + name); } for (Map.Entry<String, Command> commandEntry : knownCommands.entrySet()) { @@ -254,7 +257,7 @@ public class SimpleCommandMap implements CommandMap { String name = commandEntry.getKey(); // Use the alias, not command name if (StringUtil.startsWithIgnoreCase(name, cmdLine)) { - completions.add('/' + name); + completions.add(prefix + name); } } |