diff options
| author | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-07-14 15:58:59 +0800 |
|---|---|---|
| committer | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-08-30 22:49:51 -0400 |
| commit | b81cd1254ddc430120c64b1ddcc95e0537f32789 (patch) | |
| tree | 8fd017278979efa183748d90b0e46ed6a038dbd3 | |
| parent | a5998f09db291a15b7108dec8a66065fbdc40108 (diff) | |
| download | Skyblocker-b81cd1254ddc430120c64b1ddcc95e0537f32789.tar.gz Skyblocker-b81cd1254ddc430120c64b1ddcc95e0537f32789.tar.bz2 Skyblocker-b81cd1254ddc430120c64b1ddcc95e0537f32789.zip | |
Add rooms data saving and update reading to nio
123 files changed, 4528 insertions, 100 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java index b689f828..9a9752fb 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java @@ -16,9 +16,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.BufferedReader; -import java.io.File; import java.io.IOException; import java.io.ObjectInputStream; +import java.net.URL; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.zip.InflaterInputStream; @@ -29,6 +32,7 @@ public class DungeonSecrets { private static final HashMap<String, HashMap<String, HashMap<String, int[]>>> ROOMS = new HashMap<>(); /** * Maps the block identifier string to a custom numeric block id used in dungeon rooms data. + * * @implNote Not using {@link net.minecraft.registry.Registry#getId(Object) Registry#getId(Block)} and {@link net.minecraft.block.Blocks Blocks} since this is also used by {@link me.xmrvizzy.skyblocker.skyblock.dungeon.secrets.DungeonRoomsDFU DungeonRoomsDFU}, which runs outside of Minecraft. */ @SuppressWarnings("JavadocReference") @@ -79,63 +83,63 @@ public class DungeonSecrets { } private static void load() { - try { - List<CompletableFuture<Void>> dungeonFutures = new ArrayList<>(); - //noinspection DataFlowIssue - File dungeons = new File(SkyblockerMod.class.getResource(DUNGEONS_DATA_DIR).getFile()); - int resourcePathIndex = dungeons.getPath().indexOf(DUNGEONS_DATA_DIR); - //noinspection DataFlowIssue - for (File dungeon : dungeons.listFiles()) { - if (!dungeon.isDirectory()) { - continue; - } - File[] roomShapes = dungeon.listFiles(); - if (roomShapes == null) { - LOGGER.error("Failed to load dungeon secrets for dungeon {}", dungeon.getName()); - continue; - } - ROOMS.put(dungeon.getName(), new HashMap<>()); - List<CompletableFuture<Void>> roomShapeFutures = new ArrayList<>(); - for (File roomShape : roomShapes) { - roomShapeFutures.add(CompletableFuture.supplyAsync(() -> readRooms(roomShape, resourcePathIndex)).thenAccept(rooms -> ROOMS.get(dungeon.getName()).put(roomShape.getName(), rooms))); + List<CompletableFuture<Void>> dungeonFutures = new ArrayList<>(); + URL dungeonsURL = SkyblockerMod.class.getResource(DUNGEONS_DATA_DIR); + if (dungeonsURL == null) { + LOGGER.error("Failed to load dungeon secrets, unable to find dungeon rooms data directory"); + return; + } + Path dungeonsDir = Path.of(dungeonsURL.getPath()); + int resourcePathIndex = dungeonsDir.toString().indexOf(DUNGEONS_DATA_DIR); + try (DirectoryStream<Path> dungeons = Files.newDirectoryStream(dungeonsDir, Files::isDirectory)) { + for (Path dungeon : dungeons) { + try (DirectoryStream<Path> roomShapes = Files.newDirectoryStream(dungeon, Files::isDirectory)) { + List<CompletableFuture<Void>> roomShapeFutures = new ArrayList<>(); + HashMap<String, HashMap<String, int[]>> roomShapesMap = new HashMap<>(); + for (Path roomShape : roomShapes) { + roomShapeFutures.add(CompletableFuture.supplyAsync(() -> readRooms(roomShape, resourcePathIndex)).thenAccept(rooms -> roomShapesMap.put(roomS |
