From f7936dafb71d13fcc58f7524ab0880d3a9625924 Mon Sep 17 00:00:00 2001 From: Zrips Date: Wed, 14 Aug 2019 15:20:58 +0300 Subject: [PATCH] Lets compact sign save file Lets save player data if he finished quest New questtoplist as a sign variable to show top list by quests done on signs --- .../com/gamingmesh/jobs/Signs/SignUtil.java | 19 +++++++++++++------ .../com/gamingmesh/jobs/Signs/jobsSign.java | 2 +- .../gamingmesh/jobs/container/JobsPlayer.java | 17 ++++++++++++++--- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java index a2c2bdcf..cae70c17 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java @@ -109,14 +109,17 @@ public class SignUtil { newTemp.setType(SignTopType.getType(NameSection.getString("Type"))); newTemp.setNumber(NameSection.getInt("Number")); - if (NameSection.isString("JobName")) - newTemp.setJobName(NameSection.getString("JobName")); + if (NameSection.isString("JobName")) { + SignTopType t = SignTopType.getType(NameSection.getString("JobName")); + if (t == null) + newTemp.setJobName(NameSection.getString("JobName")); + } newTemp.setSpecial(NameSection.getBoolean("Special")); - HashMap old = SignsByType.get(newTemp.getJobName().toLowerCase()); + HashMap old = SignsByType.get(newTemp.getIdentifier().toLowerCase()); if (old == null) { old = new HashMap(); - SignsByType.put(newTemp.getJobName().toLowerCase(), old); + SignsByType.put(newTemp.getIdentifier().toLowerCase(), old); } String loc = newTemp.locToBlockString(); if (loc == null) { @@ -171,6 +174,8 @@ public class SignUtil { return SignUpdate(null, type); } + public static Integer questSignUpdateShed = null; + public boolean SignUpdate(Job job, SignTopType type) { if (!Jobs.getGCManager().SignsEnabled) return true; @@ -248,8 +253,10 @@ public class SignUtil { org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState(); if (!jSign.isSpecial()) { for (int i = 0; i < 4; i++) { - if (i + number >= PlayerList.size()) - break; + if (i + number >= PlayerList.size()) { + sign.setLine(i, ""); + continue; + } String PlayerName = PlayerList.get(i + number).getPlayerName(); if (PlayerName == null) diff --git a/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java b/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java index a24a16c8..58a3a3e7 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java @@ -147,7 +147,7 @@ public class jobsSign { } public SignTopType getType() { - return type == null ? SignTopType.toplist : type; + return type == null ? SignTopType.getType(jobName) == null ? SignTopType.toplist : SignTopType.getType(jobName) : type; } public void setType(SignTopType type) { diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 66b0cedb..4f820ae8 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -26,10 +26,12 @@ import java.util.Map.Entry; import java.util.UUID; import org.bukkit.Bukkit; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Signs.SignTopType; +import com.gamingmesh.jobs.Signs.SignUtil; import com.gamingmesh.jobs.dao.JobsDAO; import com.gamingmesh.jobs.economy.PaymentData; import com.gamingmesh.jobs.resources.jfep.Parser; @@ -506,7 +508,6 @@ public class JobsPlayer { newLevel = maxLevel; setLevel(job, newLevel); - Jobs.getPlayerManager().performCommandOnLevelUp(this, job, newLevel - 1); // } } @@ -1060,9 +1061,19 @@ public class JobsPlayer { this.doneQuests = doneQuests; } - public void addDoneQuest() { - Jobs.getSignUtil().SignUpdate(SignTopType.questtoplist); + public void addDoneQuest() { this.doneQuests++; + this.setSaved(false); + + if (SignUtil.questSignUpdateShed == null) { + SignUtil.questSignUpdateShed = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Jobs.getInstance(), new Runnable() { + @Override + public void run() { + Jobs.getSignUtil().SignUpdate(SignTopType.questtoplist); + SignUtil.questSignUpdateShed = null; + } + }, Jobs.getGCManager().getSavePeriod() * 60 * 20L); + } } public int getFurnaceCount() {