Merge pull request #76 from PikachuEXE/refactor/player-finder-find-exact-match-first

* Return a player with exact name match first when trying to partial match
This commit is contained in:
FlyingPikachu 2015-04-10 17:23:47 -04:00
commit 0ebc32f40a

View File

@ -9,8 +9,18 @@ import java.util.UUID;
public class PlayerFinder {
/**
*
* @param queryString String that contains part of player name
* @return if there is a player with exact name (case insensitive), return it
* else if there is a player with name which contains part of queryString, return it
* else {@code null}
*/
public static Player findOnlinePlayerByPartialCaseInsensitiveNameMatch(String queryString) {
Player target_online_player = null;
Player target_online_player = findOnlinePlayerByExactCaseInsensitiveNameMatch(queryString);
if (target_online_player != null) {
return target_online_player;
}
for (Player online_player : Bukkit.getOnlinePlayers()) {
if (online_player.getName().toLowerCase().contains(queryString.toLowerCase())) {