Ejemplo n.º 1
0
  public Player getPlayerExact(String name) {
    String lname = name.toLowerCase();

    for (Player player : getPlayers()) {
      if (ChatColor.stripColor(player.getName()).equalsIgnoreCase(lname)) {
        return player;
      }
    }
    return null;
  }
Ejemplo n.º 2
0
  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;
  }
Ejemplo n.º 3
0
  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;
  }