diff options
author | Score_Under <seejay.11@gmail.com> | 2012-10-09 19:44:04 +0100 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2012-10-15 03:18:59 -0500 |
commit | 3ce954bb8604c2bbef786b897c93db245dd67424 (patch) | |
tree | 6d0ca053c5130990bd04159768af2cb8027d25a8 /src/main/java/org/bukkit | |
parent | 05e889f3468b07b2897d64ee1df3e26e763408b1 (diff) | |
download | craftbukkit-3ce954bb8604c2bbef786b897c93db245dd67424.tar craftbukkit-3ce954bb8604c2bbef786b897c93db245dd67424.tar.gz craftbukkit-3ce954bb8604c2bbef786b897c93db245dd67424.tar.lz craftbukkit-3ce954bb8604c2bbef786b897c93db245dd67424.tar.xz craftbukkit-3ce954bb8604c2bbef786b897c93db245dd67424.zip |
Delegate tab-completion. Fixes BUKKIT-2181. Adds BUKKIT-2602
CommandMap now contains the functionality for tab completion. This
commit replaces the vanilla implementation and simply delegates it to
the Bukkit API.
Diffstat (limited to 'src/main/java/org/bukkit')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftServer.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 0c55945b..56ae1420 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -58,6 +58,7 @@ import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.WorldCreator; import org.bukkit.command.Command; +import org.bukkit.command.CommandException; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginCommand; @@ -1234,4 +1235,41 @@ public final class CraftServer implements Server { public WarningState getWarningState() { return warningState; } + + public List<String> tabComplete(net.minecraft.server.ICommandListener sender, String message) { + if (!(sender instanceof EntityPlayer)) { + return ImmutableList.of(); + } + + Player player = ((EntityPlayer) sender).getBukkitEntity(); + if (message.startsWith("/")) { + return tabCompleteCommand(player, message); + } else { + return tabCompleteChat(player, message); + } + } + + public List<String> tabCompleteCommand(Player player, String message) { + List<String> completions = null; + try { + completions = getCommandMap().tabComplete(player, message.substring(1)); + } catch (CommandException ex) { + player.sendMessage(ChatColor.RED + "An internal error occurred while attempting to tab-complete this command"); + getLogger().log(Level.SEVERE, "Exception when " + player.getName() + " attempted to tab complete " + message, ex); + } + + return completions == null ? ImmutableList.<String>of() : completions; + } + + public List<String> tabCompleteChat(Player player, String message) { + Player[] players = getOnlinePlayers(); + List<String> completions = new ArrayList<String>(players.length); + for (Player p : players) { + if (player.canSee(p)) { + completions.add(p.getName()); + } + } + + return completions; + } } |