From 99fcba15f0d267d2634c42392cdea737f8f0a9b4 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Thu, 6 Jan 2011 13:10:28 +0800 Subject: [PATCH] Added CraftServer.matchPlayer(String) - partial-name matching By: Animosity --- .../org/bukkit/craftbukkit/CraftServer.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 11884e7140..129749091a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/paper-server/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;