mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-01 15:03:36 +01:00
Fix for unnecessary player data saving on server startup
This commit is contained in:
parent
339ec5be3e
commit
42e3043062
@ -115,6 +115,7 @@ import com.gamingmesh.jobs.tasks.DatabaseSaveThread;
|
|||||||
import net.Zrips.CMILib.ActionBar.CMIActionBar;
|
import net.Zrips.CMILib.ActionBar.CMIActionBar;
|
||||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||||
import net.Zrips.CMILib.Locale.LC;
|
import net.Zrips.CMILib.Locale.LC;
|
||||||
|
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||||
import net.Zrips.CMILib.RawMessages.RawMessage;
|
import net.Zrips.CMILib.RawMessages.RawMessage;
|
||||||
import net.Zrips.CMILib.Version.Version;
|
import net.Zrips.CMILib.Version.Version;
|
||||||
@ -1102,8 +1103,9 @@ public final class Jobs extends JavaPlugin {
|
|||||||
if (info.getType() == ActionType.BREAK && block != null)
|
if (info.getType() == ActionType.BREAK && block != null)
|
||||||
getBpManager().remove(block);
|
getBpManager().remove(block);
|
||||||
|
|
||||||
if (pointAmount != 0D)
|
if (pointAmount != 0D) {
|
||||||
jPlayer.setSaved(false);
|
jPlayer.setSaved(false);
|
||||||
|
}
|
||||||
|
|
||||||
Map<CurrencyType, Double> payments = new HashMap<>();
|
Map<CurrencyType, Double> payments = new HashMap<>();
|
||||||
if (income != 0D)
|
if (income != 0D)
|
||||||
|
@ -440,10 +440,10 @@ public class PlayerManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
jPlayer.progression.add(new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience()));
|
jPlayer.progression.add(new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience()));
|
||||||
jPlayer.reloadMaxExperience();
|
|
||||||
jPlayer.reloadLimits();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
jPlayer.reloadMaxExperience();
|
||||||
|
jPlayer.reloadLimits();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (points != null)
|
if (points != null)
|
||||||
|
@ -25,6 +25,7 @@ import com.gamingmesh.jobs.Jobs;
|
|||||||
import com.gamingmesh.jobs.stuff.Util;
|
import com.gamingmesh.jobs.stuff.Util;
|
||||||
|
|
||||||
import net.Zrips.CMILib.Container.CMINumber;
|
import net.Zrips.CMILib.Container.CMINumber;
|
||||||
|
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||||
import net.Zrips.CMILib.Time.CMITimeManager;
|
import net.Zrips.CMILib.Time.CMITimeManager;
|
||||||
|
|
||||||
public class JobProgression {
|
public class JobProgression {
|
||||||
@ -37,10 +38,10 @@ public class JobProgression {
|
|||||||
private long leftOn = 0;
|
private long leftOn = 0;
|
||||||
|
|
||||||
public JobProgression(Job job, JobsPlayer jPlayer, int level, double experience) {
|
public JobProgression(Job job, JobsPlayer jPlayer, int level, double experience) {
|
||||||
this.job = job;
|
this.job = job;
|
||||||
this.jPlayer = jPlayer;
|
this.jPlayer = jPlayer;
|
||||||
this.experience = experience;
|
this.experience = experience;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +50,7 @@ public class JobProgression {
|
|||||||
* @return false if the job cannot
|
* @return false if the job cannot
|
||||||
*/
|
*/
|
||||||
public boolean canLevelUp() {
|
public boolean canLevelUp() {
|
||||||
return experience >= maxExperience;
|
return experience >= maxExperience;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,7 +59,7 @@ public class JobProgression {
|
|||||||
* @return false if the job cannot
|
* @return false if the job cannot
|
||||||
*/
|
*/
|
||||||
public boolean canLevelDown() {
|
public boolean canLevelDown() {
|
||||||
return experience < 0;
|
return experience < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,7 +67,7 @@ public class JobProgression {
|
|||||||
* @return the job
|
* @return the job
|
||||||
*/
|
*/
|
||||||
public Job getJob() {
|
public Job getJob() {
|
||||||
return job;
|
return job;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,9 +76,9 @@ public class JobProgression {
|
|||||||
*/
|
*/
|
||||||
public void setJob(Job job) {
|
public void setJob(Job job) {
|
||||||
// synchronized (jPlayer.saveLock) {
|
// synchronized (jPlayer.saveLock) {
|
||||||
jPlayer.setSaved(false);
|
jPlayer.setSaved(false);
|
||||||
this.job = job;
|
this.job = job;
|
||||||
reloadMaxExperienceAndCheckLevelUp();
|
reloadMaxExperienceAndCheckLevelUp();
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ public class JobProgression {
|
|||||||
* @return the experiece in this job
|
* @return the experiece in this job
|
||||||
*/
|
*/
|
||||||
public double getExperience() {
|
public double getExperience() {
|
||||||
return experience;
|
return experience;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,10 +96,10 @@ public class JobProgression {
|
|||||||
* @return - job level up
|
* @return - job level up
|
||||||
*/
|
*/
|
||||||
public boolean addExperience(double experience) {
|
public boolean addExperience(double experience) {
|
||||||
jPlayer.setSaved(false);
|
jPlayer.setSaved(false);
|
||||||
this.experience += experience;
|
this.experience += experience;
|
||||||
lastExperience = getLastExperience() + experience;
|
lastExperience = getLastExperience() + experience;
|
||||||
return checkLevelUp();
|
return checkLevelUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,9 +108,9 @@ public class JobProgression {
|
|||||||
* @return - job level up
|
* @return - job level up
|
||||||
*/
|
*/
|
||||||
public boolean setExperience(double experience) {
|
public boolean setExperience(double experience) {
|
||||||
jPlayer.setSaved(false);
|
jPlayer.setSaved(false);
|
||||||
this.experience = experience;
|
this.experience = experience;
|
||||||
return checkLevelUp();
|
return checkLevelUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,10 +119,10 @@ public class JobProgression {
|
|||||||
* @return - job level up
|
* @return - job level up
|
||||||
*/
|
*/
|
||||||
public boolean takeExperience(double experience) {
|
public boolean takeExperience(double experience) {
|
||||||
jPlayer.setSaved(false);
|
jPlayer.setSaved(false);
|
||||||
this.experience -= experience;
|
this.experience -= experience;
|
||||||
lastExperience = getLastExperience() + experience;
|
lastExperience = getLastExperience() + experience;
|
||||||
return checkLevelUp();
|
return checkLevelUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,7 +130,7 @@ public class JobProgression {
|
|||||||
* @return the experience needed to level up
|
* @return the experience needed to level up
|
||||||
*/
|
*/
|
||||||
public int getMaxExperience() {
|
public int getMaxExperience() {
|
||||||
return maxExperience;
|
return maxExperience;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -137,7 +138,7 @@ public class JobProgression {
|
|||||||
* @return the level of this job
|
* @return the level of this job
|
||||||
*/
|
*/
|
||||||
public int getLevel() {
|
public int getLevel() {
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,9 +146,9 @@ public class JobProgression {
|
|||||||
* @return the level of this job
|
* @return the level of this job
|
||||||
*/
|
*/
|
||||||
public String getLevelFormatted() {
|
public String getLevelFormatted() {
|
||||||
if (Jobs.getGCManager().RomanNumbers)
|
if (Jobs.getGCManager().RomanNumbers)
|
||||||
return CMINumber.toRoman(level);
|
return CMINumber.toRoman(level);
|
||||||
return String.valueOf(level);
|
return String.valueOf(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,26 +158,26 @@ public class JobProgression {
|
|||||||
* @return true if this progression can level up
|
* @return true if this progression can level up
|
||||||
*/
|
*/
|
||||||
public boolean setLevel(int level) {
|
public boolean setLevel(int level) {
|
||||||
jPlayer.setSaved(false);
|
jPlayer.setSaved(false);
|
||||||
this.level = level;
|
this.level = level;
|
||||||
return reloadMaxExperienceAndCheckLevelUp();
|
return reloadMaxExperienceAndCheckLevelUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reloads max experience
|
* Reloads max experience
|
||||||
*/
|
*/
|
||||||
public void reloadMaxExperience() {
|
public void reloadMaxExperience() {
|
||||||
Map<String, Double> param = new HashMap<>();
|
Map<String, Double> param = new HashMap<>();
|
||||||
param.put("joblevel", (double) level);
|
param.put("joblevel", (double) level);
|
||||||
param.put("numjobs", (double) jPlayer.getJobProgression().size());
|
param.put("numjobs", (double) jPlayer.getJobProgression().size());
|
||||||
maxExperience = (int) job.getMaxExp(param);
|
maxExperience = (int) job.getMaxExp(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxExperience(int level) {
|
public int getMaxExperience(int level) {
|
||||||
Map<String, Double> param = new HashMap<>();
|
Map<String, Double> param = new HashMap<>();
|
||||||
param.put("joblevel", (double) level);
|
param.put("joblevel", (double) level);
|
||||||
param.put("numjobs", (double) jPlayer.getJobProgression().size());
|
param.put("numjobs", (double) jPlayer.getJobProgression().size());
|
||||||
return (int) job.getMaxExp(param);
|
return (int) job.getMaxExp(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,31 +185,31 @@ public class JobProgression {
|
|||||||
* @returns if level up was performed
|
* @returns if level up was performed
|
||||||
*/
|
*/
|
||||||
private boolean checkLevelUp() {
|
private boolean checkLevelUp() {
|
||||||
if (level == 1 && experience < 0)
|
if (level == 1 && experience < 0)
|
||||||
experience = 0;
|
experience = 0;
|
||||||
|
|
||||||
if (experience < 0)
|
if (experience < 0)
|
||||||
return checkLevelDown();
|
return checkLevelDown();
|
||||||
|
|
||||||
boolean ret = false;
|
boolean ret = false;
|
||||||
while (canLevelUp()) {
|
while (canLevelUp()) {
|
||||||
// Don't level up at max level
|
// Don't level up at max level
|
||||||
if (job.getMaxLevel() > 0 && level >= jPlayer.getMaxJobLevelAllowed(job))
|
if (job.getMaxLevel() > 0 && level >= jPlayer.getMaxJobLevelAllowed(job))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
level++;
|
level++;
|
||||||
experience -= maxExperience;
|
experience -= maxExperience;
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
reloadMaxExperience();
|
reloadMaxExperience();
|
||||||
jPlayer.reloadLimits();
|
jPlayer.reloadLimits();
|
||||||
}
|
}
|
||||||
|
|
||||||
// At max level
|
// At max level
|
||||||
if (experience > maxExperience)
|
if (experience > maxExperience)
|
||||||
experience = maxExperience;
|
experience = maxExperience;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -216,26 +217,26 @@ public class JobProgression {
|
|||||||
* @returns if level down was performed
|
* @returns if level down was performed
|
||||||
*/
|
*/
|
||||||
private boolean checkLevelDown() {
|
private boolean checkLevelDown() {
|
||||||
boolean ret = false;
|
boolean ret = false;
|
||||||
while (canLevelDown()) {
|
while (canLevelDown()) {
|
||||||
if (
|
if (
|
||||||
// Don't level down at 1
|
// Don't level down at 1
|
||||||
level <= 1 ||
|
level <= 1 ||
|
||||||
!Jobs.getGCManager().AllowDelevel
|
!Jobs.getGCManager().AllowDelevel) {
|
||||||
) {
|
experience = 0;
|
||||||
experience = 0;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
level--;
|
level--;
|
||||||
experience += getMaxExperience(level);
|
experience += getMaxExperience(level);
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
reloadMaxExperience();
|
reloadMaxExperience();
|
||||||
jPlayer.reloadLimits();
|
|
||||||
}
|
jPlayer.reloadLimits();
|
||||||
return ret;
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -244,37 +245,37 @@ public class JobProgression {
|
|||||||
* @return if leveled up
|
* @return if leveled up
|
||||||
*/
|
*/
|
||||||
private boolean reloadMaxExperienceAndCheckLevelUp() {
|
private boolean reloadMaxExperienceAndCheckLevelUp() {
|
||||||
reloadMaxExperience();
|
reloadMaxExperience();
|
||||||
return checkLevelUp();
|
return checkLevelUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getLeftOn() {
|
public Long getLeftOn() {
|
||||||
return leftOn;
|
return leftOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JobProgression setLeftOn(Long leftOn) {
|
public JobProgression setLeftOn(Long leftOn) {
|
||||||
this.leftOn = leftOn;
|
this.leftOn = leftOn;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canRejoin() {
|
public boolean canRejoin() {
|
||||||
if (leftOn == 0 || leftOn + job.getRejoinCd() < System.currentTimeMillis())
|
if (leftOn == 0 || leftOn + job.getRejoinCd() < System.currentTimeMillis())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
org.bukkit.entity.Player player = jPlayer != null ? jPlayer.getPlayer() : null;
|
org.bukkit.entity.Player player = jPlayer != null ? jPlayer.getPlayer() : null;
|
||||||
return player != null && player.hasPermission("jobs.rejoinbypass");
|
return player != null && player.hasPermission("jobs.rejoinbypass");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRejoinTimeMessage() {
|
public String getRejoinTimeMessage() {
|
||||||
return leftOn == 0 ? "" : CMITimeManager.to24hourShort(leftOn + job.getRejoinCd() - System.currentTimeMillis());
|
return leftOn == 0 ? "" : CMITimeManager.to24hourShort(leftOn + job.getRejoinCd() - System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getLastExperience() {
|
public double getLastExperience() {
|
||||||
return lastExperience;
|
return lastExperience;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastExperience(double lastExperience) {
|
public void setLastExperience(double lastExperience) {
|
||||||
this.lastExperience = lastExperience;
|
this.lastExperience = lastExperience;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ import net.Zrips.CMILib.Colors.CMIChatColor;
|
|||||||
import net.Zrips.CMILib.Container.CMINumber;
|
import net.Zrips.CMILib.Container.CMINumber;
|
||||||
import net.Zrips.CMILib.Equations.Parser;
|
import net.Zrips.CMILib.Equations.Parser;
|
||||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||||
|
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||||
import net.Zrips.CMILib.Time.CMITimeManager;
|
import net.Zrips.CMILib.Time.CMITimeManager;
|
||||||
import net.Zrips.CMILib.Version.Schedulers.CMIScheduler;
|
import net.Zrips.CMILib.Version.Schedulers.CMIScheduler;
|
||||||
import net.Zrips.CMILib.Version.Schedulers.CMITask;
|
import net.Zrips.CMILib.Version.Schedulers.CMITask;
|
||||||
@ -447,6 +448,7 @@ public class JobsPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void reloadLimits() {
|
public void reloadLimits() {
|
||||||
|
|
||||||
for (CurrencyType type : CurrencyType.values()) {
|
for (CurrencyType type : CurrencyType.values()) {
|
||||||
reload(type);
|
reload(type);
|
||||||
}
|
}
|
||||||
@ -478,6 +480,7 @@ public class JobsPlayer {
|
|||||||
public int getJobCount() {
|
public int getJobCount() {
|
||||||
return getJobCount(true);
|
return getJobCount(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getJobCount(boolean includeIgnoredMaxJobs) {
|
public int getJobCount(boolean includeIgnoredMaxJobs) {
|
||||||
|
|
||||||
if (includeIgnoredMaxJobs)
|
if (includeIgnoredMaxJobs)
|
||||||
@ -997,6 +1000,8 @@ public class JobsPlayer {
|
|||||||
public void setSaved(boolean isSaved) {
|
public void setSaved(boolean isSaved) {
|
||||||
if (!isSaved && !isOnline())
|
if (!isSaved && !isOnline())
|
||||||
Jobs.getPlayerManager().addPlayer(this);
|
Jobs.getPlayerManager().addPlayer(this);
|
||||||
|
if (!Jobs.fullyLoaded)
|
||||||
|
return;
|
||||||
this.isSaved = isSaved;
|
this.isSaved = isSaved;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1376,6 +1381,7 @@ public class JobsPlayer {
|
|||||||
|
|
||||||
public void addDoneQuest(final Job job) {
|
public void addDoneQuest(final Job job) {
|
||||||
doneQuests++;
|
doneQuests++;
|
||||||
|
|
||||||
setSaved(false);
|
setSaved(false);
|
||||||
|
|
||||||
if (questSignUpdateShed == null) {
|
if (questSignUpdateShed == null) {
|
||||||
|
@ -11,6 +11,8 @@ import com.gamingmesh.jobs.Jobs;
|
|||||||
import com.gamingmesh.jobs.actions.EnchantActionInfo;
|
import com.gamingmesh.jobs.actions.EnchantActionInfo;
|
||||||
import com.gamingmesh.jobs.stuff.Util;
|
import com.gamingmesh.jobs.stuff.Util;
|
||||||
|
|
||||||
|
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||||
|
|
||||||
public class QuestProgression {
|
public class QuestProgression {
|
||||||
|
|
||||||
private Quest quest;
|
private Quest quest;
|
||||||
|
Loading…
Reference in New Issue
Block a user