From 29ebef172ffce1db60af2b0eb3639b15b30c1b75 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sat, 8 Dec 2018 00:15:06 -0600 Subject: [PATCH 1/2] Fix 1.13 world border support, handle world border changes --- .../java/org/dynmap/DynmapMapCommands.java | 10 +++++++++ .../src/main/java/org/dynmap/DynmapWorld.java | 3 +++ .../src/main/java/org/dynmap/MapManager.java | 12 +++++++++++ .../java/org/dynmap/MarkersComponent.java | 2 +- .../BukkitVersionHelperSpigot113_1.java | 21 +++++++++++++++++++ .../BukkitVersionHelperSpigot113_2.java | 21 +++++++++++++++++++ .../v113/BukkitVersionHelperSpigot113.java | 21 +++++++++++++++++++ 7 files changed, 89 insertions(+), 1 deletion(-) diff --git a/DynmapCore/src/main/java/org/dynmap/DynmapMapCommands.java b/DynmapCore/src/main/java/org/dynmap/DynmapMapCommands.java index b9c50da9..d295f84e 100644 --- a/DynmapCore/src/main/java/org/dynmap/DynmapMapCommands.java +++ b/DynmapCore/src/main/java/org/dynmap/DynmapMapCommands.java @@ -104,6 +104,7 @@ public class DynmapMapCommands { sb.append(", extrazoomout=").append(w.getExtraZoomOutLevels()).append(", sendhealth=").append(w.sendhealth); sb.append(", sendposition=").append(w.sendposition); sb.append(", protected=").append(w.is_protected); + sb.append(", showborder=").append(w.showborder); if(w.tileupdatedelay > 0) { sb.append(", tileupdatedelay=").append(w.tileupdatedelay); } @@ -172,6 +173,15 @@ public class DynmapMapCommands { core.updateWorldConfig(w); did_update = true; } + else if(tok[0].equalsIgnoreCase("showborder")) { + if(w == null) { + sender.sendMessage("Cannot set sendworldborder on disabled or undefined world"); + return true; + } + w.showborder = tok[1].equals("true"); + core.updateWorldConfig(w); + did_update = true; + } else if(tok[0].equalsIgnoreCase("protected")) { if(w == null) { sender.sendMessage("Cannot set protected on disabled or undefined world"); diff --git a/DynmapCore/src/main/java/org/dynmap/DynmapWorld.java b/DynmapCore/src/main/java/org/dynmap/DynmapWorld.java index ead5d1c7..78befeab 100644 --- a/DynmapCore/src/main/java/org/dynmap/DynmapWorld.java +++ b/DynmapCore/src/main/java/org/dynmap/DynmapWorld.java @@ -37,6 +37,7 @@ public abstract class DynmapWorld { public int servertime; public boolean sendposition; public boolean sendhealth; + public boolean showborder; private int extrazoomoutlevels; /* Number of additional zoom out levels to generate */ private boolean cancelled; private final String wname; @@ -326,6 +327,7 @@ public abstract class DynmapWorld { servertime = (int)(getTime() % 24000); sendposition = worldconfig.getBoolean("sendposition", true); sendhealth = worldconfig.getBoolean("sendhealth", true); + showborder = worldconfig.getBoolean("showborder", true); is_protected = worldconfig.getBoolean("protected", false); setExtraZoomOutLevels(worldconfig.getInteger("extrazoomout", 0)); setTileUpdateDelay(worldconfig.getInteger("tileupdatedelay", -1)); @@ -419,6 +421,7 @@ public abstract class DynmapWorld { node.put("title", getTitle()); node.put("enabled", is_enabled); node.put("protected", is_protected); + node.put("showborder", showborder); if(tileupdatedelay > 0) { node.put("tileupdatedelay", tileupdatedelay); } diff --git a/DynmapCore/src/main/java/org/dynmap/MapManager.java b/DynmapCore/src/main/java/org/dynmap/MapManager.java index 8e63c9de..77d9633d 100644 --- a/DynmapCore/src/main/java/org/dynmap/MapManager.java +++ b/DynmapCore/src/main/java/org/dynmap/MapManager.java @@ -27,11 +27,13 @@ import java.util.concurrent.atomic.AtomicLong; import org.dynmap.common.DynmapCommandSender; import org.dynmap.common.DynmapPlayer; +import org.dynmap.common.DynmapListenerManager.EventType; import org.dynmap.debug.Debug; import org.dynmap.exporter.OBJExport; import org.dynmap.hdmap.HDMapManager; import org.dynmap.renderer.DynmapBlockState; import org.dynmap.utils.MapChunkCache; +import org.dynmap.utils.Polygon; import org.dynmap.utils.TileFlags; public class MapManager { @@ -775,6 +777,7 @@ public class MapManager { } private class CheckWorldTimes implements Runnable { + HashMap last_worldborder = new HashMap(); public void run() { Future f = core.getServer().callSyncMethod(new Callable() { public Integer call() throws Exception { @@ -789,6 +792,15 @@ public class MapManager { if(wasday != isday) { pushUpdate(w, new Client.DayNight(isday)); } + // Check world border + Polygon wb = w.getWorldBorder(); + Polygon oldwb = last_worldborder.get(w.getName()); + if (((wb == null) && (oldwb == null)) || + wb.equals(oldwb)) { // No change + } + else { + core.listenerManager.processWorldEvent(EventType.WORLD_SPAWN_CHANGE, w); + } } /* Tick invalidated tiles processing */ for(MapTypeState mts : w.mapstate) { diff --git a/DynmapCore/src/main/java/org/dynmap/MarkersComponent.java b/DynmapCore/src/main/java/org/dynmap/MarkersComponent.java index a65be285..c48772c7 100644 --- a/DynmapCore/src/main/java/org/dynmap/MarkersComponent.java +++ b/DynmapCore/src/main/java/org/dynmap/MarkersComponent.java @@ -254,7 +254,7 @@ public class MarkersComponent extends ClientComponent { String borderid = "_worldborder_" + w.getName(); AreaMarker am = ms.findAreaMarker(borderid); Polygon p = null; - if (showBorder) { + if (showBorder && w.showborder) { p = w.getWorldBorder(); } if ((p != null) && (p.size() > 1)) { diff --git a/bukkit-helper-113-1/src/main/java/org/dynmap/bukkit/helper/v113_1/BukkitVersionHelperSpigot113_1.java b/bukkit-helper-113-1/src/main/java/org/dynmap/bukkit/helper/v113_1/BukkitVersionHelperSpigot113_1.java index 4fe7d22d..32c198c6 100644 --- a/bukkit-helper-113-1/src/main/java/org/dynmap/bukkit/helper/v113_1/BukkitVersionHelperSpigot113_1.java +++ b/bukkit-helper-113-1/src/main/java/org/dynmap/bukkit/helper/v113_1/BukkitVersionHelperSpigot113_1.java @@ -15,8 +15,10 @@ import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.ChunkSnapshot; +import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; +import org.bukkit.WorldBorder; import org.dynmap.DynmapChunk; import org.dynmap.Log; import org.dynmap.bukkit.helper.BukkitVersionHelper; @@ -169,4 +171,23 @@ public class BukkitVersionHelperSpigot113_1 extends BukkitVersionHelperCB { return ((BiomeBase)bb).n(); } + @Override + public Polygon getWorldBorder(World world) { + Polygon p = null; + WorldBorder wb = world.getWorldBorder(); + if (wb != null) { + Location c = wb.getCenter(); + double size = wb.getSize(); + if ((size > 1) && (size < 1E7)) { + size = size / 2; + p = new Polygon(); + p.addVertex(c.getX()-size, c.getZ()-size); + p.addVertex(c.getX()+size, c.getZ()-size); + p.addVertex(c.getX()+size, c.getZ()+size); + p.addVertex(c.getX()-size, c.getZ()+size); + } + } + return p; + } + } diff --git a/bukkit-helper-113-2/src/main/java/org/dynmap/bukkit/helper/v113_2/BukkitVersionHelperSpigot113_2.java b/bukkit-helper-113-2/src/main/java/org/dynmap/bukkit/helper/v113_2/BukkitVersionHelperSpigot113_2.java index 16e5f2ad..e06d5712 100644 --- a/bukkit-helper-113-2/src/main/java/org/dynmap/bukkit/helper/v113_2/BukkitVersionHelperSpigot113_2.java +++ b/bukkit-helper-113-2/src/main/java/org/dynmap/bukkit/helper/v113_2/BukkitVersionHelperSpigot113_2.java @@ -15,8 +15,10 @@ import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.ChunkSnapshot; +import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; +import org.bukkit.WorldBorder; import org.dynmap.DynmapChunk; import org.dynmap.Log; import org.dynmap.bukkit.helper.BukkitVersionHelper; @@ -169,4 +171,23 @@ public class BukkitVersionHelperSpigot113_2 extends BukkitVersionHelperCB { return ((BiomeBase)bb).n(); } + @Override + public Polygon getWorldBorder(World world) { + Polygon p = null; + WorldBorder wb = world.getWorldBorder(); + if (wb != null) { + Location c = wb.getCenter(); + double size = wb.getSize(); + if ((size > 1) && (size < 1E7)) { + size = size / 2; + p = new Polygon(); + p.addVertex(c.getX()-size, c.getZ()-size); + p.addVertex(c.getX()+size, c.getZ()-size); + p.addVertex(c.getX()+size, c.getZ()+size); + p.addVertex(c.getX()-size, c.getZ()+size); + } + } + return p; + } + } diff --git a/bukkit-helper-113/src/main/java/org/dynmap/bukkit/helper/v113/BukkitVersionHelperSpigot113.java b/bukkit-helper-113/src/main/java/org/dynmap/bukkit/helper/v113/BukkitVersionHelperSpigot113.java index db47af79..bb5cae28 100644 --- a/bukkit-helper-113/src/main/java/org/dynmap/bukkit/helper/v113/BukkitVersionHelperSpigot113.java +++ b/bukkit-helper-113/src/main/java/org/dynmap/bukkit/helper/v113/BukkitVersionHelperSpigot113.java @@ -15,8 +15,10 @@ import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.ChunkSnapshot; +import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; +import org.bukkit.WorldBorder; import org.dynmap.DynmapChunk; import org.dynmap.Log; import org.dynmap.bukkit.helper.BukkitVersionHelper; @@ -163,4 +165,23 @@ public class BukkitVersionHelperSpigot113 extends BukkitVersionHelperCB { return ((BiomeBase)bb).n(); } + @Override + public Polygon getWorldBorder(World world) { + Polygon p = null; + WorldBorder wb = world.getWorldBorder(); + if (wb != null) { + Location c = wb.getCenter(); + double size = wb.getSize(); + if ((size > 1) && (size < 1E7)) { + size = size / 2; + p = new Polygon(); + p.addVertex(c.getX()-size, c.getZ()-size); + p.addVertex(c.getX()+size, c.getZ()-size); + p.addVertex(c.getX()+size, c.getZ()+size); + p.addVertex(c.getX()-size, c.getZ()+size); + } + } + return p; + } + } From def802bf8de4c8aa563ba76d9155ed163d05eaf2 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sat, 8 Dec 2018 12:31:16 -0600 Subject: [PATCH 2/2] Fix world load/unload handling and chunk generate/populate events --- .../org/dynmap/forge_1_12_2/DynmapPlugin.java | 66 ++++++++----------- forge-1.12.2/src/main/resources/dynmap_at.cfg | 1 + 2 files changed, 28 insertions(+), 39 deletions(-) diff --git a/forge-1.12.2/src/main/java/org/dynmap/forge_1_12_2/DynmapPlugin.java b/forge-1.12.2/src/main/java/org/dynmap/forge_1_12_2/DynmapPlugin.java index f1257224..397c9e06 100644 --- a/forge-1.12.2/src/main/java/org/dynmap/forge_1_12_2/DynmapPlugin.java +++ b/forge-1.12.2/src/main/java/org/dynmap/forge_1_12_2/DynmapPlugin.java @@ -56,10 +56,15 @@ import net.minecraft.world.IWorldEventListener; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraft.world.biome.Biome; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.storage.ExtendedBlockStorage; import net.minecraftforge.common.ForgeChunkManager; import net.minecraftforge.common.ForgeChunkManager.Ticket; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.ServerChatEvent; +import net.minecraftforge.event.terraingen.PopulateChunkEvent; +import net.minecraftforge.event.world.ChunkEvent; +import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.ModContainer; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -1631,26 +1636,27 @@ public class DynmapPlugin } } - /**NOTYET - need rest of forge public class WorldTracker { @SubscribeEvent public void handleWorldLoad(WorldEvent.Load event) { if(!core_enabled) return; - if(!(event.world instanceof WorldServer)) return; - final ForgeWorld w = getWorld(event.world); + World w = event.getWorld(); + if(!(w instanceof WorldServer)) return; + final ForgeWorld fw = getWorld(w); // This event can be called from off server thread, so push processing there core.getServer().scheduleServerTask(new Runnable() { public void run() { - if(core.processWorldLoad(w)) // Have core process load first - fire event listeners if good load after - core.listenerManager.processWorldEvent(EventType.WORLD_LOAD, w); + if(core.processWorldLoad(fw)) // Have core process load first - fire event listeners if good load after + core.listenerManager.processWorldEvent(EventType.WORLD_LOAD, fw); } }, 0); } @SubscribeEvent public void handleWorldUnload(WorldEvent.Unload event) { if(!core_enabled) return; - if(!(event.world instanceof WorldServer)) return; - final ForgeWorld fw = getWorld(event.world); + World w = event.getWorld(); + if(!(w instanceof WorldServer)) return; + final ForgeWorld fw = getWorld(w); if(fw != null) { // This event can be called from off server thread, so push processing there core.getServer().scheduleServerTask(new Runnable() { @@ -1666,14 +1672,16 @@ public class DynmapPlugin if(wut != null) wut.world = null; } } + @SubscribeEvent public void handleChunkLoad(ChunkEvent.Load event) { if(!core_enabled) return; if(!onchunkgenerate) return; - if(!(event.world instanceof WorldServer)) return; + World w = event.getWorld(); + if(!(w instanceof WorldServer)) return; Chunk c = event.getChunk(); - if((c != null) && (c.lastSaveTime == 0)) { // If new chunk? - ForgeWorld fw = getWorld(event.world, false); + if((c != null) && (!c.isTerrainPopulated())) { // If new chunk? + ForgeWorld fw = getWorld(w, false); if(fw == null) { return; } @@ -1684,8 +1692,8 @@ public class DynmapPlugin ymax = 16*(i+1); } } - int x = c.xPosition << 4; - int z = c.zPosition << 4; + int x = c.x << 4; + int z = c.z << 4; if(ymax > 0) { mapManager.touchVolume(fw.getName(), x, 0, z, x+15, ymax, z+16, "chunkgenerate"); } @@ -1696,11 +1704,12 @@ public class DynmapPlugin public void handleChunkPopulate(PopulateChunkEvent.Post event) { if(!core_enabled) return; if(!onchunkpopulate) return; - if(!(event.world instanceof WorldServer)) return; - Chunk c = event.chunkProvider.loadChunk(event.chunkX, event.chunkZ); + World w = event.getWorld(); + if(!(w instanceof WorldServer)) return; + Chunk c = w.getChunkFromChunkCoords(event.getChunkX(), event.getChunkZ()); int ymin = 0, ymax = 0; if(c != null) { - ForgeWorld fw = getWorld(event.world, false); + ForgeWorld fw = getWorld(event.getWorld(), false); if (fw == null) return; ExtendedBlockStorage[] sections = c.getBlockStorageArray(); @@ -1709,30 +1718,13 @@ public class DynmapPlugin ymax = 16*(i+1); } } - int x = c.xPosition << 4; - int z = c.zPosition << 4; + int x = c.x << 4; + int z = c.z << 4; if(ymax > 0) mapManager.touchVolume(fw.getName(), x, ymin, z, x+15, ymax, z+16, "chunkpopulate"); } - } - - @SubscribeEvent - public void handleCommandEvent(CommandEvent event) { - if(event.isCanceled()) return; - if(event.command.getCommandName().equals("say")) { - String s = ""; - for(String p : event.parameters) { - s += p + " "; - } - s = s.trim(); - ChatMessage cm = new ChatMessage(); - cm.message = s; - cm.sender = null; - msgqueue.add(cm); - } - } + } } - */ private boolean onblockchange = false; private boolean onlightingchange = false; @@ -1803,19 +1795,15 @@ public class DynmapPlugin } } - /*NOTYET - need rest of forge private WorldTracker worldTracker = null; - */ private HashMap updateTrackers = new HashMap(); private void registerEvents() { - /*NOTYET - need rest of forge if(worldTracker == null) { worldTracker = new WorldTracker(); MinecraftForge.EVENT_BUS.register(worldTracker); } - */ // To trigger rendering. onblockchange = core.isTrigger("blockupdate"); onlightingchange = core.isTrigger("lightingupdate"); diff --git a/forge-1.12.2/src/main/resources/dynmap_at.cfg b/forge-1.12.2/src/main/resources/dynmap_at.cfg index 668f8fbf..e97eb6d8 100644 --- a/forge-1.12.2/src/main/resources/dynmap_at.cfg +++ b/forge-1.12.2/src/main/resources/dynmap_at.cfg @@ -1,3 +1,4 @@ public net.minecraft.world.gen.ChunkProviderServer field_73247_e # chunkLoader public net.minecraft.world.chunk.storage.AnvilChunkLoader field_75825_d # chunkSaveLocation public net.minecraft.world.biome.Biome field_76791_y # biomeName +public net.minecraft.world.chunk.Chunk field_76641_n # lastSaveTime