aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com')
-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;
}
}