diff options
author | Wesley Wolfe <weswolf@aol.com> | 2012-10-17 04:31:36 -0500 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2012-10-17 04:31:36 -0500 |
commit | 4166af1d3aec67c88e34dd442d38f8208e099c52 (patch) | |
tree | c4a47a3cd156555c7d9bb9eb646d1771ceec74ef /src/main/java/org | |
parent | 3ce954bb8604c2bbef786b897c93db245dd67424 (diff) | |
download | craftbukkit-4166af1d3aec67c88e34dd442d38f8208e099c52.tar craftbukkit-4166af1d3aec67c88e34dd442d38f8208e099c52.tar.gz craftbukkit-4166af1d3aec67c88e34dd442d38f8208e099c52.tar.lz craftbukkit-4166af1d3aec67c88e34dd442d38f8208e099c52.tar.xz craftbukkit-4166af1d3aec67c88e34dd442d38f8208e099c52.zip |
Implement chat tab completion API. Fixes BUKKIT-2608. Adds BUKKIT-2607.
The chat tab completion implementation also includes a sanity check to
assure type-safety in the list.
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftServer.java | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 56ae1420..853c240b 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -6,6 +6,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; @@ -86,6 +87,7 @@ import org.bukkit.craftbukkit.util.DatFileFilter; import org.bukkit.craftbukkit.util.Versioning; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.player.PlayerChatTabCompleteEvent; import org.bukkit.event.world.WorldInitEvent; import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldSaveEvent; @@ -113,6 +115,7 @@ import org.bukkit.potion.Potion; import org.bukkit.potion.PotionEffectType; import org.bukkit.plugin.messaging.StandardMessenger; import org.bukkit.scheduler.BukkitWorker; +import org.bukkit.util.StringUtil; import org.bukkit.util.permissions.DefaultPermissions; import org.yaml.snakeyaml.Yaml; @@ -1257,19 +1260,31 @@ public final class CraftServer implements Server { 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); + List<String> completions = new ArrayList<String>(); + PlayerChatTabCompleteEvent event = new PlayerChatTabCompleteEvent(player, message, completions); + String token = event.getLastToken(); for (Player p : players) { - if (player.canSee(p)) { + if (player.canSee(p) && StringUtil.startsWithIgnoreCase(p.getName(), token)) { completions.add(p.getName()); } } - + pluginManager.callEvent(event); + + Iterator<?> it = completions.iterator(); + while (it.hasNext()) { + Object current = it.next(); + if (!(current instanceof String)) { + // Sanity + it.remove(); + } + } + Collections.sort(completions, String.CASE_INSENSITIVE_ORDER); return completions; } } |