Added UUID overload for getPlayer

This commit is contained in:
Norbi Peti 2016-10-29 19:05:50 +02:00
parent 12a42f8aba
commit 24d778e69d

View file

@ -24,7 +24,7 @@ import com.palmergames.bukkit.towny.object.TownyUniverse;
* @author Norbi * @author Norbi
* *
*/ */
public class TBMCPlayer implements AutoCloseable { //TODO: Load player data in Core public class TBMCPlayer implements AutoCloseable {
private static final String TBMC_PLAYERS_DIR = "TBMC/players"; private static final String TBMC_PLAYERS_DIR = "TBMC/players";
private HashMap<String, Object> data = new HashMap<>(); private HashMap<String, Object> data = new HashMap<>();
@ -127,8 +127,8 @@ public class TBMCPlayer implements AutoCloseable { //TODO: Load player data in C
private static HashMap<UUID, TBMCPlayer> LoadedPlayers = new HashMap<>(); private static HashMap<UUID, TBMCPlayer> LoadedPlayers = new HashMap<>();
/** /**
* This method returns a TBMC player from their name. Calling this method may return an offline player which will load it, therefore it's highly recommended to use {@link #close()} to unload the player data. Using * This method returns a TBMC player from their name. Calling this method may return an offline player which will load it, therefore it's highly recommended to use {@link #close()} to unload the
* try-with-resources may be the easiest way to achieve this. Example: * player data. Using try-with-resources may be the easiest way to achieve this. Example:
* *
* <pre> * <pre>
* {@code * {@code
@ -174,6 +174,29 @@ public class TBMCPlayer implements AutoCloseable { //TODO: Load player data in C
return TBMCPlayer.loadPlayer(p); return TBMCPlayer.loadPlayer(p);
} }
/**
* This method returns a TBMC player from a Bukkit player. Calling this method may return an offline player, therefore it's highly recommended to use {@link #close()} to unload the player data.
* Using try-with-resources may be the easiest way to achieve this. Example:
*
* <pre>
* {@code
* try(TBMCPlayer player = getPlayer(p))
* {
* ...
* }
* </pre>
*
* @param p
* The Player object
* @return The {@link TBMCPlayer} object for the player
*/
public static TBMCPlayer getPlayer(UUID uuid) {
if (TBMCPlayer.LoadedPlayers.containsKey(uuid))
return TBMCPlayer.LoadedPlayers.get(uuid);
else
return TBMCPlayer.loadPlayer(Bukkit.getOfflinePlayer(uuid));
}
/** /**
* Only intended to use from ButtonCore * Only intended to use from ButtonCore
*/ */