From 12c4df777dea48fd4fd5d9bb147b88aa85a0c199 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sat, 1 Dec 2018 19:22:47 -0600 Subject: [PATCH] Add workaround for Spigot 1.13.2 bug with loadChunk(x,z,false) Workaround problem with fact that World.loadChunk(x, z, false) fails when called on existing chunks that have not been migrated to 1.13.x format. --- .../helper/v113_2/MapChunkCache113_2.java | 22 +++++++++++++++++++ .../bukkit/helper/AbstractMapChunkCache.java | 6 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/bukkit-helper-113-2/src/main/java/org/dynmap/bukkit/helper/v113_2/MapChunkCache113_2.java b/bukkit-helper-113-2/src/main/java/org/dynmap/bukkit/helper/v113_2/MapChunkCache113_2.java index 382d82ea..6d822667 100644 --- a/bukkit-helper-113-2/src/main/java/org/dynmap/bukkit/helper/v113_2/MapChunkCache113_2.java +++ b/bukkit-helper-113-2/src/main/java/org/dynmap/bukkit/helper/v113_2/MapChunkCache113_2.java @@ -2,6 +2,7 @@ package org.dynmap.bukkit.helper.v113_2; import org.bukkit.block.Biome; import org.bukkit.ChunkSnapshot; +import org.bukkit.World; import org.dynmap.bukkit.helper.AbstractMapChunkCache; import org.dynmap.bukkit.helper.BukkitVersionHelper; import org.dynmap.renderer.DynmapBlockState; @@ -63,4 +64,25 @@ public class MapChunkCache113_2 extends AbstractMapChunkCache { public Snapshot wrapChunkSnapshot(ChunkSnapshot css) { return new WrappedSnapshot(css); } + @Override + public boolean loadChunkNoGenerate(World w, int x, int z) { + boolean rslt = w.loadChunk(x, z, false); + // Workaround for Spigot 1.13.2 bug - check if generated and do load-with-generate if so to drive migration of old chunks + if (!rslt) { + boolean generated = true; + // Check one in each direction: see if all are generated + for (int xx = x-3; xx <= x+3; xx++) { + for (int zz = z-3; zz <= z+3; zz++) { + if (w.isChunkGenerated(xx, zz) == false) { + generated = false; + break; + } + } + } + if (generated) { + rslt = w.loadChunk(x, z, true); + } + } + return rslt; + } } diff --git a/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/AbstractMapChunkCache.java b/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/AbstractMapChunkCache.java index d106ac6a..5eec9145 100644 --- a/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/AbstractMapChunkCache.java +++ b/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/AbstractMapChunkCache.java @@ -796,7 +796,7 @@ public abstract class AbstractMapChunkCache extends MapChunkCache { wasLoaded = true; } try { - didload = w.loadChunk(chunk.x, chunk.z, false); + didload = loadChunkNoGenerate(w, chunk.x, chunk.z); } catch (Throwable t) { /* Catch chunk error from Bukkit */ Log.warning("Bukkit error loading chunk " + chunk.x + "," + chunk.z + " on " + w.getName()); if(!wasLoaded) { /* If wasn't loaded, we loaded it if it now is */ @@ -1013,6 +1013,10 @@ public abstract class AbstractMapChunkCache extends MapChunkCache { return dw; } + public boolean loadChunkNoGenerate(World w, int x, int z) { + return w.loadChunk(x, z, false); + } + static { Biome[] b = Biome.values(); BiomeMap[] bm = BiomeMap.values();