From 7ba5a2bd86ef8487b682f3dfc514f762198aa36c Mon Sep 17 00:00:00 2001 From: Zrips Date: Tue, 29 Aug 2023 12:59:05 +0300 Subject: [PATCH] To disable max job limit now it needs to be set to -1 and not 0 --- src/main/java/com/gamingmesh/jobs/Jobs.java | 2 +- .../jobs/Placeholders/Placeholder.java | 3 ++- .../com/gamingmesh/jobs/PlayerManager.java | 23 ++++++++++--------- .../gamingmesh/jobs/config/ConfigManager.java | 2 ++ .../jobs/config/GeneralConfigManager.java | 5 ++-- .../gamingmesh/jobs/container/JobsPlayer.java | 3 ++- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index e9971e3f..21f7df0b 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -154,7 +154,7 @@ public final class Jobs extends JavaPlugin { private GuiManager guiManager; private static JobsDAO dao; - private static List jobs; + private static List jobs = new ArrayList(); private static Job noneJob; private static Map usedSlots = new WeakHashMap<>(); diff --git a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java index e3af33ad..2b67b2c8 100644 --- a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java +++ b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java @@ -582,7 +582,8 @@ public class Placeholder { return convert(true); case maxjobs: - return Integer.toString(Jobs.getPlayerManager().getMaxJobs(user)); + int max = Jobs.getPlayerManager().getMaxJobs(user); + return Integer.toString(max == -1 ? 99 : max); default: break; diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index 224963d1..15ef2a66 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -63,9 +63,9 @@ import com.gamingmesh.jobs.hooks.HookManager; import com.gamingmesh.jobs.stuff.Util; import net.Zrips.CMILib.ActionBar.CMIActionBar; +import net.Zrips.CMILib.Container.CMINumber; import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIMaterial; -import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.NBT.CMINBT; import net.Zrips.CMILib.Version.Version; @@ -488,10 +488,10 @@ public class PlayerManager { Jobs.getSignUtil().updateAllSign(job); job.updateTotalPlayers(); - jPlayer.maxJobsEquation = getMaxJobs(jPlayer); - + jPlayer.maxJobsEquation = CMINumber.clamp(getMaxJobs(jPlayer), 0, 9999); + // Removing from cached item boost for recalculation - cache.remove(jPlayer.getUniqueId()); + cache.remove(jPlayer.getUniqueId()); } private static void performCommandsOnLeave(JobsPlayer jPlayer, Job job) { @@ -533,10 +533,10 @@ public class PlayerManager { Jobs.getSignUtil().updateAllSign(job); job.updateTotalPlayers(); - + // Removing from cached item boost for recalculation - cache.remove(jPlayer.getUniqueId()); - + cache.remove(jPlayer.getUniqueId()); + return true; } @@ -931,7 +931,8 @@ public class PlayerManager { * @return true if the player is under the given jobs size */ public boolean getJobsLimit(JobsPlayer jPlayer, short currentCount) { - return getMaxJobs(jPlayer) > currentCount; + int max = getMaxJobs(jPlayer); + return max == -1 ? true : max > currentCount; } /** @@ -1064,7 +1065,7 @@ public class PlayerManager { continue; } } - + jitems.add(getJobsItemByNbt(item)); } } @@ -1214,11 +1215,11 @@ public class PlayerManager { int playerMaxJobs = getMaxJobs(jPlayer); int playerCurrentJobs = jPlayer.progression.size(); - if (playerMaxJobs <= 0 || playerCurrentJobs >= playerMaxJobs) + if (playerMaxJobs == 0 || playerMaxJobs != -1 && playerCurrentJobs >= playerMaxJobs) return; for (Job one : Jobs.getJobs()) { - if (jPlayer.progression.size() >= playerMaxJobs) + if (playerMaxJobs != -1 && jPlayer.progression.size() >= playerMaxJobs) return; if (one.getMaxSlots() != null && Jobs.getUsedSlots(one) >= one.getMaxSlots()) diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index 0821b358..212d6377 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -1571,6 +1571,8 @@ public class ConfigManager { return job; } } + + return null; } diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index a4a98967..411d6cbe 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -45,6 +45,7 @@ import net.Zrips.CMILib.Equations.Parser; import net.Zrips.CMILib.FileHandler.ConfigReader; import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIMaterial; +import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Version.Version; @@ -442,9 +443,9 @@ public class GeneralConfigManager { "For this to work, the player needs to get a new job for the timer to start.", "Counting in hours"); jobExpiryTime = c.get("JobExpirationTime", 0); - c.addComment("max-jobs", "Maximum number of jobs a player can join.", "Use 0 for no maximum", "Keep in mind that jobs.max.[amount] will bypass this setting"); + c.addComment("max-jobs", "Maximum number of jobs a player can join.", "Use -1 to disable limitations", "Keep in mind that jobs.max.[amount] will bypass this setting"); maxJobs = c.get("max-jobs", 3); - + c.addComment("disable-payment-if-max-level-reached", "Disabling the payment if the user reached the maximum level of a job."); disablePaymentIfMaxLevelReached = c.get("disable-payment-if-max-level-reached", false); diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 0a51170f..520bef13 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -43,6 +43,7 @@ import com.gamingmesh.jobs.economy.PaymentData; import net.Zrips.CMILib.ActionBar.CMIActionBar; import net.Zrips.CMILib.Colors.CMIChatColor; +import net.Zrips.CMILib.Container.CMINumber; import net.Zrips.CMILib.Equations.Parser; import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Logs.CMIDebug; @@ -442,7 +443,7 @@ public class JobsPlayer { Parser eq = Jobs.getGCManager().getLimit(type).getMaxEquation(); eq.setVariable("totallevel", getTotalLevels()); - maxJobsEquation = Jobs.getPlayerManager().getMaxJobs(this); + maxJobsEquation = CMINumber.clamp(Jobs.getPlayerManager().getMaxJobs(this), 0, 9999); limits.put(type, (int) eq.getValue()); setSaved(false); }