diff options
author | Animosity <nullcline@gmail.com> | 2011-01-06 13:10:28 +0800 |
---|---|---|
committer | Dinner Bone <dinnerbone@dinnerbone.com> | 2011-01-07 17:53:18 +0800 |
commit | 1e3c5a393b9ab7b527e1553540c9388ce7c31399 (patch) | |
tree | 352b079681b70c0818f287672cffb0951ca98cc9 | |
parent | 6a786c1c21308805294040083a0ccf04bf9ebcf9 (diff) | |
download | craftbukkit-1e3c5a393b9ab7b527e1553540c9388ce7c31399.tar craftbukkit-1e3c5a393b9ab7b527e1553540c9388ce7c31399.tar.gz craftbukkit-1e3c5a393b9ab7b527e1553540c9388ce7c31399.tar.lz craftbukkit-1e3c5a393b9ab7b527e1553540c9388ce7c31399.tar.xz craftbukkit-1e3c5a393b9ab7b527e1553540c9388ce7c31399.zip |
Added CraftServer.matchPlayer(String) - partial-name matching
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftServer.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 11884e71..12974909 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -80,6 +80,30 @@ public final class CraftServer implements Server { public Player getPlayer(final EntityPlayerMP entity) { return entity.a.getPlayer(); } + + public Player matchPlayer(String wantedPlayerName) { + Player wantedPlayer = null; + + for (Player iterPlayer : this.getOnlinePlayers()) { + String iterPlayerName = iterPlayer.getName(); + + if (wantedPlayerName.equalsIgnoreCase(iterPlayerName)) { + // Exact match + wantedPlayer = this.getPlayer(wantedPlayerName); + break; + } + if (wantedPlayerName.toLowerCase().indexOf(iterPlayerName.toLowerCase()) != -1) { + // Partial match + if (wantedPlayer != null) { + // Multiple matches + return null; + } + wantedPlayer = iterPlayer; + } + } + + return wantedPlayer; + } public PluginManager getPluginManager() { return pluginManager; |