From 7d961a26be737b03861565227ba3a4f6b8c2db35 Mon Sep 17 00:00:00 2001 From: way2muchnoise Date: Sun, 27 Oct 2024 12:45:49 +0100 Subject: [PATCH] create config file for fabric if it doesn't exist --- .../fabric/config/ConfigFileHandler.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Fabric/src/main/java/betteradvancements/fabric/config/ConfigFileHandler.java b/Fabric/src/main/java/betteradvancements/fabric/config/ConfigFileHandler.java index 028e70a..9a861d8 100644 --- a/Fabric/src/main/java/betteradvancements/fabric/config/ConfigFileHandler.java +++ b/Fabric/src/main/java/betteradvancements/fabric/config/ConfigFileHandler.java @@ -22,8 +22,13 @@ public class ConfigFileHandler { public static void readFromConfig() { JsonObject root = new JsonObject(); - try (FileReader file = new FileReader(getConfigFile())) { - root = JsonParser.parseReader(file).getAsJsonObject(); + try { + File configFile = getConfigFile(); + if (!configFile.exists()) { + writeToConfig(); + configFile = getConfigFile(); + } + root = JsonParser.parseReader(new FileReader(configFile)).getAsJsonObject(); } catch (IOException e) { Constants.log.error(e); } @@ -106,7 +111,7 @@ public static void writeToConfig() { } } - public static File getConfigFile() { + public static File getConfigFile() throws IOException { return FabricLoader.getInstance().getConfigDir().resolve("betteradvancements.json").toFile(); } }