From e24dba84a6dcc8a33c96971a6de7678c774e8229 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Mon, 16 Nov 2020 21:57:09 +0100 Subject: [PATCH] Add permission based max quests Closes #964 Closes #809 --- .../com/gamingmesh/jobs/PermissionManager.java | 2 +- .../gamingmesh/jobs/config/ConfigManager.java | 3 +-- .../gamingmesh/jobs/container/JobsPlayer.java | 16 ++++++++++++++++ .../com/gamingmesh/jobs/container/Quest.java | 9 ++++----- .../jobs/container/QuestProgression.java | 7 +++++++ 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/PermissionManager.java b/src/main/java/com/gamingmesh/jobs/PermissionManager.java index e7f9a523..05f3c1d4 100644 --- a/src/main/java/com/gamingmesh/jobs/PermissionManager.java +++ b/src/main/java/com/gamingmesh/jobs/PermissionManager.java @@ -156,7 +156,7 @@ public class PermissionManager { else if (amount == 0D || allowMinus || temp > amount) amount = temp; } catch (NumberFormatException ignored) { - ignored.printStackTrace(); + // Should be ignored } } diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index de6380f3..aaff748f 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -1169,8 +1169,7 @@ public class ConfigManager { desc = sqsection.getStringList("RewardDesc"), areas = sqsection.getStringList("RestrictedAreas"); - if (sqsection.isInt("fromLevel")) - quest.setMinLvl(sqsection.getInt("fromLevel")); + quest.setMinLvl(sqsection.getInt("fromLevel")); if (sqsection.isInt("toLevel")) quest.setMaxLvl(sqsection.getInt("toLevel")); diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 62b33596..7e404c97 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -304,6 +304,22 @@ public class JobsPlayer { return Boost; } + public int getPlayerMaxQuest(String jobName) { + int m1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest." + jobName, false, true, false).intValue(); + int max = m1; + + m1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest.all", false, true, false).intValue(); + if (m1 != 0 && (m1 > max || m1 < max)) { + max = m1; + } + + m1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest", false, true, false).intValue(); + if (m1 != 0 && (m1 > max || m1 < max)) { + max = m1; + } + + return max; + } /** * Reloads max experience for this job. diff --git a/src/main/java/com/gamingmesh/jobs/container/Quest.java b/src/main/java/com/gamingmesh/jobs/container/Quest.java index 8a750bd4..c6427008 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Quest.java +++ b/src/main/java/com/gamingmesh/jobs/container/Quest.java @@ -16,8 +16,7 @@ public class Quest { private Job job; private Long validUntil = 0L; - private int chance = 100; - private Integer minLvl = null; + private int chance = 100, minLvl = 0; private Integer maxLvl = null; private final List rewardCmds = new ArrayList<>(), rewards = new ArrayList<>(), area = new ArrayList<>(); @@ -126,7 +125,7 @@ public class Quest { this.configName = configName; } - public Integer getMinLvl() { + public int getMinLvl() { return minLvl; } @@ -146,10 +145,10 @@ public class Quest { if (level == null) return true; - if (getMinLvl() != null && level < getMinLvl()) + if (level < minLvl) return false; - if (getMaxLvl() != null && level > getMaxLvl()) + if (maxLvl != null && level > maxLvl) return false; return true; diff --git a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java index c269dee4..42d8daf8 100644 --- a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java +++ b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java @@ -104,6 +104,13 @@ public class QuestProgression { } } + if (quest.getJob() != null) { + int maxQuest = jPlayer.getPlayerMaxQuest(quest.getJob().getName()); + if (maxQuest > 0 && jPlayer.getDoneQuests() >= maxQuest) { + return; + } + } + if (!isCompleted()) { HashMap byAction = quest.getObjectives().get(action.getType());