From ed4cb11b87f6a95c760eacc530bb0997a8595fce Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 30 Dec 2016 22:44:30 +0100 Subject: [PATCH] Added temporary fix for TBMCPlugins/ButtonChat#56 --- src/main/java/buttondevteam/lib/TBMCPlayer.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/buttondevteam/lib/TBMCPlayer.java b/src/main/java/buttondevteam/lib/TBMCPlayer.java index 3008e94..da1e582 100644 --- a/src/main/java/buttondevteam/lib/TBMCPlayer.java +++ b/src/main/java/buttondevteam/lib/TBMCPlayer.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.Map.Entry; import java.util.Optional; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -30,7 +31,7 @@ import com.palmergames.bukkit.towny.object.TownyUniverse; public class TBMCPlayer implements AutoCloseable { private static final String TBMC_PLAYERS_DIR = "TBMC/players"; - private HashMap data = new HashMap<>(); + private ConcurrentHashMap data = new ConcurrentHashMap<>(); /** *

@@ -254,6 +255,8 @@ public class TBMCPlayer implements AutoCloseable { return uuid; } + private ConcurrentHashMap, TBMCPlayer> playermap = new ConcurrentHashMap<>(); // TODO + /** * Gets the TBMCPlayer object as a specific plugin player, keeping it's data * * @@ -262,12 +265,16 @@ public class TBMCPlayer implements AutoCloseable { * @param cl * The TBMCPlayer subclass */ + @SuppressWarnings("unchecked") public T asPluginPlayer(Class cl) { T obj = null; + if (playermap.containsKey(cl)) + return (T) playermap.get(cl); try { obj = cl.newInstance(); ((TBMCPlayer) obj).uuid = uuid; - ((TBMCPlayer) obj).data.putAll(data); + // ((TBMCPlayer) obj).data.putAll(data); + playermap.put(cl, obj); } catch (Exception e) { e.printStackTrace(); }