diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java index d9bc2d5..acd8c5e 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java @@ -14,9 +14,10 @@ import io.github.cottonmc.jankson.JanksonFactory; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.io.File; -import java.io.FileOutputStream; +import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; public class LibGuiClient implements ClientModInitializer { public static final Logger logger = LogManager.getLogger(); @@ -37,11 +38,15 @@ public class LibGuiClient implements ClientModInitializer { public static LibGuiConfig loadConfig() { try { - File file = new File(FabricLoader.getInstance().getConfigDirectory(),"libgui.json5"); + Path file = FabricLoader.getInstance().getConfigDir().resolve("libgui.json5"); - if (!file.exists()) saveConfig(new LibGuiConfig()); + if (Files.notExists(file)) saveConfig(new LibGuiConfig()); - JsonObject json = jankson.load(file); + JsonObject json; + try (InputStream in = Files.newInputStream(file)) { + json = jankson.load(in); + } + config = jankson.fromJson(json, LibGuiConfig.class); /* @@ -60,13 +65,11 @@ public class LibGuiClient implements ClientModInitializer { public static void saveConfig(LibGuiConfig config) { try { - File file = new File(FabricLoader.getInstance().getConfigDirectory(),"libgui.json5"); + Path file = FabricLoader.getInstance().getConfigDir().resolve("libgui.json5"); JsonElement json = jankson.toJson(config); String result = json.toJson(true, true); - try (FileOutputStream out = new FileOutputStream(file, false)) { - out.write(result.getBytes(StandardCharsets.UTF_8)); - } + Files.write(file, result.getBytes(StandardCharsets.UTF_8)); } catch (Exception e) { logger.error("[LibGui] Error saving config: {}", e.getMessage()); } |