From 128d356655f229c943dc791a2694214dfbd588d4 Mon Sep 17 00:00:00 2001 From: Pierre Kisters Date: Sat, 15 Aug 2020 16:49:02 +0200 Subject: [PATCH] fixes --- .../dynmap/fabric_1_16_1/ChunkSnapshot.java | 12 ++++++---- .../fabric_1_16_1/FabricMapChunkCache.java | 22 ++++++++++++------ .../org/dynmap/fabric_1_16_1/FabricWorld.java | 2 +- .../dynmap/fabric_1_16_2/ChunkSnapshot.java | 12 ++++++---- .../fabric_1_16_2/FabricMapChunkCache.java | 23 +++++++++++++------ .../org/dynmap/fabric_1_16_2/FabricWorld.java | 2 +- 6 files changed, 49 insertions(+), 24 deletions(-) diff --git a/fabric-1.16.1/src/main/java/org/dynmap/fabric_1_16_1/ChunkSnapshot.java b/fabric-1.16.1/src/main/java/org/dynmap/fabric_1_16_1/ChunkSnapshot.java index d3ba79ac..a4792f0d 100644 --- a/fabric-1.16.1/src/main/java/org/dynmap/fabric_1_16_1/ChunkSnapshot.java +++ b/fabric-1.16.1/src/main/java/org/dynmap/fabric_1_16_1/ChunkSnapshot.java @@ -125,7 +125,10 @@ public class ChunkSnapshot { this.inhabitedTicks = inhabitedTime; } - public ChunkSnapshot(CompoundTag nbt, int worldheight) { + public static class StateListException extends Exception { + } + + public ChunkSnapshot(CompoundTag nbt, int worldheight) throws StateListException { this.x = nbt.getInt("xPos"); this.z = nbt.getInt("zPos"); this.captureFulltime = 0; @@ -187,10 +190,11 @@ public class ChunkSnapshot { int bitsperblock = (statelist.length * 64) / 4096; int expectedStatelistLength = (4096 + (64 / bitsperblock) - 1) / (64 / bitsperblock); if (expectedStatelistLength > statelist.length) { // TODO: find out why this is happening and why it doesn't seem to happen on other platforms - Log.warning("Got statelist of length " + statelist.length + " but expected a length of " + expectedStatelistLength); - long[] expandedStatelist = new long[expectedStatelistLength]; + Log.warning("Got statelist of length " + statelist.length + " but expected a length of " + expectedStatelistLength + " at ChunkPos(x=" + x + ",z=" + z + ")"); + throw new StateListException(); + /*long[] expandedStatelist = new long[expectedStatelistLength]; System.arraycopy(statelist, 0, expandedStatelist, 0, statelist.length); - statelist = expandedStatelist; + statelist = expandedStatelist;*/ } PackedIntegerArray db = new PackedIntegerArray(bitsperblock, 4096, statelist); diff --git a/fabric-1.16.1/src/main/java/org/dynmap/fabric_1_16_1/FabricMapChunkCache.java b/fabric-1.16.1/src/main/java/org/dynmap/fabric_1_16_1/FabricMapChunkCache.java index ac2b7f5a..9ba27a66 100644 --- a/fabric-1.16.1/src/main/java/org/dynmap/fabric_1_16_1/FabricMapChunkCache.java +++ b/fabric-1.16.1/src/main/java/org/dynmap/fabric_1_16_1/FabricMapChunkCache.java @@ -996,7 +996,7 @@ public class FabricMapChunkCache extends MapChunkCache { } // Prep snapshot and add to cache - private SnapshotCache.SnapshotRec prepChunkSnapshot(DynmapChunk chunk, CompoundTag nbt) { + private SnapshotCache.SnapshotRec prepChunkSnapshot(DynmapChunk chunk, CompoundTag nbt) throws ChunkSnapshot.StateListException { ChunkSnapshot ss = new ChunkSnapshot(nbt, dw.worldheight); DynIntHashMap tileData = new DynIntHashMap(); @@ -1072,9 +1072,13 @@ public class FabricMapChunkCache extends MapChunkCache { if (vis) { // If visible CompoundTag nbt = ChunkSerializer.serialize((ServerWorld) w, cps.getWorldChunk(chunk.x, chunk.z, false)); if (nbt != null) nbt = nbt.getCompound("Level"); - SnapshotCache.SnapshotRec ssr = prepChunkSnapshot(chunk, nbt); - ss = ssr.ss; - tileData = ssr.tileData; + try { + SnapshotCache.SnapshotRec ssr = prepChunkSnapshot(chunk, nbt); + ss = ssr.ss; + tileData = ssr.tileData; + } catch (ChunkSnapshot.StateListException e) { + continue; + } } else { if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) { ss = STONE; @@ -1148,9 +1152,13 @@ public class FabricMapChunkCache extends MapChunkCache { tileData = new DynIntHashMap(); } else { // Prep snapshot - SnapshotCache.SnapshotRec ssr = prepChunkSnapshot(chunk, nbt); - ss = ssr.ss; - tileData = ssr.tileData; + try { + SnapshotCache.SnapshotRec ssr = prepChunkSnapshot(chunk, nbt); + ss = ssr.ss; + tileData = ssr.tileData; + } catch (ChunkSnapshot.StateListException e) { + continue; + } } snaparray[chunkindex] = ss; snaptile[chunkindex] = tileData; diff --git a/fabric-1.16.1/src/main/java/org/dynmap/fabric_1_16_1/FabricWorld.java b/fabric-1.16.1/src/main/java/org/dynmap/fabric_1_16_1/FabricWorld.java index 9b4e31ec..5ac2ada6 100644 --- a/fabric-1.16.1/src/main/java/org/dynmap/fabric_1_16_1/FabricWorld.java +++ b/fabric-1.16.1/src/main/java/org/dynmap/fabric_1_16_1/FabricWorld.java @@ -50,8 +50,8 @@ public class FabricWorld extends DynmapWorld { public FabricWorld(WorldAccess w) { this(getWorldName(w), w.getWorld().getHeight(), w.getWorld().getSeaLevel(), - w.getWorld().getRegistryKey() == World.END, w.getWorld().getRegistryKey() == World.NETHER, + w.getWorld().getRegistryKey() == World.END, w.getWorld().getRegistryKey().getValue().getPath()); setWorldLoaded(w); } diff --git a/fabric-1.16.2/src/main/java/org/dynmap/fabric_1_16_2/ChunkSnapshot.java b/fabric-1.16.2/src/main/java/org/dynmap/fabric_1_16_2/ChunkSnapshot.java index f301bea5..fb1182ff 100644 --- a/fabric-1.16.2/src/main/java/org/dynmap/fabric_1_16_2/ChunkSnapshot.java +++ b/fabric-1.16.2/src/main/java/org/dynmap/fabric_1_16_2/ChunkSnapshot.java @@ -125,7 +125,10 @@ public class ChunkSnapshot { this.inhabitedTicks = inhabitedTime; } - public ChunkSnapshot(CompoundTag nbt, int worldheight) { + public static class StateListException extends Exception { + } + + public ChunkSnapshot(CompoundTag nbt, int worldheight) throws StateListException { this.x = nbt.getInt("xPos"); this.z = nbt.getInt("zPos"); this.captureFulltime = 0; @@ -187,10 +190,11 @@ public class ChunkSnapshot { int bitsperblock = (statelist.length * 64) / 4096; int expectedStatelistLength = (4096 + (64 / bitsperblock) - 1) / (64 / bitsperblock); if (expectedStatelistLength > statelist.length) { // TODO: find out why this is happening and why it doesn't seem to happen on other platforms - Log.warning("Got statelist of length " + statelist.length + " but expected a length of " + expectedStatelistLength); - long[] expandedStatelist = new long[expectedStatelistLength]; + Log.warning("Got statelist of length " + statelist.length + " but expected a length of " + expectedStatelistLength + " at ChunkPos(x=" + x + ",z=" + z + ")"); + throw new StateListException(); + /*long[] expandedStatelist = new long[expectedStatelistLength]; System.arraycopy(statelist, 0, expandedStatelist, 0, statelist.length); - statelist = expandedStatelist; + statelist = expandedStatelist;*/ } PackedIntegerArray db = new PackedIntegerArray(bitsperblock, 4096, statelist); diff --git a/fabric-1.16.2/src/main/java/org/dynmap/fabric_1_16_2/FabricMapChunkCache.java b/fabric-1.16.2/src/main/java/org/dynmap/fabric_1_16_2/FabricMapChunkCache.java index c43b86ee..cd9069d2 100644 --- a/fabric-1.16.2/src/main/java/org/dynmap/fabric_1_16_2/FabricMapChunkCache.java +++ b/fabric-1.16.2/src/main/java/org/dynmap/fabric_1_16_2/FabricMapChunkCache.java @@ -1024,7 +1024,7 @@ public class FabricMapChunkCache extends MapChunkCache { } // Prep snapshot and add to cache - private SnapshotCache.SnapshotRec prepChunkSnapshot(DynmapChunk chunk, CompoundTag nbt) { + private SnapshotCache.SnapshotRec prepChunkSnapshot(DynmapChunk chunk, CompoundTag nbt) throws ChunkSnapshot.StateListException { ChunkSnapshot ss = new ChunkSnapshot(nbt, dw.worldheight); DynIntHashMap tileData = new DynIntHashMap(); @@ -1104,11 +1104,16 @@ public class FabricMapChunkCache extends MapChunkCache { } catch (NullPointerException e) { // TODO: find out why this is happening and why it only seems to happen since 1.16.2 Log.severe("ChunkSerializer.serialize threw a NullPointerException", e); + continue; } if (nbt != null) nbt = nbt.getCompound("Level"); - SnapshotCache.SnapshotRec ssr = prepChunkSnapshot(chunk, nbt); - ss = ssr.ss; - tileData = ssr.tileData; + try { + SnapshotCache.SnapshotRec ssr = prepChunkSnapshot(chunk, nbt); + ss = ssr.ss; + tileData = ssr.tileData; + } catch (ChunkSnapshot.StateListException e) { + continue; + } } else { if (hidestyle == HiddenChunkStyle.FILL_STONE_PLAIN) { ss = STONE; @@ -1182,9 +1187,13 @@ public class FabricMapChunkCache extends MapChunkCache { tileData = new DynIntHashMap(); } else { // Prep snapshot - SnapshotCache.SnapshotRec ssr = prepChunkSnapshot(chunk, nbt); - ss = ssr.ss; - tileData = ssr.tileData; + try { + SnapshotCache.SnapshotRec ssr = prepChunkSnapshot(chunk, nbt); + ss = ssr.ss; + tileData = ssr.tileData; + } catch (ChunkSnapshot.StateListException e) { + continue; + } } snaparray[chunkindex] = ss; snaptile[chunkindex] = tileData; diff --git a/fabric-1.16.2/src/main/java/org/dynmap/fabric_1_16_2/FabricWorld.java b/fabric-1.16.2/src/main/java/org/dynmap/fabric_1_16_2/FabricWorld.java index ad01a82a..777befd6 100644 --- a/fabric-1.16.2/src/main/java/org/dynmap/fabric_1_16_2/FabricWorld.java +++ b/fabric-1.16.2/src/main/java/org/dynmap/fabric_1_16_2/FabricWorld.java @@ -51,8 +51,8 @@ public class FabricWorld extends DynmapWorld { public FabricWorld(DynmapPlugin plugin, World w) { this(plugin, getWorldName(plugin, w), w.getHeight(), w.getSeaLevel(), - w.getRegistryKey() == World.END, w.getRegistryKey() == World.NETHER, + w.getRegistryKey() == World.END, w.getRegistryKey().getValue().getPath()); setWorldLoaded(w); }