aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorLMBishop <13875753+LMBishop@users.noreply.github.com>2019-12-29 18:50:10 +0000
committerLMBishop <13875753+LMBishop@users.noreply.github.com>2019-12-29 18:50:10 +0000
commitc01d401821735064b7678c5962f67c46a9129edb (patch)
tree8eac84a85cc3d60e04cd0b3ef154eaf6e6843de8 /src/main
parent3759ed526265a3785d7121db41339c4f04699690 (diff)
Fixed quest progress not saving
- Closes #56 - TaskProgress now has a new field 'modified' as the QuestProgress 'modified' field is initialised false when generated using the generate blank function. - 'modified' should be set to true in QuestProgress when it is manually started, but the auto start option bypasses this altogether which results in the plugin not saving QuestProgress as it is considered unmodified even if progress has been made. - 'modified' fields in TaskProgress should fix this issue.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/leonardobishop/quests/player/QPlayerManager.java2
-rw-r--r--src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgress.java17
-rw-r--r--src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java11
-rw-r--r--src/main/java/com/leonardobishop/quests/player/questprogressfile/TaskProgress.java16
4 files changed, 40 insertions, 6 deletions
diff --git a/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java b/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java
index 8230f412..27790f76 100644
--- a/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java
+++ b/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java
@@ -62,7 +62,7 @@ public class QPlayerManager {
boolean taskCompleted = data.getBoolean("quest-progress." + id + ".task-progress." + taskid + ".completed");
Object taskProgression = data.get("quest-progress." + id + ".task-progress." + taskid + ".progress");
- TaskProgress taskProgress = new TaskProgress(taskid, taskProgression, uuid, taskCompleted);
+ TaskProgress taskProgress = new TaskProgress(taskid, taskProgression, uuid, taskCompleted, false);
questProgress.addTaskProgress(taskProgress);
}
diff --git a/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgress.java b/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgress.java
index 26326269..fe9108ce 100644
--- a/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgress.java
+++ b/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgress.java
@@ -92,15 +92,24 @@ public class QuestProgress {
}
public void repairTaskProgress(String taskid) {
- TaskProgress taskProgress = new TaskProgress(taskid, null, player, false);
+ TaskProgress taskProgress = new TaskProgress(taskid, null, player, false, false);
this.addTaskProgress(taskProgress);
}
public boolean isWorthSaving() {
- return modified;
+ if (modified) return true;
+ else {
+ for (TaskProgress progress : this.taskProgress.values()) {
+ if (progress.isModified()) return true;
+ }
+ return false;
+ }
}
- public void setWorthSaving(boolean modified) {
- this.modified = modified;
+ public void resetModified() {
+ this.modified = false;
+ for (TaskProgress progress : this.taskProgress.values()) {
+ progress.setModified(false);
+ }
}
}
diff --git a/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java b/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java
index 42251f27..21e5c61b 100644
--- a/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java
+++ b/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java
@@ -9,6 +9,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitRunnable;
import java.io.File;
import java.io.IOException;
@@ -265,7 +266,7 @@ public class QuestProgressFile {
Quest quest = plugin.getQuestManager().getQuestById(questid);
QuestProgress questProgress = new QuestProgress(quest.getId(), false, false, 0, player, false, false);
for (Task task : quest.getTasks()) {
- TaskProgress taskProgress = new TaskProgress(task.getId(), null, player, false);
+ TaskProgress taskProgress = new TaskProgress(task.getId(), null, player, false, false);
questProgress.addTaskProgress(taskProgress);
}
@@ -309,6 +310,14 @@ public class QuestProgressFile {
try {
data.save(file);
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ for (QuestProgress questProgress : questProgress.values()) {
+ questProgress.resetModified();
+ }
+ }
+ }.runTask(plugin);
} catch (IOException e) {
e.printStackTrace();
}
diff --git a/src/main/java/com/leonardobishop/quests/player/questprogressfile/TaskProgress.java b/src/main/java/com/leonardobishop/quests/player/questprogressfile/TaskProgress.java
index d85c8599..a4c71460 100644
--- a/src/main/java/com/leonardobishop/quests/player/questprogressfile/TaskProgress.java
+++ b/src/main/java/com/leonardobishop/quests/player/questprogressfile/TaskProgress.java
@@ -4,6 +4,7 @@ import java.util.UUID;
public class TaskProgress {
+ private boolean modified;
private String taskid;
private Object progress;
private UUID player;
@@ -15,6 +16,11 @@ public class TaskProgress {
this.completed = completed;
}
+ public TaskProgress(String taskid, Object progress, UUID player, boolean completed, boolean modified) {
+ this(taskid, progress, player, completed);
+ this.modified = modified;
+ }
+
public String getTaskId() {
return taskid;
}
@@ -25,6 +31,7 @@ public class TaskProgress {
public void setProgress(Object progress) {
this.progress = progress;
+ this.modified = true;
}
public UUID getPlayer() {
@@ -37,5 +44,14 @@ public class TaskProgress {
public void setCompleted(boolean complete) {
this.completed = complete;
+ this.modified = true;
+ }
+
+ public boolean isModified() {
+ return modified;
+ }
+
+ public void setModified(boolean modified) {
+ this.modified = modified;
}
}