From cd85a929d0d0e30b172af9339be32aceeccddb40 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Mon, 8 Jul 2019 09:36:28 +0300 Subject: [PATCH] Fix issue when custom generated default challenges were overwritten and deleted. --- .../challenges/ChallengesImportManager.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java index 2d9c496..953bc26 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java @@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.annotations.Expose; import java.io.*; import java.nio.file.Files; +import java.nio.file.Paths; import java.util.*; import java.util.stream.Collectors; @@ -236,8 +237,13 @@ public class ChallengesImportManager return false; } + // default configuration should be removed. + // user made configuration should not!. + boolean removeAtEnd = + !Files.exists(Paths.get(this.addon.getDataFolder().getPath() + "/default.json")); + // Safe json configuration to Challenges folder. - this.addon.saveResource("default.json", true); + this.addon.saveResource("default.json", false); try { @@ -280,8 +286,11 @@ public class ChallengesImportManager this.addon.getChallengesManager().save(); - // Remove default.yml file from resources to avoid interacting with it. - new File(this.addon.getDataFolder(), "default.json").delete(); + if (removeAtEnd) + { + // Remove default.yml file from resources to avoid interacting with it. + new File(this.addon.getDataFolder(), "default.json").delete(); + } return true; }