public Player getPlayerExact(String name) { String lname = name.toLowerCase(); for (Player player : getPlayers()) { if (ChatColor.stripColor(player.getName()).equalsIgnoreCase(lname)) { return player; } } return null; }
public Player getPlayer(String name) { Player[] players = getPlayers(); Player found = null; String lowerName = name.toLowerCase(); int delta = Integer.MAX_VALUE; for (Player player : players) { if (ChatColor.stripColor(player.getName()).toLowerCase().startsWith(lowerName)) { int curDelta = player.getName().length() - lowerName.length(); if (curDelta < delta) { found = player; delta = curDelta; } if (curDelta == 0) { break; } } } return found; }
public List<Player> matchPlayer(String partialName) { List<Player> matchedPlayers = new ArrayList<Player>(); for (Player iterPlayer : this.getPlayers()) { String iterPlayerName = ChatColor.stripColor(iterPlayer.getName()); if (partialName.equalsIgnoreCase(iterPlayerName)) { // Exact match matchedPlayers.clear(); matchedPlayers.add(iterPlayer); break; } if (iterPlayerName.toLowerCase().indexOf(partialName.toLowerCase()) != -1) { // Partial match matchedPlayers.add(iterPlayer); } } return matchedPlayers; }