From fe2b70bdc0529531cd6f5f8ecff9081a8e3c2460 Mon Sep 17 00:00:00 2001 From: Zrips Date: Tue, 8 Mar 2022 15:08:11 +0200 Subject: [PATCH] Explore data should no longer check by players name for performance reasons --- .../com/gamingmesh/jobs/PlayerManager.java | 22 ++++++++++++++++++- .../commands/list/resetexploreregion.java | 4 ++-- .../jobs/config/ExploreManager.java | 4 ++-- .../jobs/container/ExploreChunk.java | 4 ---- .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 4 +++- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index 2ba46908..0dcb2dcb 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -59,6 +59,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.Messages.CMIMessages; import net.Zrips.CMILib.NBT.CMINBT; import net.Zrips.CMILib.Version.Version; @@ -190,9 +191,16 @@ public class PlayerManager { return playerUUIDMap.get(jPlayer.getUniqueId()); } + JobsPlayer jPlayer = playersNameCache.get(name.toLowerCase()); + + if (jPlayer != null) { + return playerUUIDMap.get(jPlayer.getUniqueId()); + } + UUID playerUUID = Bukkit.getPlayerUniqueId(name); if (playerUUID == null) return null; + return playerUUIDMap.get(playerUUID); } @@ -380,10 +388,22 @@ public class PlayerManager { return playersNameCache.get(playerName.toLowerCase()); } + JobsPlayer jPlayer = playersNameCache.get(playerName.toLowerCase()); + + if (jPlayer != null) { + return jPlayer; + } + UUID playerUUID = Bukkit.getPlayerUniqueId(playerName); + if (playerUUID == null) return null; - JobsPlayer jPlayer = playersUUID.get(playerUUID); + jPlayer = playersUUID.get(playerUUID); + + if (jPlayer != null) { + playersNameCache.put(playerName.toLowerCase(), jPlayer); + } + return jPlayer != null ? jPlayer : playersUUIDCache.get(playerUUID); } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java b/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java index a703a83d..4eed1a05 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java @@ -1,9 +1,9 @@ package com.gamingmesh.jobs.commands.list; +import org.bukkit.command.CommandSender; + import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; -import com.gamingmesh.jobs.config.ExploreManager; -import org.bukkit.command.CommandSender; public class resetexploreregion implements Cmd { diff --git a/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java b/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java index 29ef4382..b838273d 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java @@ -47,10 +47,10 @@ public class ExploreManager { return; Jobs.consoleMsg("&eLoading explorer data"); + Long time = System.currentTimeMillis(); Jobs.getJobsDAO().loadExplore(); - int size = getSize(); - Jobs.consoleMsg("&eLoaded explorer data" + (size != 0 ? " (&6" + size + "&e)" : ".")); + Jobs.consoleMsg("&eLoaded explorer data" + (size != 0 ? " (&6" + size + "&e)" : " ") + " in " + (System.currentTimeMillis() - time) + " ms"); } public Map> getWorlds() { diff --git a/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java b/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java index 15c55f13..fa9e85e3 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java +++ b/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java @@ -79,10 +79,6 @@ public class ExploreChunk { playerIds.add(id); } catch (NumberFormatException e) { updated = true; - JobsPlayer jp = Jobs.getPlayerManager().getJobsPlayer(one); - - if (jp != null) - playerIds.add(jp.getUserId()); } } diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 596caa44..32a8ddcc 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -42,6 +42,7 @@ import com.gamingmesh.jobs.economy.PaymentData; import com.gamingmesh.jobs.stuff.TimeManage; import com.gamingmesh.jobs.stuff.Util; +import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Messages.CMIMessages; public abstract class JobsDAO { @@ -1328,7 +1329,7 @@ public abstract class JobsDAO { * @param userName - the player being searched for * @return list of all of the names of the jobs the players are part of. */ - public synchronized List getAllJobsOffline(String userName) { + public synchronized List getAllJobsOffline2(String userName) { List jobs = new ArrayList<>(); PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(userName); @@ -2581,6 +2582,7 @@ public abstract class JobsDAO { prest = conn.prepareStatement("SELECT * FROM `" + DBTables.ExploreDataTable.getTableName() + "`;"); res = prest.executeQuery(); Set missingWorlds = new HashSet<>(); + while (res.next()) { int worldId = res.getInt(ExploreDataTableFields.worldid.getCollumn()); JobsWorld jworld = Util.getJobsWorld(worldId);