diff options
| author | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2022-04-18 15:18:17 +0100 |
|---|---|---|
| committer | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2022-04-18 15:18:17 +0100 |
| commit | a51b0c6ac010b7395b75e31ff9833b43c468acde (patch) | |
| tree | 34ee703ef25b61be1b3217ced17db3a6ca969c2d /common/src | |
| parent | 13ec48e7b45b4e3c253ac8504e0402b4ab0a147c (diff) | |
Fix reset and fullreset commands (closes #351)
Diffstat (limited to 'common/src')
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 |
