diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 84995303..363018e3 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -167,6 +167,8 @@ public final class Jobs extends JavaPlugin { private static boolean hasLimitedItems = false; + public static boolean fullyLoaded = false; + private static final int MAX_ENTRIES = 20; public static final LinkedHashMap FASTPAYMENT = new LinkedHashMap(MAX_ENTRIES + 1, .75F, false) { protected boolean removeEldestEntry(Map.Entry eldest) { @@ -779,7 +781,7 @@ public final class Jobs extends JavaPlugin { System.out.println("There was some issues when starting plugin. Please contact dev about this. Plugin will be disabled."); setEnabled(false); } - + fullyLoaded = true; CMIMessages.consoleMessage(suffix); } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java index 871e882a..fc96e935 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java @@ -84,6 +84,7 @@ public class quests implements Cmd { List list = jPlayer.getQuestProgressions(jobProg.getJob()); for (QuestProgression q : list) { + int totalAmountNeeded = q.getTotalAmountNeeded(); int totalAmountDone = q.getTotalAmountDone(); diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index 744b03a1..26b8b15f 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -1453,17 +1453,22 @@ public class ConfigManager { Quest quest = new Quest(sqsection.getString("Name", one), job); ActionType actionType = ActionType.getByName(sqsection.getString("Action")); + quest.setConfigName(one); + if (actionType != null) { KeyValues kv = getKeyValue(sqsection.getString("Target").toUpperCase(), actionType, jobFullName); - if (kv != null) { int amount = sqsection.getInt("Amount", 1); - quest.addObjective(new QuestObjective(actionType, kv.getId(), kv.getMeta(), (kv.getType() + kv.getSubType()).toUpperCase(), amount)); + QuestObjective newObjective = new QuestObjective(actionType, kv.getId(), kv.getMeta(), (kv.getType() + kv.getSubType()).toUpperCase(), amount); + quest.addObjective(newObjective); } } for (String oneObjective : sqsection.getStringList("Objectives")) { List objectives = QuestObjective.get(oneObjective, jobFullName); + + + quest.addObjectives(objectives); } @@ -1472,7 +1477,6 @@ public class ConfigManager { if (sqsection.isInt("toLevel")) quest.setMaxLvl(sqsection.getInt("toLevel")); - quest.setConfigName(one); quest.setChance(sqsection.getInt("Chance", 100)); quest.setRewardCmds(sqsection.getStringList("RewardCommands")); quest.setDescription(sqsection.getStringList("RewardDesc")); diff --git a/src/main/java/com/gamingmesh/jobs/container/Quest.java b/src/main/java/com/gamingmesh/jobs/container/Quest.java index 7e339d97..3a137b7c 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Quest.java +++ b/src/main/java/com/gamingmesh/jobs/container/Quest.java @@ -10,18 +10,21 @@ import java.util.Set; import com.gamingmesh.jobs.Jobs; +import net.Zrips.CMILib.Logs.CMIDebug; + public class Quest { private String configName = ""; private String questName = ""; private Job job; private long validUntil = 0L; + private int objectiveCount = 0; private int chance = 100, minLvl = 0; private Integer maxLvl; private boolean enabled = false; - + private final List rewardCmds = new ArrayList<>(), rewards = new ArrayList<>(), area = new ArrayList<>(); private boolean stopped = false; @@ -191,6 +194,7 @@ public class Quest { return false; } + @Deprecated public void setObjectives(Map> objectives) { if (objectives == null) { return; @@ -206,7 +210,42 @@ public class Quest { } } + // Grabs existing job-quest-objective in case this is reload and we can reuse same objective object to avoid issue + private QuestObjective reuseOldObjectiveObject(QuestObjective objective) { + if (!Jobs.fullyLoaded) + return objective; + + Job oldJob = Jobs.getJob(job.getName()); + + if (oldJob == null) + return objective; + + Quest oldQuest = oldJob.getQuest(this.getConfigName()); + + if (oldQuest == null) + return objective; + + Map oldObjectives = oldQuest.getObjectives().get(objective.getAction()); + + if (oldObjectives == null) + return objective; + + QuestObjective oldObjective = oldObjectives.get(objective.getTargetName()); + + if (oldObjective == null) + return oldObjective; + + if (oldObjective.getIdentifier().equals(objective.getIdentifier())) { + return oldObjective; + } + + return objective; + } + public void addObjective(QuestObjective objective) { + + objective = reuseOldObjectiveObject(objective); + Map old = objectives.get(objective.getAction()); if (old == null) { old = new HashMap<>(); @@ -227,4 +266,18 @@ public class Quest { public void setEnabled(boolean enabled) { this.enabled = enabled; } + + private void count() { + for (ActionType one : actions) { + Map old = objectives.get(one); + if (old != null) + objectiveCount += old.size(); + } + } + + public int getObjectiveCount() { + if (objectiveCount < 1) + count(); + return objectiveCount; + } } diff --git a/src/main/java/com/gamingmesh/jobs/container/QuestObjective.java b/src/main/java/com/gamingmesh/jobs/container/QuestObjective.java index e1d7aba7..98b04701 100644 --- a/src/main/java/com/gamingmesh/jobs/container/QuestObjective.java +++ b/src/main/java/com/gamingmesh/jobs/container/QuestObjective.java @@ -16,6 +16,8 @@ public class QuestObjective { private int amount = Integer.MAX_VALUE; private ActionType action = null; + private String serializedLine = ""; + public static List get(String objective, String jobName) { String[] split = objective.split(";", 3); @@ -115,4 +117,12 @@ public class QuestObjective { public boolean same(QuestObjective obj) { return obj.id == this.id && obj.meta.equals(this.meta) && obj.name.equals(this.name) && obj.amount == this.amount && obj.action == this.action; } + + public String getIdentifier() { + if (serializedLine.isEmpty()) { + serializedLine = getAction().toString() + ";" + getTargetName() + ";" + getAmount(); + } + + return serializedLine; + } } diff --git a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java index 687bb535..dda6e201 100644 --- a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java +++ b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java @@ -56,6 +56,7 @@ public class QuestProgression { public int getTotalAmountDone() { int amountDone = 0; + for (Integer one : done.values()) { amountDone += one; }