From fa02426dd569239d3334c02faf05db46d9841bb1 Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Sun, 12 Apr 2020 20:53:34 -0400 Subject: [PATCH] Null and index checks for #1191 --- .../java/me/blackvein/quests/Quester.java | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index 2b94bfd32..b7a936c3d 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -345,10 +345,9 @@ public class Quester { public QuestData getQuestData(Quest quest) { if (questData.containsKey(quest)) { return questData.get(quest); - } else if (quest != null) { - plugin.getLogger().severe("Unable to fetch data for quest " + quest.getId()); } - return null; + plugin.getLogger().info("Creating new data for quest " + quest.getId()); + return new QuestData(this); } public void updateJournal() { @@ -1114,18 +1113,21 @@ public class Quester { for (Location l : getCurrentStage(quest).locationsToReach) { for (Location l2 : getQuestData(quest).locationsReached) { if (l.equals(l2)) { - if (!getQuestData(quest).hasReached.isEmpty()) { - if (getQuestData(quest).hasReached.get(getQuestData(quest).locationsReached.indexOf(l2)) - == false) { - String obj = Lang.get(getPlayer(), "goTo"); - obj = obj.replace("", getCurrentStage(quest).locationNames - .get(getCurrentStage(quest).locationsToReach.indexOf(l))); - unfinishedObjectives.add(ChatColor.GREEN + obj); - } else { - String obj = Lang.get(getPlayer(), "goTo"); - obj = obj.replace("", getCurrentStage(quest).locationNames - .get(getCurrentStage(quest).locationsToReach.indexOf(l))); - finishedObjectives.add(ChatColor.GRAY + obj); + if (getQuestData(quest) != null && getQuestData(quest).hasReached != null) { + if (!getQuestData(quest).hasReached.isEmpty()) { + int r = getQuestData(quest).locationsReached.indexOf(l2); + if (r < getQuestData(quest).hasReached.size() + && getQuestData(quest).hasReached.get(r) == false) { + String obj = Lang.get(getPlayer(), "goTo"); + obj = obj.replace("", getCurrentStage(quest).locationNames + .get(getCurrentStage(quest).locationsToReach.indexOf(l))); + unfinishedObjectives.add(ChatColor.GREEN + obj); + } else { + String obj = Lang.get(getPlayer(), "goTo"); + obj = obj.replace("", getCurrentStage(quest).locationNames + .get(getCurrentStage(quest).locationsToReach.indexOf(l))); + finishedObjectives.add(ChatColor.GRAY + obj); + } } } } @@ -2046,10 +2048,7 @@ public class Quester { * @param l The location being reached */ public void reachLocation(Quest quest, Location l) { - if (getQuestData(quest).locationsReached == null) { - return; - } - if (getQuestData(quest).locationsReached.isEmpty()) { + if (getQuestData(quest) == null || getQuestData(quest).locationsReached == null) { return; } int index = 0;