mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-29 04:18:07 +01:00
Async data load on login when in multiserver mode
This commit is contained in:
parent
2d01ec3cc7
commit
63d2381c5b
@ -24,6 +24,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
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.Logs.CMIDebug;
|
||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||
import net.Zrips.CMILib.NBT.CMINBT;
|
||||
import net.Zrips.CMILib.Version.Version;
|
||||
import net.Zrips.CMILib.Version.Schedulers.CMIScheduler;
|
||||
|
||||
@ -232,10 +232,30 @@ public class PlayerManager {
|
||||
JobsPlayer jPlayer = playersUUIDCache.get(player.getUniqueId());
|
||||
|
||||
if (jPlayer == null || Jobs.getGCManager().MultiServerCompatability()) {
|
||||
if (jPlayer != null)
|
||||
|
||||
if (Jobs.getGCManager().MultiServerCompatability()) {
|
||||
CompletableFuture<JobsPlayer> future = CompletableFuture.supplyAsync(() -> {
|
||||
JobsPlayer jobsPlayer = playersUUIDCache.get(player.getUniqueId());
|
||||
jobsPlayer = jobsPlayer == null ? new JobsPlayer(player) : jobsPlayer;
|
||||
loadPlayer(jobsPlayer);
|
||||
return jobsPlayer;
|
||||
});
|
||||
future.thenAccept(this::finalizeJoinPlayer);
|
||||
return;
|
||||
}
|
||||
|
||||
jPlayer = jPlayer == null ? new JobsPlayer(player) : jPlayer;
|
||||
jPlayer = Jobs.getJobsDAO().loadFromDao(jPlayer);
|
||||
else
|
||||
jPlayer = Jobs.getJobsDAO().loadFromDao(player);
|
||||
|
||||
loadPlayer(jPlayer);
|
||||
}
|
||||
|
||||
finalizeJoinPlayer(jPlayer);
|
||||
}
|
||||
|
||||
private static void loadPlayer(JobsPlayer jPlayer) {
|
||||
|
||||
Jobs.getJobsDAO().loadFromDao(jPlayer);
|
||||
|
||||
if (Jobs.getGCManager().MultiServerCompatability()) {
|
||||
jPlayer.setArchivedJobs(Jobs.getJobsDAO().getArchivedJobs(jPlayer));
|
||||
@ -244,7 +264,7 @@ public class PlayerManager {
|
||||
}
|
||||
|
||||
// Lets load quest progression
|
||||
PlayerInfo info = Jobs.getJobsDAO().loadPlayerData(player.getUniqueId());
|
||||
PlayerInfo info = Jobs.getJobsDAO().loadPlayerData(jPlayer.getUniqueId());
|
||||
if (info != null) {
|
||||
jPlayer.setDoneQuests(info.getQuestsDone());
|
||||
jPlayer.setQuestProgressionFromString(info.getQuestProgression());
|
||||
@ -253,8 +273,10 @@ public class PlayerManager {
|
||||
Jobs.getJobsDAO().loadLog(jPlayer);
|
||||
}
|
||||
|
||||
private void finalizeJoinPlayer(JobsPlayer jPlayer) {
|
||||
|
||||
addPlayer(jPlayer);
|
||||
autoJoinJobs(player);
|
||||
autoJoinJobs(jPlayer.getPlayer());
|
||||
jPlayer.onConnect();
|
||||
jPlayer.reloadHonorific();
|
||||
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
|
||||
|
@ -9,7 +9,6 @@ import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.i18n.Language;
|
||||
|
||||
import net.Zrips.CMILib.Locale.LC;
|
||||
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||
import net.Zrips.CMILib.RawMessages.RawMessage;
|
||||
import net.Zrips.CMILib.Time.CMITimeManager;
|
||||
import net.Zrips.CMILib.Time.timeModifier;
|
||||
@ -97,23 +96,26 @@ public class boost implements Cmd {
|
||||
}
|
||||
}
|
||||
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());
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (type == null) {
|
||||
for (CurrencyType curr : CurrencyType.values()) {
|
||||
job.addBoost(curr, 0);
|
||||
}
|
||||
Language.sendMessage(sender, "command.boost.output.jobsboostreset", job);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
job.addBoost(type, 0);
|
||||
Language.sendMessage(sender, "command.boost.output.jobstypeboostreset", job, "%type%", type.getDisplayName());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,9 @@ public class resetlimit implements Cmd {
|
||||
|
||||
@Override
|
||||
public Boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
|
||||
if (args.length != 1) {
|
||||
|
||||
if (args.length != 1)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("all")) {
|
||||
for (JobsPlayer jPlayer : Jobs.getPlayerManager().getPlayersCache().values()) {
|
||||
|
@ -53,9 +53,9 @@ public class Language {
|
||||
|
||||
public static String updateJob(String text, Job job) {
|
||||
return text
|
||||
.replaceAll("\\[jobname\\]|%jobname%", job.getName())
|
||||
.replaceAll("\\[jobdisplayname\\]|%jobdisplayname%", job.getDisplayName())
|
||||
.replaceAll("\\[jobfullname\\]|%jobfullname%", job.getJobFullName());
|
||||
.replaceAll("(\\[|%)jobname(\\]|%)", job.getName())
|
||||
.replaceAll("(\\[|%)jobdisplayname(\\]|%)", job.getDisplayName())
|
||||
.replaceAll("(\\[|%)jobfullname(\\]|%)", job.getJobFullName());
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender sender, String key, Object... variables) {
|
||||
|
Loading…
Reference in New Issue
Block a user