mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Better implementation of matchPlayer(String) - return List of potential matches
By: Animosity <nullcline@gmail.com>
This commit is contained in:
parent
99fcba15f0
commit
f73b61f1ce
@ -1,6 +1,7 @@
|
|||||||
package org.bukkit.craftbukkit;
|
package org.bukkit.craftbukkit;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -81,28 +82,24 @@ public final class CraftServer implements Server {
|
|||||||
return entity.a.getPlayer();
|
return entity.a.getPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player matchPlayer(String wantedPlayerName) {
|
public List<Player> matchPlayer(String partialName) {
|
||||||
Player wantedPlayer = null;
|
List<Player> matchedPlayers = new ArrayList<Player>();
|
||||||
|
|
||||||
for (Player iterPlayer : this.getOnlinePlayers()) {
|
for (Player iterPlayer : this.getOnlinePlayers()) {
|
||||||
String iterPlayerName = iterPlayer.getName();
|
String iterPlayerName = iterPlayer.getName();
|
||||||
|
|
||||||
if (wantedPlayerName.equalsIgnoreCase(iterPlayerName)) {
|
if (partialName.equalsIgnoreCase(iterPlayerName)) {
|
||||||
// Exact match
|
// Exact match
|
||||||
wantedPlayer = this.getPlayer(wantedPlayerName);
|
matchedPlayers.add(iterPlayer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (wantedPlayerName.toLowerCase().indexOf(iterPlayerName.toLowerCase()) != -1) {
|
if (iterPlayerName.toLowerCase().indexOf(partialName.toLowerCase()) != -1) {
|
||||||
// Partial match
|
// Partial match
|
||||||
if (wantedPlayer != null) {
|
matchedPlayers.add(iterPlayer);
|
||||||
// Multiple matches
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
wantedPlayer = iterPlayer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return wantedPlayer;
|
return matchedPlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginManager getPluginManager() {
|
public PluginManager getPluginManager() {
|
||||||
|
Loading…
Reference in New Issue
Block a user