aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/FairySouls.java
diff options
context:
space:
mode:
authorAaron <51387595+AzureAaron@users.noreply.github.com>2023-11-04 00:24:53 -0400
committerGitHub <noreply@github.com>2023-11-04 00:24:53 -0400
commitd8bd4d6c76de9ae2c03d59646c55673c1e8e30e1 (patch)
tree4eb0234e3292fc9b37e807770c789ff63d2f18c5 /src/main/java/de/hysky/skyblocker/skyblock/FairySouls.java
parenta309de2e02d4c635983bf181ca23b7e119edab56 (diff)
parent0d738a4bd470a4f5608f59cb88c0aba33b1ac4fc (diff)
downloadSkyblocker-d8bd4d6c76de9ae2c03d59646c55673c1e8e30e1.tar.gz
Skyblocker-d8bd4d6c76de9ae2c03d59646c55673c1e8e30e1.tar.bz2
Skyblocker-d8bd4d6c76de9ae2c03d59646c55673c1e8e30e1.zip
Merge pull request #404 from AzureAaron/nio-refactor
NIO Refactor
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/FairySouls.java')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/FairySouls.java9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/FairySouls.java b/src/main/java/de/hysky/skyblocker/skyblock/FairySouls.java
index 67bdfdc5..3e1220b0 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/FairySouls.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/FairySouls.java
@@ -30,6 +30,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@@ -70,7 +72,7 @@ public class FairySouls {
NEURepoManager.NEU_REPO.getConstants().getFairySouls().getSoulLocations().forEach((location, fairySoulsForLocation) -> fairySouls.put(location, fairySoulsForLocation.stream().map(coordinate -> new BlockPos(coordinate.getX(), coordinate.getY(), coordinate.getZ())).collect(Collectors.toUnmodifiableSet())));
LOGGER.debug("[Skyblocker] Loaded {} fairy souls across {} locations", fairySouls.values().stream().mapToInt(Set::size).sum(), fairySouls.size());
- try (BufferedReader reader = new BufferedReader(new FileReader(SkyblockerMod.CONFIG_DIR.resolve("found_fairy_souls.json").toFile()))) {
+ try (BufferedReader reader = Files.newBufferedReader(SkyblockerMod.CONFIG_DIR.resolve("found_fairy_souls.json"))) {
for (Map.Entry<String, JsonElement> foundFairiesForProfileJson : JsonParser.parseReader(reader).getAsJsonObject().asMap().entrySet()) {
Map<String, Set<BlockPos>> foundFairiesForProfile = new HashMap<>();
for (Map.Entry<String, JsonElement> foundFairiesForLocationJson : foundFairiesForProfileJson.getValue().getAsJsonObject().asMap().entrySet()) {
@@ -83,7 +85,7 @@ public class FairySouls {
foundFairies.put(foundFairiesForProfileJson.getKey(), foundFairiesForProfile);
}
LOGGER.debug("[Skyblocker] Loaded found fairy souls");
- } catch (FileNotFoundException ignored) {
+ } catch (NoSuchFileException ignored) {
} catch (IOException e) {
LOGGER.error("[Skyblocker] Failed to load found fairy souls", e);
}
@@ -92,7 +94,7 @@ public class FairySouls {
}
private static void saveFoundFairySouls(MinecraftClient client) {
- try (BufferedWriter writer = new BufferedWriter(new FileWriter(SkyblockerMod.CONFIG_DIR.resolve("found_fairy_souls.json").toFile()))) {
+ try (BufferedWriter writer = Files.newBufferedWriter(SkyblockerMod.CONFIG_DIR.resolve("found_fairy_souls.json"))) {
JsonObject foundFairiesJson = new JsonObject();
for (Map.Entry<String, Map<String, Set<BlockPos>>> foundFairiesForProfile : foundFairies.entrySet()) {
JsonObject foundFairiesForProfileJson = new JsonObject();
@@ -106,7 +108,6 @@ public class FairySouls {
foundFairiesJson.add(foundFairiesForProfile.getKey(), foundFairiesForProfileJson);
}
SkyblockerMod.GSON.toJson(foundFairiesJson, writer);
- writer.close();
LOGGER.info("[Skyblocker] Saved found fairy souls");
} catch (IOException e) {
LOGGER.error("[Skyblocker] Failed to write found fairy souls to file", e);