From 3674ba378600e854c8f9296aff0777ba64175897 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Fri, 24 Jun 2011 19:10:10 -0500 Subject: [PATCH] Add support for now-functional chunk generate detection (chunkgenerated render trigger) --- configuration.txt | 1 + src/main/java/org/dynmap/DynmapPlugin.java | 48 ++++++++++++++++------ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/configuration.txt b/configuration.txt index 085b27cb..a91b3945 100644 --- a/configuration.txt +++ b/configuration.txt @@ -89,6 +89,7 @@ render-triggers: - snowform - leavesdecay - blockburn + - chunkgenerated # The path where the tile-files are placed. tilespath: web/tiles diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 1d58600a..e349e7f3 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -52,6 +52,7 @@ public class DynmapPlugin extends JavaPlugin { public Events events = new Events(); /* Flag to let code know that we're doing reload - make sure we don't double-register event handlers */ public boolean is_reload = false; + private boolean generate_only = false; public static File dataDirectory; public static File tilesDirectory; @@ -247,21 +248,44 @@ public class DynmapPlugin extends JavaPlugin { WorldListener renderTrigger = new WorldListener() { @Override public void onChunkLoad(ChunkLoadEvent event) { - int x = event.getChunk().getX() * 16 + 8; - int z = event.getChunk().getZ() * 16 + 8; - mm.touch(new Location(event.getWorld(), x, 127, z)); + if(generate_only) { + if(!isNewChunk(event)) + return; + /* Touch extreme corners */ + int x = event.getChunk().getX() * 16; + int z = event.getChunk().getZ() * 16; + mm.touch(new Location(event.getWorld(), x, 0, z)); + mm.touch(new Location(event.getWorld(), x+15, 127, z)); + mm.touch(new Location(event.getWorld(), x+15, 0, z+15)); + mm.touch(new Location(event.getWorld(), x, 127, z+15)); + } + else { + int x = event.getChunk().getX() * 16 + 8; + int z = event.getChunk().getZ() * 16 + 8; + mm.touch(new Location(event.getWorld(), x, 127, z)); + } + } + private boolean isNewChunk(ChunkLoadEvent event) { + return event.isNewChunk(); } - - /* - * @Override public void onChunkGenerated(ChunkLoadEvent event) - * { int x = event.getChunk().getX() * 16 + 8; int z = - * event.getChunk().getZ() * 16 + 8; mm.touch(new - * Location(event.getWorld(), x, 127, z)); } - */ }; - if (isTrigger("chunkloaded")) + boolean ongenerate = isTrigger("chunkgenerated"); + if(ongenerate) { + try { /* Test if new enough bukkit to allow this */ + ChunkLoadEvent.class.getDeclaredMethod("isNewChunk", new Class[0]); + } catch (NoSuchMethodException nsmx) { + Log.info("Warning: CraftBukkit build does not support function needed for 'chunkgenerated' trigger - disabling"); + ongenerate = false; + } + } + if(isTrigger("chunkloaded")) { + generate_only = false; pm.registerEvent(org.bukkit.event.Event.Type.CHUNK_LOAD, renderTrigger, org.bukkit.event.Event.Priority.Monitor, this); - //if (isTrigger("chunkgenerated")) pm.registerEvent(Event.Type.CHUNK_GENERATED, renderTrigger, Priority.Monitor, this); + } + else if(ongenerate) { + generate_only = true; + pm.registerEvent(org.bukkit.event.Event.Type.CHUNK_LOAD, renderTrigger, org.bukkit.event.Event.Priority.Monitor, this); + } } // To link configuration to real loaded worlds.