summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnimosity <nullcline@gmail.com>2011-01-06 13:10:28 +0800
committerDinner Bone <dinnerbone@dinnerbone.com>2011-01-07 17:53:18 +0800
commit1e3c5a393b9ab7b527e1553540c9388ce7c31399 (patch)
tree352b079681b70c0818f287672cffb0951ca98cc9
parent6a786c1c21308805294040083a0ccf04bf9ebcf9 (diff)
downloadcraftbukkit-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.java24
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;