mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-04 14:04:49 +01:00
Prevent Blocks from getting lost when a chunk reloads
This commit is contained in:
parent
ca4076077e
commit
6e3ee31336
4 changed files with 21 additions and 2 deletions
|
@ -44,8 +44,11 @@ public class Chunk {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
|
bukkitChunk = ((WorldServer) world).getWorld().popPreservedChunk( i, j );
|
||||||
|
if (bukkitChunk == null) {
|
||||||
bukkitChunk = new org.bukkit.craftbukkit.CraftChunk( this );
|
bukkitChunk = new org.bukkit.craftbukkit.CraftChunk( this );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public org.bukkit.Chunk bukkitChunk;
|
public org.bukkit.Chunk bukkitChunk;
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
|
@ -209,6 +209,8 @@ public class ChunkProviderServer implements IChunkProvider
|
||||||
ChunkUnloadEvent cue = new ChunkUnloadEvent(Type.CHUNK_UNLOADED, chunk.bukkitChunk);
|
ChunkUnloadEvent cue = new ChunkUnloadEvent(Type.CHUNK_UNLOADED, chunk.bukkitChunk);
|
||||||
server.getPluginManager().callEvent(cue);
|
server.getPluginManager().callEvent(cue);
|
||||||
if (!cue.isCancelled()) {
|
if (!cue.isCancelled()) {
|
||||||
|
g.getWorld().preserveChunk( (CraftChunk) chunk.bukkitChunk );
|
||||||
|
|
||||||
chunk.e();
|
chunk.e();
|
||||||
this.b(chunk);
|
this.b(chunk);
|
||||||
this.a(chunk);
|
this.a(chunk);
|
||||||
|
|
|
@ -11,7 +11,7 @@ import org.bukkit.block.Block;
|
||||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||||
|
|
||||||
public class CraftChunk implements Chunk {
|
public class CraftChunk implements Chunk {
|
||||||
private final net.minecraft.server.Chunk chunk;
|
private net.minecraft.server.Chunk chunk;
|
||||||
private final HashMap<Integer, Block> cache = new HashMap<Integer, Block>();
|
private final HashMap<Integer, Block> cache = new HashMap<Integer, Block>();
|
||||||
|
|
||||||
public CraftChunk(net.minecraft.server.Chunk chunk) {
|
public CraftChunk(net.minecraft.server.Chunk chunk) {
|
||||||
|
@ -48,4 +48,8 @@ public class CraftChunk implements Chunk {
|
||||||
}
|
}
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void breakLink() {
|
||||||
|
this.chunk = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ public class CraftWorld implements World {
|
||||||
private final Environment environment;
|
private final Environment environment;
|
||||||
private final CraftServer server;
|
private final CraftServer server;
|
||||||
private final ChunkProviderServer provider;
|
private final ChunkProviderServer provider;
|
||||||
|
private HashMap<Integer,CraftChunk> unloadedChunks = new HashMap<Integer, CraftChunk>();
|
||||||
|
|
||||||
private static final Random rand = new Random();
|
private static final Random rand = new Random();
|
||||||
|
|
||||||
|
@ -45,6 +46,15 @@ public class CraftWorld implements World {
|
||||||
server.addWorld(this);
|
server.addWorld(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void preserveChunk( CraftChunk chunk ) {
|
||||||
|
chunk.breakLink();
|
||||||
|
unloadedChunks.put( chunk.getX() << 16 + chunk.getZ(), chunk );
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftChunk popPreservedChunk( int x, int z ) {
|
||||||
|
return unloadedChunks.remove( x << 16 + z );
|
||||||
|
}
|
||||||
|
|
||||||
public Block getBlockAt(int x, int y, int z) {
|
public Block getBlockAt(int x, int y, int z) {
|
||||||
return getChunkAt(x >> 4, z >> 4).getBlock(x & 0xF, y & 0x7F, z & 0xF);
|
return getChunkAt(x >> 4, z >> 4).getBlock(x & 0xF, y & 0x7F, z & 0xF);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue