mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-10-01 04:57:27 +02:00
added more Error handling to File saving
This commit is contained in:
parent
f1e1f688ad
commit
45ea7b2699
@ -31,13 +31,15 @@ public abstract class FileSaver {
|
||||
|
||||
public void init() {
|
||||
if (file.exists()) {
|
||||
final JsonObject parentNode;
|
||||
JsonObject parentNode = null;
|
||||
try {
|
||||
parentNode = ViaFabricPlus.GSON.fromJson(new FileReader(file), JsonObject.class).getAsJsonObject();
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (parentNode != null) {
|
||||
read(parentNode);
|
||||
}
|
||||
read(parentNode);
|
||||
}
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
@ -45,7 +47,7 @@ public abstract class FileSaver {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try (final FileWriter fw = new FileWriter(file)) {
|
||||
@ -54,7 +56,7 @@ public abstract class FileSaver {
|
||||
fw.write(ViaFabricPlus.GSON.toJson(parentNode));
|
||||
fw.flush();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user