Added CraftServer.matchPlayer(String) - partial-name matching

This commit is contained in:
Animosity 2011-01-06 13:10:28 +08:00 committed by Dinner Bone
parent 6a786c1c21
commit 1e3c5a393b

View File

@ -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;