From aad4b6460333f354d2cc2419167197bc43e452a3 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sun, 19 Aug 2012 18:04:36 -0500 Subject: [PATCH] Set to 0.70.3 - fix for CB internals change in 1.3.1-R2.1 --- pom.xml | 2 +- .../org/dynmap/bukkit/NewMapChunkCache.java | 41 ++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 07847991..8f955971 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.dynmap dynmap - 0.80 + 0.70.3 dynmap UTF-8 diff --git a/src/main/java/org/dynmap/bukkit/NewMapChunkCache.java b/src/main/java/org/dynmap/bukkit/NewMapChunkCache.java index c1a8b74e..c9aa5c9e 100644 --- a/src/main/java/org/dynmap/bukkit/NewMapChunkCache.java +++ b/src/main/java/org/dynmap/bukkit/NewMapChunkCache.java @@ -1,10 +1,15 @@ package org.dynmap.bukkit; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.ListIterator; +import net.minecraft.server.ChunkProviderServer; + import org.bukkit.World; import org.bukkit.Chunk; import org.bukkit.block.Biome; @@ -28,6 +33,8 @@ import org.getspout.spoutapi.block.SpoutChunk; public class NewMapChunkCache implements MapChunkCache { private static boolean init = false; private static boolean use_spout = false; + private static Field unloadqueue = null; + private static Method queuecontainskey = null; private World w; private DynmapWorld dw; @@ -659,6 +666,21 @@ public class NewMapChunkCache implements MapChunkCache { if(!init) { use_spout = DynmapPlugin.plugin.hasSpout(); + try { + unloadqueue = ChunkProviderServer.class.getField("unloadQueue"); + Class cls = unloadqueue.getType(); + String nm = cls.getName(); + if (nm.equals("org.bukkit.craftbukkit.util.LongHashset")) { + queuecontainskey = unloadqueue.getType().getMethod("containsKey", new Class[] { int.class, int.class }); + } + else { + unloadqueue = null; + } + } catch (NoSuchFieldException nsfx) { + unloadqueue = null; + } catch (NoSuchMethodException nsmx) { + unloadqueue = null; + } init = true; } } @@ -709,7 +731,14 @@ public class NewMapChunkCache implements MapChunkCache { public int loadChunks(int max_to_load) { long t0 = System.nanoTime(); CraftWorld cw = (CraftWorld)w; - LongHashset unloadqueue = cw.getHandle().chunkProviderServer.unloadQueue; + Object queue = null; + try { + if (unloadqueue != null) { + queue = unloadqueue.get(cw.getHandle().chunkProviderServer); + } + } catch (IllegalArgumentException iax) { + } catch (IllegalAccessException e) { + } int cnt = 0; if(iterator == null) iterator = chunks.listIterator(); @@ -754,7 +783,15 @@ public class NewMapChunkCache implements MapChunkCache { chunks_attempted++; boolean wasLoaded = w.isChunkLoaded(chunk.x, chunk.z); boolean didload = false; - boolean isunloadpending = unloadqueue.containsKey(chunk.x, chunk.z); + boolean isunloadpending = false; + if (queue != null) { + try { + isunloadpending = (Boolean)queuecontainskey.invoke(queue, chunk.x, chunk.z); + } catch (IllegalAccessException iax) { + } catch (IllegalArgumentException e) { + } catch (InvocationTargetException e) { + } + } if (isunloadpending) { /* Workaround: can't be pending if not loaded */ wasLoaded = true; }