aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/net/sowgro/npehero/levelapi/Difficulty.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/sowgro/npehero/levelapi/Difficulty.java')
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/levelapi/Difficulty.java11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main/java/net/sowgro/npehero/levelapi/Difficulty.java b/src/main/java/net/sowgro/npehero/levelapi/Difficulty.java
index 2e99a7a..99fa285 100755
--- a/src/main/java/net/sowgro/npehero/levelapi/Difficulty.java
+++ b/src/main/java/net/sowgro/npehero/levelapi/Difficulty.java
@@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder;
import com.google.gson.ToNumberPolicy;
import java.io.*;
+import java.util.HashMap;
import java.util.Map;
/**
@@ -50,6 +51,9 @@ public class Difficulty implements Comparable<Difficulty>
return;
}
Map<String, Object> data = jsonParser.fromJson(new FileReader(jsonFile), Map.class);
+ if (data == null) {
+ data = new HashMap<>();
+ }
title = (String) data.getOrDefault("title", title);
bpm = (Double) data.getOrDefault("bpm", bpm);
@@ -78,8 +82,13 @@ public class Difficulty implements Comparable<Difficulty>
* @throws IOException If there is a problem writing to the file
*/
public void writeMetadata() throws IOException {
- jsonFile.createNewFile();
+ if (!jsonFile.createNewFile()) {
+ throw new IOException("Could not create file " + jsonFile.getAbsolutePath());
+ }
Map<String, Object> data = jsonParser.fromJson(new FileReader(jsonFile), Map.class); // start with previous values
+ if (data == null) {
+ data = new HashMap<>();
+ }
data.put("title", title);
data.put("endTime", endTime);
data.put("priority", order);