aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/main/java/com/leonardobishop
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java/com/leonardobishop')
-rw-r--r--common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgress.java10
-rw-r--r--common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java37
2 files changed, 42 insertions, 5 deletions
diff --git a/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgress.java b/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgress.java
index d0e0627d..06d8a91d 100644
--- a/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgress.java
+++ b/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgress.java
@@ -130,6 +130,16 @@ public class QuestProgress {
}
}
+ public boolean hasNonDefaultValues() {
+ if (this.started || this.completed || this.completedBefore || this.completionDate != 0) return true;
+ else {
+ for (TaskProgress progress : this.taskProgress.values()) {
+ if (progress.getProgress() != null || progress.isCompleted()) return true;
+ }
+ return false;
+ }
+ }
+
public void queueForCompletionTest() {
plugin.getQuestCompleter().queueSingular(this);
}
diff --git a/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java b/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java
index 4a740ee3..40d80509 100644
--- a/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java
+++ b/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java
@@ -168,7 +168,7 @@ public class QuestProgressFile {
}
/**
- * Get the {@link UUID} of the player this QuestProgressFile represents
+ * Get the {@link UUID} of the player this QuestProgressFile represents.
*
* @return UUID
*/
@@ -177,7 +177,7 @@ public class QuestProgressFile {
}
/**
- * Get the {@link QuestProgress} for a specified {@link Quest}, and generates a new one if it does not exist
+ * Get the {@link QuestProgress} for a specified {@link Quest}, and generates a new one if it does not exist.
*
* @param quest the quest to get progress for
* @return {@link QuestProgress} or null if the quest does not exist
@@ -192,14 +192,23 @@ public class QuestProgressFile {
/**
* Generate a new blank {@link QuestProgress} for a specified {@code quest}.
- * Has no effect if there is already an existing {@link QuestProgress} for {@code quest}.
*
* @param quest the quest to generate progress for
*/
public void generateBlankQuestProgress(Quest quest) {
- QuestProgress questProgress = new QuestProgress(plugin, quest.getId(), false, false, 0, playerUUID, false, false);
+ generateBlankQuestProgress(quest, false);
+ }
+
+ /**
+ * Generate a new blank {@link QuestProgress} for a specified {@code quest}.
+ *
+ * @param quest the quest to generate progress for
+ * @param modified the modified state of the quest
+ */
+ public void generateBlankQuestProgress(Quest quest, boolean modified) {
+ QuestProgress questProgress = new QuestProgress(plugin, quest.getId(), false, false, 0, playerUUID, false, modified);
for (Task task : quest.getTasks()) {
- TaskProgress taskProgress = new TaskProgress(questProgress, task.getId(), null, playerUUID, false, false);
+ TaskProgress taskProgress = new TaskProgress(questProgress, task.getId(), null, playerUUID, false, modified);
questProgress.addTaskProgress(taskProgress);
}
@@ -211,6 +220,24 @@ public class QuestProgressFile {
}
/**
+ * Reset quests to their default state. More specifically, this will reset all
+ * quest progress with non-default parameters back to default and only
+ * set the modified flag in that case.
+ */
+ public void reset() {
+ for (QuestProgress questProgress : questProgress.values()) {
+ if (!questProgress.hasNonDefaultValues()) {
+ continue;
+ }
+ Quest quest = plugin.getQuestManager().getQuestById(questProgress.getQuestId());
+ if (quest == null) {
+ continue;
+ }
+ generateBlankQuestProgress(quest, true);
+ }
+ }
+
+ /**
* Removes any references to quests or tasks which are no longer defined in the config.
*/
@Deprecated