diff options
author | Phillip Schichtel <quick_wango@code-infection.de> | 2013-08-17 18:51:10 -0600 |
---|---|---|
committer | Nate Mortensen <nate.richard.mortensen@gmail.com> | 2013-09-10 20:58:23 -0500 |
commit | eb88c17565198a477d1a412cf64279b37ff664ab (patch) | |
tree | 8d31756b6fffbe63fa4b38202fabe0c032fe7ffd /src/main/java/org | |
parent | 3528ca5475b8ef79c830366f325d9415b234b285 (diff) | |
download | bukkit-eb88c17565198a477d1a412cf64279b37ff664ab.tar bukkit-eb88c17565198a477d1a412cf64279b37ff664ab.tar.gz bukkit-eb88c17565198a477d1a412cf64279b37ff664ab.tar.lz bukkit-eb88c17565198a477d1a412cf64279b37ff664ab.tar.xz bukkit-eb88c17565198a477d1a412cf64279b37ff664ab.zip |
Add support for command tab completion in the console. Adds BUKKIT-4168
This commit corrects tab-completion logic to consider non-player command
senders.
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); } } |