From 416ad5f8e7c30455cf68bf5f73b7a9ff084478c9 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Mon, 16 Nov 2020 19:42:33 +0100 Subject: [PATCH] Calculate the max jobs variable for equations --- .../com/gamingmesh/jobs/Gui/GuiManager.java | 12 ++++----- src/main/java/com/gamingmesh/jobs/Jobs.java | 10 +++---- .../jobs/Placeholders/Placeholder.java | 8 ++---- .../com/gamingmesh/jobs/PlayerManager.java | 24 +++++++++++++---- .../jobs/commands/JobsCommands.java | 6 ++--- .../gamingmesh/jobs/config/ConfigManager.java | 8 +++--- .../gamingmesh/jobs/container/JobInfo.java | 9 ++++--- .../gamingmesh/jobs/container/JobsPlayer.java | 27 ++++++++++--------- src/main/resources/jobConfig.yml | 6 ++++- 9 files changed, 65 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java index f2f6d63a..36f7205b 100644 --- a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java +++ b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java @@ -215,15 +215,15 @@ public class GuiManager { continue; } - double income = jInfo.getIncome(level, numjobs); + double income = jInfo.getIncome(level, numjobs, JPlayer.maxJobsEquation); income = boost.getFinalAmount(CurrencyType.MONEY, income); String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString(); - double xp = jInfo.getExperience(level, numjobs); + double xp = jInfo.getExperience(level, numjobs, JPlayer.maxJobsEquation); xp = boost.getFinalAmount(CurrencyType.EXP, xp); String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString(); - double points = jInfo.getPoints(level, numjobs); + double points = jInfo.getPoints(level, numjobs, JPlayer.maxJobsEquation); points = boost.getFinalAmount(CurrencyType.POINTS, points); String pointsColor = points >= 0 ? "" : ChatColor.RED.toString(); @@ -372,15 +372,15 @@ public class GuiManager { continue; } - double income = jInfo.getIncome(level, numjobs); + double income = jInfo.getIncome(level, numjobs, JPlayer.maxJobsEquation); income = boost.getFinalAmount(CurrencyType.MONEY, income); String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString(); - double xp = jInfo.getExperience(level, numjobs); + double xp = jInfo.getExperience(level, numjobs, JPlayer.maxJobsEquation); xp = boost.getFinalAmount(CurrencyType.EXP, xp); String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString(); - double points = jInfo.getPoints(level, numjobs); + double points = jInfo.getPoints(level, numjobs, JPlayer.maxJobsEquation); points = boost.getFinalAmount(CurrencyType.POINTS, points); String pointsColor = points >= 0 ? "" : ChatColor.RED.toString(); diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 0857d513..80390d44 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -892,8 +892,8 @@ public class Jobs extends JavaPlugin { if (jobinfo == null) return; - Double income = jobinfo.getIncome(1, numjobs); - Double pointAmount = jobinfo.getPoints(1, numjobs); + Double income = jobinfo.getIncome(1, numjobs, jPlayer.maxJobsEquation); + Double pointAmount = jobinfo.getPoints(1, numjobs, jPlayer.maxJobsEquation); if (income == 0D && pointAmount == 0D) return; @@ -997,9 +997,9 @@ public class Jobs extends JavaPlugin { continue; } - Double income = jobinfo.getIncome(level, numjobs); - Double pointAmount = jobinfo.getPoints(level, numjobs); - Double expAmount = jobinfo.getExperience(level, numjobs); + Double income = jobinfo.getIncome(level, numjobs, jPlayer.maxJobsEquation); + Double pointAmount = jobinfo.getPoints(level, numjobs, jPlayer.maxJobsEquation); + Double expAmount = jobinfo.getExperience(level, numjobs, jPlayer.maxJobsEquation); if (income == 0D && pointAmount == 0D && expAmount == 0D) continue; diff --git a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java index c346a198..b41acc83 100644 --- a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java +++ b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java @@ -573,9 +573,7 @@ public class Placeholder { return convert(true); case maxjobs: - int max = Jobs.getPermissionManager().getMaxPermission(user, "jobs.max", false).intValue(); - max = max == 0 ? Jobs.getGCManager().getMaxJobs() : max; - return Integer.toString(max); + return Integer.toString(Jobs.getPlayerManager().getMaxJobs(user)); default: break; @@ -622,9 +620,7 @@ public class Placeholder { // Global placeholders switch (placeHolder) { case maxjobs: - int max = Jobs.getPermissionManager().getMaxPermission(user, "jobs.max", false).intValue(); - max = max == 0 ? Jobs.getGCManager().getMaxJobs() : max; - return Integer.toString(max); + return Integer.toString(Jobs.getPlayerManager().getMaxJobs(user)); case total_workers: return Integer.toString(Jobs.getJobsDAO().getTotalPlayers()); default: diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index e0d94084..b932f3ac 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -393,6 +393,7 @@ public class PlayerManager { Jobs.getSignUtil().updateAllSign(job); job.updateTotalPlayers(); + jPlayer.maxJobsEquation = getMaxJobs(jPlayer); } /** @@ -779,14 +780,27 @@ public class PlayerManager { } /** - * Get max jobs - * @param player - * @return True if he have permission + * Checks whenever the given jobs player is under the max allowed jobs. + * @param player {@link JobsPlayer} + * @param currentCount the current jobs size + * @return true if the player is under the given jobs size */ public boolean getJobsLimit(JobsPlayer jPlayer, short currentCount) { + return getMaxJobs(jPlayer) > currentCount; + } + + /** + * Gets the maximum jobs from player. + * @param jPlayer {@link JobsPlayer} + * @return the maximum allowed jobs + */ + public int getMaxJobs(JobsPlayer jPlayer) { + if (jPlayer == null) { + return 0; + } + int max = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.max", false).intValue(); - max = max == 0 ? Jobs.getGCManager().getMaxJobs() : max; - return max > currentCount; + return max == 0 ? Jobs.getGCManager().getMaxJobs() : max; } public BoostMultiplier getBoost(JobsPlayer player, Job job) { diff --git a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java index 666867b6..abf95044 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java @@ -348,16 +348,16 @@ public class JobsCommands implements CommandExecutor { String materialName = info.getRealisticName(); - double income = info.getIncome(level, numjobs); + double income = info.getIncome(level, numjobs, player.maxJobsEquation); income = boost.getFinalAmount(CurrencyType.MONEY, income); String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString(); - double xp = info.getExperience(level, numjobs); + double xp = info.getExperience(level, numjobs, player.maxJobsEquation); xp = boost.getFinalAmount(CurrencyType.EXP, xp); String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString(); - double points = info.getPoints(level, numjobs); + double points = info.getPoints(level, numjobs, player.maxJobsEquation); points = boost.getFinalAmount(CurrencyType.POINTS, points); String pointsColor = xp >= 0 ? "" : ChatColor.RED.toString(); diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index b8071bdb..de6380f3 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -120,6 +120,7 @@ public class ConfigManager { cfg.addComment(pt + ".leveling-progression-equation", "Equation used for calculating how much experience is needed to go to the next level.", "Available parameters:", " numjobs - the number of jobs the player has", + " maxjobs - the number of jobs the player have max", " joblevel - the level the player has attained in the job.", " NOTE: Please take care of the brackets when modifying this equation."); cfg.get(pt + ".leveling-progression-equation", "10*(joblevel)+(joblevel*joblevel*4)"); @@ -127,6 +128,7 @@ public class ConfigManager { cfg.addComment(pt + ".income-progression-equation", "Equation used for calculating how much income is given per action for the job level.", "Available parameters:", " numjobs - the number of jobs the player has", + " maxjobs - the number of jobs the player have max", " baseincome - the income for the action at level 1 (as set in the configuration).", " joblevel - the level the player has attained in the job.", "NOTE: Please take care of the brackets when modifying this equation."); @@ -135,6 +137,7 @@ public class ConfigManager { cfg.addComment(pt + ".points-progression-equation", "Equation used for calculating how much points is given per action for the job level.", "Available parameters:", " numjobs - the number of jobs the player has", + " maxjobs - the number of jobs the player have max", " basepoints - the points for the action at level 1 (as set in the configuration).", " joblevel - the level the player has attained in the job.", "NOTE: Please take care of the brackets when modifying this equation."); @@ -143,6 +146,7 @@ public class ConfigManager { cfg.addComment(pt + ".experience-progression-equation", "Equation used for calculating how much experience is given per action for the job level.", "Available parameters:", " numjobs - the number of jobs the player has", + " maxjobs - the number of jobs the player have max", " baseexperience - the experience for the action at level 1 (as set in the configuration).", " joblevel - the level the player has attained in the job.", "NOTE: Please take care of the brackets when modifying this equation."); @@ -785,7 +789,6 @@ public class ConfigManager { maxExpEquation.setVariable("numjobs", 1); maxExpEquation.setVariable("maxjobs", 2); maxExpEquation.setVariable("joblevel", 1); - maxExpEquation.getValue(); } catch (Throwable e) { log.warning("Job " + jobKey + " has an invalid leveling-progression-equation property. Skipping job!"); continue; @@ -801,7 +804,6 @@ public class ConfigManager { incomeEquation.setVariable("maxjobs", 2); incomeEquation.setVariable("joblevel", 1); incomeEquation.setVariable("baseincome", 1); - incomeEquation.getValue(); } catch (Throwable e) { log.warning("Job " + jobKey + " has an invalid income-progression-equation property. Skipping job!"); continue; @@ -817,7 +819,6 @@ public class ConfigManager { expEquation.setVariable("maxjobs", 2); expEquation.setVariable("joblevel", 1); expEquation.setVariable("baseexperience", 1); - expEquation.getValue(); } catch (Throwable e) { log.warning("Job " + jobKey + " has an invalid experience-progression-equation property. Skipping job!"); continue; @@ -833,7 +834,6 @@ public class ConfigManager { pointsEquation.setVariable("maxjobs", 2); pointsEquation.setVariable("joblevel", 1); pointsEquation.setVariable("basepoints", 1); - pointsEquation.getValue(); } catch (Throwable e) { log.warning("Job " + jobKey + " has an invalid points-progression-equation property. Skipping job!"); continue; diff --git a/src/main/java/com/gamingmesh/jobs/container/JobInfo.java b/src/main/java/com/gamingmesh/jobs/container/JobInfo.java index 39a868fe..031704f7 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobInfo.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobInfo.java @@ -110,35 +110,38 @@ public class JobInfo { return basePoints; } - public double getIncome(double level, double numjobs) { + public double getIncome(double level, int numjobs, int maxJobs) { if (softIncomeLevelLimit != null && level > softIncomeLevelLimit) level = softIncomeLevelLimit; if (baseIncome == 0 || !Jobs.getGCManager().PaymentMethodsMoney) return 0; moneyEquation.setVariable("joblevel", level); moneyEquation.setVariable("numjobs", numjobs); + moneyEquation.setVariable("maxjobs", maxJobs); moneyEquation.setVariable("baseincome", baseIncome); return moneyEquation.getValue(); } - public double getExperience(double level, double numjobs) { + public double getExperience(double level, int numjobs, int maxJobs) { if (softExpLevelLimit != null && level > softExpLevelLimit) level = softExpLevelLimit; if (baseXp == 0 || !Jobs.getGCManager().PaymentMethodsExp) return 0; xpEquation.setVariable("joblevel", level); xpEquation.setVariable("numjobs", numjobs); + xpEquation.setVariable("maxjobs", maxJobs); xpEquation.setVariable("baseexperience", baseXp); return xpEquation.getValue(); } - public double getPoints(double level, double numjobs) { + public double getPoints(double level, int numjobs, int maxJobs) { if (softPointsLevelLimit != null && level > softPointsLevelLimit) level = softPointsLevelLimit; if (basePoints == 0 || !Jobs.getGCManager().PaymentMethodsPoints) return 0; pointsEquation.setVariable("joblevel", level); pointsEquation.setVariable("numjobs", numjobs); + pointsEquation.setVariable("maxjobs", maxJobs); pointsEquation.setVariable("basepoints", basePoints); return pointsEquation.getValue(); } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index aee4f7d4..62b33596 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -43,13 +43,17 @@ import com.gamingmesh.jobs.resources.jfep.Parser; import com.gamingmesh.jobs.stuff.TimeManage; public class JobsPlayer { - // the player the object belongs to - private String userName = "Unknown"; - // progression of the player in each job - public UUID playerUUID; - public final ArrayList progression = new ArrayList<>(); - private ArchivedJobs archivedJobs = new ArchivedJobs(); + private String userName = "Unknown"; + + public UUID playerUUID; + + // progression of the player in each job + public final ArrayList progression = new ArrayList<>(); + + public int maxJobsEquation = 0; + + private ArchivedJobs archivedJobs = new ArchivedJobs(); private PaymentData paymentLimits; private final HashMap> boostCounter = new HashMap<>(); @@ -70,7 +74,6 @@ public class JobsPlayer { // save lock // public final Object saveLock = new Object(); - // log private HashMap logList = new HashMap<>(); private Long seen = System.currentTimeMillis(); @@ -839,8 +842,8 @@ public class JobsPlayer { JobInfo jobinfo = Jobs.getNoneJob().getJobInfo(info, 1); if (jobinfo == null) return false; - Double income = jobinfo.getIncome(1, numjobs); - Double points = jobinfo.getPoints(1, numjobs); + Double income = jobinfo.getIncome(1, numjobs, maxJobsEquation); + Double points = jobinfo.getPoints(1, numjobs, maxJobsEquation); if (income == 0D && points == 0D) return false; } @@ -850,9 +853,9 @@ public class JobsPlayer { JobInfo jobinfo = prog.getJob().getJobInfo(info, level); if (jobinfo == null) continue; - Double income = jobinfo.getIncome(level, numjobs); - Double pointAmount = jobinfo.getPoints(level, numjobs); - Double expAmount = jobinfo.getExperience(level, numjobs); + Double income = jobinfo.getIncome(level, numjobs, maxJobsEquation); + Double pointAmount = jobinfo.getPoints(level, numjobs, maxJobsEquation); + Double expAmount = jobinfo.getExperience(level, numjobs, maxJobsEquation); if (income != 0D || pointAmount != 0D || expAmount != 0D) return true; } diff --git a/src/main/resources/jobConfig.yml b/src/main/resources/jobConfig.yml index ebc1d4c0..f6fcfb3d 100644 --- a/src/main/resources/jobConfig.yml +++ b/src/main/resources/jobConfig.yml @@ -53,12 +53,14 @@ Jobs: # Equation used for calculating how much experience is needed to go to the next level. # Available parameters: # numjobs - the number of jobs the player has + # maxjobs - the number of jobs the player have max # joblevel - the level the player has attained in the job. # NOTE: Please take care of the brackets when modifying this equation. leveling-progression-equation: 10*(joblevel)+(joblevel*joblevel*4) # Equation used for calculating how much income is given per action for the job level. # Available parameters: # numjobs - the number of jobs the player has + # maxjobs - the number of jobs the player have max # baseincome - the income for the action at level 1 (as set in the configuration). # joblevel - the level the player has attained in the job. # NOTE: Please take care of the brackets when modifying this equation. @@ -66,6 +68,7 @@ Jobs: # Equation used for calculating how much points is given per action for the job level. # Available parameters: # numjobs - the number of jobs the player has + # maxjobs - the number of jobs the player have max # basepoints - the points for the action at level 1 (as set in the configuration). # joblevel - the level the player has attained in the job. # NOTE: Please take care of the brackets when modifying this equation. @@ -73,6 +76,7 @@ Jobs: # Equation used for calculating how much experience is given per action for the job level. # Available parameters: # numjobs - the number of jobs the player has + # maxjobs - the number of jobs the player have max # baseexperience - the experience for the action at level 1 (as set in the configuration). # joblevel - the level the player has attained in the job. # NOTE: Please take care of the brackets when modifying this equation. @@ -350,7 +354,7 @@ Jobs: income: 5.0 experience: 10.0 # Shear sheeps by its color - # You can use "color-all" to specify all known colors. + # You can use "color-all" identifier to specify all known colors. Shear: Black: income: 2.0