package me.fatpigsarefat.quests.player.questprogressfile;

import java.util.*;

public class QuestProgress {

    private Map<String, TaskProgress> taskProgress = new HashMap<>();
    private String questid;
    private boolean started;
    private boolean completed;
    private boolean completedBefore;
    private long completionDate;
    private UUID player;
    private boolean modified;

    public QuestProgress(String questid, boolean completed, boolean completedBefore, long completionDate, UUID player, boolean started) {
        this.questid = questid;
        this.completed = completed;
        this.completedBefore = completedBefore;
        this.completionDate = completionDate;
        this.player = player;
        this.started = started;
    }

    public QuestProgress(String questid, boolean completed, boolean completedBefore, long completionDate, UUID player, boolean started, boolean modified) {
        this(questid, completed, completedBefore, completionDate, player, started);
        this.modified = modified;
    }

    public String getQuestId() {
        return questid;
    }

    public boolean isCompleted() {
        return completed;
    }

    public void setStarted(boolean started) {
        this.started = started;
        this.modified = true;
    }

    public boolean isStarted() {
        return started;
    }

    public void setCompleted(boolean completed) {
        this.completed = completed;
        this.modified = true;
    }

    public long getCompletionDate() {
        return completionDate;
    }

    public void setCompletionDate(long completionDate) {
        this.completionDate = completionDate;
        this.modified = true;
    }

    public UUID getPlayer() {
        return player;
    }

    public boolean isCompletedBefore() {
        return completedBefore;
    }

    public void setCompletedBefore(boolean completedBefore) {
        this.completedBefore = completedBefore;
        this.modified = true;
    }

    public void addTaskProgress(TaskProgress taskProgress) {
        this.taskProgress.put(taskProgress.getTaskId(), taskProgress);
    }

    public Collection<TaskProgress> getTaskProgress() {
        return taskProgress.values();
    }

    public TaskProgress getTaskProgress(String taskId) {
        return taskProgress.getOrDefault(taskId, null);
    }

    public boolean isWorthSaving() {
        return modified;
    }

    public void setWorthSaving(boolean modified) {
        this.modified = modified;
    }
}

@@ -73,9 +73,89 @@
 til.
-*
+Collection;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.UUID
 ;%0A%0Ap
@@ -1268,20 +1268,22 @@
 void set
-Star
+Comple
 ted(bool
@@ -1278,36 +1278,38 @@
 mpleted(boolean 
-star
+comple
 ted) %7B%0A        t
@@ -1308,38 +1308,42 @@
        this.
-started = star
+completed = comple
 ted;%0A       
@@ -1447,38 +1447,36 @@
  public void set
-Comple
+Star
 ted(boolean comp
@@ -1463,38 +1463,36 @@
 Started(boolean 
-comple
+star
 ted) %7B%0A        t
@@ -1495,34 +1495,30 @@
    this.
-completed = comple
+started = star
 ted;%0A   
@@ -2363,53 +2363,403 @@
     
-return taskProgress.getOrDefault(taskId, null
+TaskProgress tP = taskProgress.getOrDefault(taskId, null);%0A        if (tP == null) %7B%0A            repairTaskProgress(taskId);%0A            tP = taskProgress.getOrDefault(taskId, null);%0A        %7D%0A        return tP;%0A    %7D%0A%0A    public void repairTaskProgress(String taskid) %7B%0A        TaskProgress taskProgress = new TaskProgress(taskid, null, player, false);%0A        this.addTaskProgress(taskProgress
 );%0A 

Fix for NullPointerException when a task is added after the quest has already been initialized before.