1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-02 14:29:07 +01:00

Properly loading archived jobs when running network

This commit is contained in:
Zrips 2020-12-17 17:16:48 +02:00
parent c97beba83d
commit 7544eea2ac
3 changed files with 56 additions and 6 deletions

View File

@ -1174,7 +1174,7 @@ public class Jobs extends JavaPlugin {
return false;
}
if ((time < System.currentTimeMillis()) && (bp.getAction() != DBAction.DELETE)) {
if (time < System.currentTimeMillis() && bp.getAction() != DBAction.DELETE) {
getBpManager().remove(block);
return true;
}

View File

@ -188,6 +188,12 @@ public class PlayerManager {
else
jPlayer = Jobs.getJobsDAO().loadFromDao(player);
if (Jobs.getGCManager().MultiServerCompatability()) {
ArchivedJobs archivedJobs = Jobs.getJobsDAO().getArchivedJobs(jPlayer);
if (archivedJobs != null) {
jPlayer.setArchivedJobs(archivedJobs);
}
}
// Lets load quest progression
PlayerInfo info = Jobs.getJobsDAO().loadPlayerData(player.getUniqueId());
if (info != null) {
@ -384,8 +390,7 @@ public class PlayerManager {
if (jobsjoinevent.isCancelled())
return;
Bukkit.getScheduler().runTaskAsynchronously(Jobs.getInstance(), () ->
Jobs.getJobsDAO().joinJob(jPlayer, jPlayer.getJobProgression(job)));
Bukkit.getScheduler().runTaskAsynchronously(Jobs.getInstance(), () -> Jobs.getJobsDAO().joinJob(jPlayer, jPlayer.getJobProgression(job)));
jPlayer.setLeftTime(job);
PerformCommands.performCommandsOnJoin(jPlayer, job);
@ -690,7 +695,7 @@ public class PlayerManager {
if (levelUpEvent.getOldTitle() != null)
message = message.replace("%titlename%", levelUpEvent.getOldTitle()
.getChatColor().toString() + levelUpEvent.getOldTitle().getName());
.getChatColor().toString() + levelUpEvent.getOldTitle().getName());
message = message.replace("%playername%", player != null ? player.getDisplayName() : jPlayer.getName());
message = message.replace("%joblevel%", "" + prog.getLevel());
@ -715,7 +720,7 @@ public class PlayerManager {
Sound sound = levelUpEvent.getTitleChangeSound();
if (player != null)
player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getTitleChangeVolume(),
levelUpEvent.getTitleChangePitch());
levelUpEvent.getTitleChangePitch());
}
} catch (Exception e) {
}
@ -727,7 +732,7 @@ public class PlayerManager {
message = message.replace("%playername%", player != null ? player.getDisplayName() : jPlayer.getName());
message = message.replace("%titlename%", levelUpEvent.getNewTitle()
.getChatColor().toString() + levelUpEvent.getNewTitle().getName());
.getChatColor().toString() + levelUpEvent.getNewTitle().getName());
message = message.replace("%jobname%", job.getNameWithColor());
for (String line : message.split("\n")) {

View File

@ -752,6 +752,51 @@ public abstract class JobsDAO {
return map;
}
public ArchivedJobs getArchivedJobs(JobsPlayer player) {
ArchivedJobs jobs = new ArchivedJobs();
JobsConnection conn = getConnection();
if (conn == null || player == null)
return jobs;
PreparedStatement prest = null;
ResultSet res = null;
try {
prest = conn.prepareStatement("SELECT * FROM `" + DBTables.ArchiveTable.getTableName() + "` WHERE `" + ArchiveTableFields.userid.getCollumn() + "` = ?;");
prest.setInt(1, player.getUserId());
res = prest.executeQuery();
while (res.next()) {
String jobName = res.getString(ArchiveTableFields.job.getCollumn());
Double exp = res.getDouble(ArchiveTableFields.experience.getCollumn());
int lvl = res.getInt(ArchiveTableFields.level.getCollumn());
Long left = res.getLong(ArchiveTableFields.left.getCollumn());
int jobid = res.getInt(ArchiveTableFields.jobid.getCollumn());
Job job = null;
if (jobid != 0) {
job = Jobs.getJob(jobid);
} else {
job = Jobs.getJob(jobName);
converted = false;
}
if (job == null)
continue;
JobProgression jp = new JobProgression(job, player, lvl, exp);
if (left != 0L)
jp.setLeftOn(left);
jobs.addArchivedJob(jp);
}
} catch (Exception e) {
close(res);
close(prest);
} finally {
close(res);
close(prest);
}
return jobs;
}
public HashMap<Integer, HashMap<String, Log>> getAllLogs() {
HashMap<Integer, HashMap<String, Log>> map = new HashMap<>();
JobsConnection conn = getConnection();