1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-30 21:07:48 +01:00

Async data load on login when in multiserver mode

This commit is contained in:
Zrips 2024-04-16 14:51:33 +03:00
parent 2d01ec3cc7
commit 63d2381c5b
4 changed files with 64 additions and 40 deletions

View File

@ -24,6 +24,7 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -69,7 +70,6 @@ import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Logs.CMIDebug;
import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Messages.CMIMessages;
import net.Zrips.CMILib.NBT.CMINBT;
import net.Zrips.CMILib.Version.Version; import net.Zrips.CMILib.Version.Version;
import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; import net.Zrips.CMILib.Version.Schedulers.CMIScheduler;
@ -232,29 +232,51 @@ public class PlayerManager {
JobsPlayer jPlayer = playersUUIDCache.get(player.getUniqueId()); JobsPlayer jPlayer = playersUUIDCache.get(player.getUniqueId());
if (jPlayer == null || Jobs.getGCManager().MultiServerCompatability()) { if (jPlayer == null || Jobs.getGCManager().MultiServerCompatability()) {
if (jPlayer != null)
jPlayer = Jobs.getJobsDAO().loadFromDao(jPlayer);
else
jPlayer = Jobs.getJobsDAO().loadFromDao(player);
if (Jobs.getGCManager().MultiServerCompatability()) { if (Jobs.getGCManager().MultiServerCompatability()) {
jPlayer.setArchivedJobs(Jobs.getJobsDAO().getArchivedJobs(jPlayer)); CompletableFuture<JobsPlayer> future = CompletableFuture.supplyAsync(() -> {
jPlayer.setPaymentLimit(Jobs.getJobsDAO().getPlayersLimits(jPlayer)); JobsPlayer jobsPlayer = playersUUIDCache.get(player.getUniqueId());
jPlayer.setPoints(Jobs.getJobsDAO().getPlayerPoints(jPlayer)); jobsPlayer = jobsPlayer == null ? new JobsPlayer(player) : jobsPlayer;
loadPlayer(jobsPlayer);
return jobsPlayer;
});
future.thenAccept(this::finalizeJoinPlayer);
return;
} }
// Lets load quest progression jPlayer = jPlayer == null ? new JobsPlayer(player) : jPlayer;
PlayerInfo info = Jobs.getJobsDAO().loadPlayerData(player.getUniqueId()); jPlayer = Jobs.getJobsDAO().loadFromDao(jPlayer);
if (info != null) {
jPlayer.setDoneQuests(info.getQuestsDone());
jPlayer.setQuestProgressionFromString(info.getQuestProgression());
}
Jobs.getJobsDAO().loadLog(jPlayer); loadPlayer(jPlayer);
} }
finalizeJoinPlayer(jPlayer);
}
private static void loadPlayer(JobsPlayer jPlayer) {
Jobs.getJobsDAO().loadFromDao(jPlayer);
if (Jobs.getGCManager().MultiServerCompatability()) {
jPlayer.setArchivedJobs(Jobs.getJobsDAO().getArchivedJobs(jPlayer));
jPlayer.setPaymentLimit(Jobs.getJobsDAO().getPlayersLimits(jPlayer));
jPlayer.setPoints(Jobs.getJobsDAO().getPlayerPoints(jPlayer));
}
// Lets load quest progression
PlayerInfo info = Jobs.getJobsDAO().loadPlayerData(jPlayer.getUniqueId());
if (info != null) {
jPlayer.setDoneQuests(info.getQuestsDone());
jPlayer.setQuestProgressionFromString(info.getQuestProgression());
}
Jobs.getJobsDAO().loadLog(jPlayer);
}
private void finalizeJoinPlayer(JobsPlayer jPlayer) {
addPlayer(jPlayer); addPlayer(jPlayer);
autoJoinJobs(player); autoJoinJobs(jPlayer.getPlayer());
jPlayer.onConnect(); jPlayer.onConnect();
jPlayer.reloadHonorific(); jPlayer.reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(jPlayer); Jobs.getPermissionHandler().recalculatePermissions(jPlayer);

View File

@ -9,7 +9,6 @@ import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.i18n.Language;
import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Locale.LC;
import net.Zrips.CMILib.Logs.CMIDebug;
import net.Zrips.CMILib.RawMessages.RawMessage; import net.Zrips.CMILib.RawMessages.RawMessage;
import net.Zrips.CMILib.Time.CMITimeManager; import net.Zrips.CMILib.Time.CMITimeManager;
import net.Zrips.CMILib.Time.timeModifier; import net.Zrips.CMILib.Time.timeModifier;
@ -97,23 +96,26 @@ public class boost implements Cmd {
} }
} }
Language.sendMessage(sender, "command.boost.output.allreset"); Language.sendMessage(sender, "command.boost.output.allreset");
} else { return true;
for (Job one : Jobs.getJobs()) {
one.addBoost(type, 0);
}
Language.sendMessage(sender, "command.boost.output.alltypereset", "%type%", type.getDisplayName());
} }
} else {
if (type == null) { for (Job one : Jobs.getJobs()) {
for (CurrencyType curr : CurrencyType.values()) { one.addBoost(type, 0);
job.addBoost(curr, 0);
}
Language.sendMessage(sender, "command.boost.output.jobsboostreset", job);
} else {
job.addBoost(type, 0);
Language.sendMessage(sender, "command.boost.output.jobstypeboostreset", job, "%type%", type.getDisplayName());
} }
Language.sendMessage(sender, "command.boost.output.alltypereset", "%type%", type.getDisplayName());
return true;
} }
if (type == null) {
for (CurrencyType curr : CurrencyType.values()) {
job.addBoost(curr, 0);
}
Language.sendMessage(sender, "command.boost.output.jobsboostreset", job);
return true;
}
job.addBoost(type, 0);
Language.sendMessage(sender, "command.boost.output.jobstypeboostreset", job, "%type%", type.getDisplayName());
return true; return true;
} }

View File

@ -11,9 +11,9 @@ public class resetlimit implements Cmd {
@Override @Override
public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
if (args.length != 1) {
if (args.length != 1)
return false; return false;
}
if (args[0].equalsIgnoreCase("all")) { if (args[0].equalsIgnoreCase("all")) {
for (JobsPlayer jPlayer : Jobs.getPlayerManager().getPlayersCache().values()) { for (JobsPlayer jPlayer : Jobs.getPlayerManager().getPlayersCache().values()) {

View File

@ -53,9 +53,9 @@ public class Language {
public static String updateJob(String text, Job job) { public static String updateJob(String text, Job job) {
return text return text
.replaceAll("\\[jobname\\]|%jobname%", job.getName()) .replaceAll("(\\[|%)jobname(\\]|%)", job.getName())
.replaceAll("\\[jobdisplayname\\]|%jobdisplayname%", job.getDisplayName()) .replaceAll("(\\[|%)jobdisplayname(\\]|%)", job.getDisplayName())
.replaceAll("\\[jobfullname\\]|%jobfullname%", job.getJobFullName()); .replaceAll("(\\[|%)jobfullname(\\]|%)", job.getJobFullName());
} }
public static void sendMessage(CommandSender sender, String key, Object... variables) { public static void sendMessage(CommandSender sender, String key, Object... variables) {