mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 15:00:13 +01:00
Added CraftServer.matchPlayer(String) - partial-name matching
By: Animosity <nullcline@gmail.com>
This commit is contained in:
parent
87ab5dc0f8
commit
99fcba15f0
1 changed files with 24 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue