PaperSpigot-Parent/CraftBukkit-Patches/0118-Remove-the-lastChunkAccessed-if-it-is-unloaded.patch

61 lines
3.1 KiB
Diff

From 2317a818c043982fd266b38c53d737dbae4c0260 Mon Sep 17 00:00:00 2001
From: Thinkofdeath <thethinkofdeath@gmail.com>
Date: Tue, 18 Mar 2014 09:49:30 +0000
Subject: [PATCH] Remove the lastChunkAccessed if it is unloaded.
This fixes an issue where a chunk would be unloaded but remain in lastChunkAccessed meaning calls on getChunkAt could return a chunk that is no longer loaded, this caused an issue where the chunk could be reloaded whilst in use reverting any block changes. This caused findEndPortal to return null even after createEndPortal which would crash the server trying to teleport to a null location.
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index b669d05..33e4cff 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -316,6 +316,13 @@ public class ChunkProviderServer implements IChunkProvider {
long chunkcoordinates = this.unloadQueue.popFirst();
Chunk chunk = this.chunks.get(chunkcoordinates);
if (chunk == null) continue;
+ // Spigot start - Remove the chunk from the cache if it is unloaded
+ Chunk result = world.lastChunkAccessed;
+ if ( result != null && result.locX == chunk.locX && result.locZ == chunk.locZ )
+ {
+ world.lastChunkAccessed = null;
+ }
+ // Spigot end
ChunkUnloadEvent event = new ChunkUnloadEvent(chunk.bukkitChunk);
server.getPluginManager().callEvent(event);
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 40325bf..ca8d029 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -154,7 +154,7 @@ public abstract class World implements IBlockAccess {
public boolean pvpMode;
public boolean keepSpawnInMemory = true;
public ChunkGenerator generator;
- Chunk lastChunkAccessed;
+ public Chunk lastChunkAccessed; // Spigot - Make public
int lastXAccessed = Integer.MIN_VALUE;
int lastZAccessed = Integer.MIN_VALUE;
final Object chunkLock = new Object();
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 154b868..8592205 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -187,6 +187,14 @@ public class CraftWorld implements World {
world.chunkProviderServer.saveChunkNOP(chunk);
}
+ // Spigot start - Remove the chunk from the cache if it is unloaded
+ net.minecraft.server.Chunk result = world.lastChunkAccessed;
+ if ( result != null && result.locX == chunk.locX && result.locZ == chunk.locZ )
+ {
+ world.lastChunkAccessed = null;
+ }
+ // Spigot end
+
world.chunkProviderServer.unloadQueue.remove(x, z);
world.chunkProviderServer.chunks.remove(LongHash.toLong(x, z));
--
1.8.3.2