diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2021-02-27 16:23:05 +0200 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2021-02-27 16:23:05 +0200 |
commit | 61f953a2c88047ccc5fb2de0b91e661503d0f06a (patch) | |
tree | 2f5be9d66734f5455cd9970d0ea3d88a066cd164 | |
parent | 764a436c529c9d2bb53ded3f8d9917ec18ab669c (diff) | |
download | LibGui-61f953a2c88047ccc5fb2de0b91e661503d0f06a.tar.gz LibGui-61f953a2c88047ccc5fb2de0b91e661503d0f06a.tar.bz2 LibGui-61f953a2c88047ccc5fb2de0b91e661503d0f06a.zip |
Move config handling to Path
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/impl/client/LibGuiClient.java | 21 | ||||
-rw-r--r-- | src/main/resources/fabric.mod.json | 4 |
2 files changed, 14 insertions, 11 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()); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 1030297..a48f2bf 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -26,9 +26,9 @@ "mixins.libgui.accessors.json" ], "depends": { - "fabricloader": ">=0.8.8", + "fabricloader": ">=0.11.0", "fabric": "*", - "minecraft": ">=1.16.1", + "minecraft": ">=1.16.5", "jankson": "^3.0.0", "fabric-networking-api-v1": "^1.0.0" }, |