From 24d778e69d6933311738c80be0323657728dda09 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 29 Oct 2016 19:05:50 +0200 Subject: [PATCH] Added UUID overload for getPlayer --- .../java/buttondevteam/lib/TBMCPlayer.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/java/buttondevteam/lib/TBMCPlayer.java b/src/main/java/buttondevteam/lib/TBMCPlayer.java index 6b52160..94ee5be 100644 --- a/src/main/java/buttondevteam/lib/TBMCPlayer.java +++ b/src/main/java/buttondevteam/lib/TBMCPlayer.java @@ -24,7 +24,7 @@ import com.palmergames.bukkit.towny.object.TownyUniverse; * @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 HashMap data = new HashMap<>(); @@ -127,8 +127,8 @@ public class TBMCPlayer implements AutoCloseable { //TODO: Load player data in C private static HashMap 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 - * try-with-resources may be the easiest way to achieve this. Example: + * 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 try-with-resources may be the easiest way to achieve this. Example: * *
 	 * {@code
@@ -174,6 +174,29 @@ public class TBMCPlayer implements AutoCloseable { //TODO: Load player data in C
 			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:
+	 * 
+	 * 
+	 * {@code
+	 * try(TBMCPlayer player = getPlayer(p))
+	 * {
+	 * 	...
+	 * }
+	 * 
+ * + * @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 */