diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2024-08-29 21:51:14 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2024-08-29 21:51:14 -0400 |
commit | fb70a24c04a5beec6cc7ff9248ef8f5fd46fcc87 (patch) | |
tree | 8f9610d0da1301d6b5e82903418aaf0459cf8666 /src/main/java/net/sowgro/npehero/levelapi/Difficulty.java | |
parent | 7a3aa914a7a64952dd0e134cd998d0cf0e445b4f (diff) | |
download | NPEhero-fb70a24c04a5beec6cc7ff9248ef8f5fd46fcc87.tar.gz NPEhero-fb70a24c04a5beec6cc7ff9248ef8f5fd46fcc87.tar.bz2 NPEhero-fb70a24c04a5beec6cc7ff9248ef8f5fd46fcc87.zip |
Implement new create dialog
Diffstat (limited to 'src/main/java/net/sowgro/npehero/levelapi/Difficulty.java')
-rwxr-xr-x | src/main/java/net/sowgro/npehero/levelapi/Difficulty.java | 11 |
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); |