Skip to content

Commit

Permalink
Fix issue when custom generated default challenges were overwritten a…
Browse files Browse the repository at this point in the history
…nd deleted.
  • Loading branch information
BONNe committed Jul 8, 2019
1 parent 52f9ee1 commit cd85a92
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;

Expand Down Expand Up @@ -236,8 +237,13 @@ public boolean loadDefaultChallenges(User user, World world)
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
{
Expand Down Expand Up @@ -280,8 +286,11 @@ public boolean loadDefaultChallenges(User user, World world)

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;
}
Expand Down

0 comments on commit cd85a92

Please sign in to comment.