From 60bfde2f20cab9fade83e6f34af2a2ee5ed168c9 Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 7 Mar 2013 20:12:46 +1100 Subject: [PATCH] Thread safety. Adds thread safety for chunk load / unload methods. --- src/main/java/org/bukkit/craftbukkit/CraftWorld.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 9343d46..b569dc4 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -232,6 +232,7 @@ public class CraftWorld implements World { } public boolean unloadChunkRequest(int x, int z, boolean safe) { + if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous chunk unload!"); if (safe && isChunkInUse(x, z)) { return false; } @@ -242,6 +243,7 @@ public class CraftWorld implements World { } public boolean unloadChunk(int x, int z, boolean save, boolean safe) { + if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous chunk unload!"); if (safe && isChunkInUse(x, z)) { return false; } @@ -309,6 +311,7 @@ public class CraftWorld implements World { } public boolean loadChunk(int x, int z, boolean generate) { + if (Thread.currentThread() != MinecraftServer.getServer().primaryThread) throw new IllegalStateException("Asynchronous chunk load!"); chunkLoadCount++; if (generate) { // Use the default variant of loadChunk when generate == true. -- 1.8.1-rc2