diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java index e013923f8e..9c19a218a6 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java @@ -36,12 +36,16 @@ public class CraftChunk implements Chunk { public net.minecraft.server.Chunk getHandle() { net.minecraft.server.Chunk c = weakChunk.get(); if (c == null) { - weakChunk = new WeakReference(worldServer.c(x,z)); - c = weakChunk.get(); + c = worldServer.c(x,z); + weakChunk = new WeakReference(c); } return c; } + void breakLink() { + weakChunk.clear(); + } + public int getX() { return x; } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 2dda576593..2fab5cdca2 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -45,6 +45,7 @@ public class CraftWorld implements World { } public void preserveChunk( CraftChunk chunk ) { + chunk.breakLink(); unloadedChunks.put( (chunk.getX() << 16) + chunk.getZ(), chunk ); } @@ -141,6 +142,7 @@ public class CraftWorld implements World { provider.a(chunk); } + preserveChunk((CraftChunk)chunk.bukkitChunk); provider.a.remove(x, z); provider.e.remove(x, z); provider.f.remove(chunk);