1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 15:03:36 +01:00

Properly updating current player count in the job

This commit is contained in:
Zrips 2024-04-16 12:21:30 +03:00
parent 1fb79f4ba2
commit 746c4313cb
2 changed files with 17 additions and 5 deletions

View File

@ -489,7 +489,8 @@ public class PlayerManager {
Jobs.takeSlot(job); Jobs.takeSlot(job);
Jobs.getSignUtil().updateAllSign(job); Jobs.getSignUtil().updateAllSign(job);
job.updateTotalPlayers(); job.modifyTotalPlayerWorking(1);
jPlayer.maxJobsEquation = CMINumber.clamp(getMaxJobs(jPlayer), 0, 9999); jPlayer.maxJobsEquation = CMINumber.clamp(getMaxJobs(jPlayer), 0, 9999);
// Removing from cached item boost for recalculation // Removing from cached item boost for recalculation
@ -534,7 +535,8 @@ public class PlayerManager {
jPlayer.getLeftTimes().remove(jPlayer.getUniqueId()); jPlayer.getLeftTimes().remove(jPlayer.getUniqueId());
Jobs.getSignUtil().updateAllSign(job); Jobs.getSignUtil().updateAllSign(job);
job.updateTotalPlayers();
job.modifyTotalPlayerWorking(-1);
// Removing from cached item boost for recalculation // Removing from cached item boost for recalculation
cache.remove(jPlayer.getUniqueId()); cache.remove(jPlayer.getUniqueId());
@ -565,9 +567,9 @@ public class PlayerManager {
if (!jPlayer.transferJob(oldjob, newjob) || !Jobs.getJobsDAO().quitJob(jPlayer, oldjob)) if (!jPlayer.transferJob(oldjob, newjob) || !Jobs.getJobsDAO().quitJob(jPlayer, oldjob))
return false; return false;
oldjob.updateTotalPlayers(); oldjob.modifyTotalPlayerWorking(-1);
Jobs.getJobsDAO().joinJob(jPlayer, jPlayer.getJobProgression(newjob)); Jobs.getJobsDAO().joinJob(jPlayer, jPlayer.getJobProgression(newjob));
newjob.updateTotalPlayers(); newjob.modifyTotalPlayerWorking(1);
jPlayer.save(); jPlayer.save();
return true; return true;
} }

View File

@ -211,6 +211,16 @@ public class Job {
return totalPlayers; return totalPlayers;
} }
/**
*
* @param change the amount to change
* @return the new total
*/
public int modifyTotalPlayerWorking(int change) {
totalPlayers = CMINumber.clamp(totalPlayers + change, 0, Integer.MAX_VALUE);
updateBonus();
return totalPlayers;
}
/** /**
* Updates the total players property from database synchronously. * Updates the total players property from database synchronously.