1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 04:25:15 +01:00

PLayer data load needs to be in sync...

This commit is contained in:
Zrips 2021-07-16 17:58:40 +03:00
parent 404dcb8f1a
commit bbdacf8e03
3 changed files with 31 additions and 37 deletions

View File

@ -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<Void> 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<Void> loadAllPlayersData() {
return CompletableFuture.supplyAsync(() -> {
long time = System.currentTimeMillis();
// Cloning to avoid issues
Map<UUID, PlayerInfo> temp = new HashMap<>(getPlayerManager().getPlayersInfoUUIDMap());
Map<Integer, List<JobsDAOData>> playersJobs = dao.getAllJobs();
Map<Integer, PlayerPoints> playersPoints = dao.getAllPoints();
Map<Integer, Map<String, Log>> playersLogs = dao.getAllLogs();
Map<Integer, ArchivedJobs> playersArchives = dao.getAllArchivedJobs();
Map<Integer, PaymentData> playersLimits = dao.loadPlayerLimits();
for (Iterator<PlayerInfo> 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<UUID, PlayerInfo> temp = new HashMap<>(getPlayerManager().getPlayersInfoUUIDMap());
Map<Integer, List<JobsDAOData>> playersJobs = dao.getAllJobs();
Map<Integer, PlayerPoints> playersPoints = dao.getAllPoints();
Map<Integer, Map<String, Log>> playersLogs = dao.getAllLogs();
Map<Integer, ArchivedJobs> playersArchives = dao.getAllArchivedJobs();
Map<Integer, PaymentData> playersLimits = dao.loadPlayerLimits();
for (Iterator<PlayerInfo> 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() {

View File

@ -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) {

View File

@ -1779,7 +1779,6 @@ public abstract class JobsDAO {
res.getInt(UserTableFields.donequests.getCollumn()),
res.getString(UserTableFields.quests.getCollumn())));
} catch (IllegalArgumentException e) {
uuids.add(uuid);
}
}