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

@@ -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);
}
}