Example #1
0
  /**
   * Get a player's data file
   *
   * @param playerName
   * @return
   */
  public PlayerEntry getPlayerEntry(String playerName) {
    PlayerEntry data = players.get(playerName.toLowerCase());

    if (data == null) {
      data = new PlayerEntry();
      data.setName(playerName);
      players.put(playerName.toLowerCase(), data);
    }

    return data;
  }
  /**
   * Get a player's data file, will look up by UUID first, then name.
   *
   * @param player
   * @return
   */
  public PlayerEntry getPlayerEntry(Player player) {
    // look for player in memory
    String playerName = player.getName();
    PlayerEntry data = players.get(playerName.toLowerCase());

    // otherwise look in database
    if (data == null) {
      UUID uuid = player.getUniqueId();

      data = plugin.getStorageManager().extractPlayer(uuid);
      if (data == null) {
        data = plugin.getStorageManager().extractPlayer(player.getName());
      } else if (!playerName.equalsIgnoreCase(data.getName())) {
        plugin.getStorageManager().migrate(data.getName(), playerName);
        data.setName(playerName);
      }
      if (data == null) {
        data = plugin.getStorageManager().createPlayer(playerName, uuid);
      }
      players.put(playerName.toLowerCase(), data);
    }

    return data;
  }