From 286a12c4ef8e2b531f2fee2c7bee9a83648e3447 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 9 Jun 2019 09:59:08 -0500 Subject: [PATCH] Add experimental option to try to migrate old chunks --- .../src/main/java/org/dynmap/DynmapCore.java | 9 +++++++++ .../helper/v113_2/MapChunkCache113_2.java | 4 +++- .../helper/v114_1/MapChunkCache114_1.java | 15 ++++++++++++++- .../bukkit/helper/v114/MapChunkCache114.java | 19 ++++++++++++++++--- .../java/org/dynmap/bukkit/DynmapPlugin.java | 7 +++++++ spigot/src/main/resources/configuration.txt | 7 +++++++ 6 files changed, 56 insertions(+), 5 deletions(-) diff --git a/DynmapCore/src/main/java/org/dynmap/DynmapCore.java b/DynmapCore/src/main/java/org/dynmap/DynmapCore.java index 82570a03..f4259be6 100644 --- a/DynmapCore/src/main/java/org/dynmap/DynmapCore.java +++ b/DynmapCore/src/main/java/org/dynmap/DynmapCore.java @@ -120,6 +120,7 @@ public class DynmapCore implements DynmapCommonAPI { private List sortPermissionNodes; private int perTickLimit = 50; // 50 ms private boolean dumpMissing = false; + private static boolean migrate_chunks = false; private int config_hashcode; /* Used to signal need to reload web configuration (world changes, config update, etc) */ private int fullrenderplayerlimit; /* Number of online players that will cause fullrender processing to pause */ @@ -203,6 +204,10 @@ public class DynmapCore implements DynmapCommonAPI { public final void setBiomeNames(String[] names) { biomenames = names; } + + public static final boolean migrateChunks() { + return migrate_chunks; + } public final String getBiomeName(int biomeid) { String n = null; @@ -447,6 +452,10 @@ public class DynmapCore implements DynmapCommonAPI { dumpMissing = configuration.getBoolean("dump-missing-blocks", false); + migrate_chunks = configuration.getBoolean("migrate-chunks", false); + if (migrate_chunks) + Log.info("EXPERIMENTAL: chunk migration enabled"); + /* Load preupdate/postupdate commands */ ImageIOManager.preUpdateCommand = configuration.getString("custom-commands/image-updates/preupdatecommand", ""); ImageIOManager.postUpdateCommand = configuration.getString("custom-commands/image-updates/postupdatecommand", ""); 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 6d822667..dd11ba47 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 @@ -3,11 +3,13 @@ package org.dynmap.bukkit.helper.v113_2; import org.bukkit.block.Biome; import org.bukkit.ChunkSnapshot; import org.bukkit.World; +import org.dynmap.DynmapCore; import org.dynmap.bukkit.helper.AbstractMapChunkCache; import org.dynmap.bukkit.helper.BukkitVersionHelper; import org.dynmap.renderer.DynmapBlockState; import net.minecraft.server.v1_13_R2.DataPaletteBlock; +import net.minecraft.server.v1_13_R2.Chunk; /** * Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread @@ -68,7 +70,7 @@ public class MapChunkCache113_2 extends AbstractMapChunkCache { 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) { + if ((!rslt) && DynmapCore.migrateChunks()) { boolean generated = true; // Check one in each direction: see if all are generated for (int xx = x-3; xx <= x+3; xx++) { diff --git a/bukkit-helper-114-1/src/main/java/org/dynmap/bukkit/helper/v114_1/MapChunkCache114_1.java b/bukkit-helper-114-1/src/main/java/org/dynmap/bukkit/helper/v114_1/MapChunkCache114_1.java index bfffcda4..5c2f4ef2 100644 --- a/bukkit-helper-114-1/src/main/java/org/dynmap/bukkit/helper/v114_1/MapChunkCache114_1.java +++ b/bukkit-helper-114-1/src/main/java/org/dynmap/bukkit/helper/v114_1/MapChunkCache114_1.java @@ -298,6 +298,12 @@ public class MapChunkCache114_1 extends AbstractMapChunkCache { } if (nbt != null) { nbt = nbt.getCompound("Level"); + if (nbt != null) { + String stat = nbt.getString("Status"); + if ((stat == null) || (stat.equals("full") == false)) { + nbt = null; + } + } } return nbt; } @@ -315,7 +321,14 @@ public class MapChunkCache114_1 extends AbstractMapChunkCache { if (nbt != null) { String stat = nbt.getString("Status"); if ((stat == null) || (stat.equals("full") == false)) { - nbt = null; + nbt = null; + if ((stat == null) || stat.equals("") && DynmapCore.migrateChunks()) { + Chunk c = cw.getHandle().getChunkAt(x, z); + if (c != null) { + nbt = fetchLoadedChunkNBT(w, x, z); + cw.getHandle().unloadChunk(c); + } + } } } } diff --git a/bukkit-helper-114/src/main/java/org/dynmap/bukkit/helper/v114/MapChunkCache114.java b/bukkit-helper-114/src/main/java/org/dynmap/bukkit/helper/v114/MapChunkCache114.java index d42a22be..8b85ed9b 100644 --- a/bukkit-helper-114/src/main/java/org/dynmap/bukkit/helper/v114/MapChunkCache114.java +++ b/bukkit-helper-114/src/main/java/org/dynmap/bukkit/helper/v114/MapChunkCache114.java @@ -297,6 +297,12 @@ public class MapChunkCache114 extends AbstractMapChunkCache { } if (nbt != null) { nbt = nbt.getCompound("Level"); + if (nbt != null) { + String stat = nbt.getString("Status"); + if ((stat == null) || (stat.equals("full") == false)) { + nbt = null; + } + } } return nbt; } @@ -313,9 +319,16 @@ public class MapChunkCache114 extends AbstractMapChunkCache { nbt = nbt.getCompound("Level"); if (nbt != null) { String stat = nbt.getString("Status"); - if ((stat == null) || (stat.equals("full") == false)) { - nbt = null; - } + if ((stat == null) || (stat.equals("full") == false)) { + nbt = null; + if ((stat == null) || stat.equals("") && DynmapCore.migrateChunks()) { + Chunk c = cw.getHandle().getChunkAt(x, z); + if (c != null) { + nbt = fetchLoadedChunkNBT(w, x, z); + cw.getHandle().unloadChunk(c); + } + } + } } } return nbt; diff --git a/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java b/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java index 19983066..be7e73e1 100644 --- a/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java +++ b/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java @@ -1624,4 +1624,11 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { Polygon getWorldBorder(World w) { return helper.getWorldBorder(w); } + + public static boolean migrateChunks() { + if ((plugin != null) && (plugin.core != null)) { + return plugin.core.migrateChunks(); + } + return false; + } } diff --git a/spigot/src/main/resources/configuration.txt b/spigot/src/main/resources/configuration.txt index b1280266..9e398f45 100644 --- a/spigot/src/main/resources/configuration.txt +++ b/spigot/src/main/resources/configuration.txt @@ -463,3 +463,10 @@ verbose: false # - class: org.dynmap.debug.LogDebugger # Debug: dump blocks missing render data dump-missing-blocks: false + +# Have dynmap migrate old chunks to the new format for the current MC version (specifically, for migrating pre-1.13 chunks to 1.13 or 1.14). This is needed +# in order to render chunks on an upgraded server (due to various bugs/limitations in CB/spigot 1.13+). This setting is NOT suggested to be enabled full time, +# but only long enough to do a fullrender of a migrated world - it should be turned back off once worlds are migrated). It is EXPERIMENTAL, so be sure to backup +# your worlds before running with this setting enabled (set to true) +# +#migrate-chunks: true