From bbdacf8e03413b065cdbfa8e15e81545a5509f13 Mon Sep 17 00:00:00 2001 From: Zrips Date: Fri, 16 Jul 2021 17:58:40 +0300 Subject: [PATCH] PLayer data load needs to be in sync... --- src/main/java/com/gamingmesh/jobs/Jobs.java | 63 +++++++++---------- .../com/gamingmesh/jobs/PlayerManager.java | 4 +- .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 1 - 3 files changed, 31 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 562aa695..de39827f 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -114,6 +114,7 @@ import net.Zrips.CMILib.ActionBar.CMIActionBar; import net.Zrips.CMILib.Colors.CMIChatColor; import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.Items.CMIMaterial; +import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.RawMessages.RawMessage; import net.Zrips.CMILib.Version.Version; @@ -543,43 +544,35 @@ public final class Jobs extends JavaPlugin { private void startup() { reload(true); - CompletableFuture pd = loadAllPlayersData(); - - // attempt to add all online players to cache - pd.thenAccept(e -> getServer().getOnlinePlayers().forEach(getPlayerManager()::playerJoin)); + // This goes in sync to avoid issues while loading data + loadAllPlayersData(); + for (Player online : Bukkit.getServer().getOnlinePlayers()) + getPlayerManager().playerJoin(online); } - public static CompletableFuture loadAllPlayersData() { - return CompletableFuture.supplyAsync(() -> { - long time = System.currentTimeMillis(); - // Cloning to avoid issues - Map temp = new HashMap<>(getPlayerManager().getPlayersInfoUUIDMap()); - Map> playersJobs = dao.getAllJobs(); - Map playersPoints = dao.getAllPoints(); - Map> playersLogs = dao.getAllLogs(); - Map playersArchives = dao.getAllArchivedJobs(); - Map playersLimits = dao.loadPlayerLimits(); - - for (Iterator it = temp.values().iterator(); it.hasNext();) { - PlayerInfo one = it.next(); - int id = one.getID(); - JobsPlayer jPlayer = getPlayerManager().getJobsPlayerOffline( - one, - playersJobs.get(id), - playersPoints.get(id), - playersLogs.get(id), - playersArchives.get(id), - playersLimits.get(id)); - if (jPlayer != null) - getPlayerManager().addPlayerToCache(jPlayer); - } - - return time; - }).thenAccept(t -> { - if (!getPlayerManager().getPlayersCache().isEmpty()) - consoleMsg("&e[Jobs] Preloaded " + getPlayerManager().getPlayersCache().size() + " players data in " + - ((int) (((System.currentTimeMillis() - t) / 1000d) * 100) / 100D)); - }); + public static void loadAllPlayersData() { + long time = System.currentTimeMillis(); + HashMap temp = new HashMap<>(getPlayerManager().getPlayersInfoUUIDMap()); + Map> playersJobs = dao.getAllJobs(); + Map playersPoints = dao.getAllPoints(); + Map> playersLogs = dao.getAllLogs(); + Map playersArchives = dao.getAllArchivedJobs(); + Map playersLimits = dao.loadPlayerLimits(); + for (Iterator it = temp.values().iterator(); it.hasNext();) { + PlayerInfo one = it.next(); + int id = one.getID(); + JobsPlayer jPlayer = getPlayerManager().getJobsPlayerOffline( + one, + playersJobs.get(id), + playersPoints.get(id), + playersLogs.get(id), + playersArchives.get(id), + playersLimits.get(id)); + if (jPlayer != null) + getPlayerManager().addPlayerToCache(jPlayer); + } + if (!getPlayerManager().getPlayersCache().isEmpty()) + consoleMsg("&e[Jobs] Preloaded " + getPlayerManager().getPlayersCache().size() + " players data in " + ((int) ((System.currentTimeMillis() - time) / 1000.0D * 100.0D) / 100.0D)); } public static void convertDatabase() { diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index a5a8d8a6..f36765c4 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -63,6 +63,7 @@ import com.gamingmesh.jobs.stuff.Util; import net.Zrips.CMILib.ActionBar.CMIActionBar; import net.Zrips.CMILib.Items.CMIItemStack; +import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.NBT.CMINBT; import net.Zrips.CMILib.Version.Version; @@ -130,8 +131,9 @@ public class PlayerManager { playersCache.put(jName, jPlayer); - if (jPlayer.getUniqueId() != null) + if (jPlayer.getUniqueId() != null) { playersUUIDCache.put(jPlayer.getUniqueId(), jPlayer); + } } public void addPlayer(JobsPlayer jPlayer) { diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 33b778dc..9066fbeb 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -1779,7 +1779,6 @@ public abstract class JobsDAO { res.getInt(UserTableFields.donequests.getCollumn()), res.getString(UserTableFields.quests.getCollumn()))); } catch (IllegalArgumentException e) { - uuids.add(uuid); } }