From fb70a24c04a5beec6cc7ff9248ef8f5fd46fcc87 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 29 Aug 2024 21:51:14 -0400 Subject: Implement new create dialog --- src/main/java/net/sowgro/npehero/levelapi/Difficulty.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/main/java/net/sowgro/npehero/levelapi/Difficulty.java') 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 return; } Map 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 * @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 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); -- cgit v1.2.3