Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-20 21:40:06 +01:00
don't store weak references for EmptyChunks or cache CraftBlocks
Dieser Commit ist enthalten in:
Ursprung
8ab90b344c
Commit
696349884b
@ -56,10 +56,12 @@ public class Chunk {
|
|||||||
Arrays.fill(this.c, -999);
|
Arrays.fill(this.c, -999);
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
org.bukkit.craftbukkit.CraftWorld cworld = this.world.getWorld();
|
if (!(this instanceof EmptyChunk)) {
|
||||||
this.bukkitChunk = (cworld == null) ? null : cworld.popPreservedChunk(i, j);
|
org.bukkit.craftbukkit.CraftWorld cworld = this.world.getWorld();
|
||||||
if (this.bukkitChunk == null) {
|
this.bukkitChunk = (cworld == null) ? null : cworld.popPreservedChunk(i, j);
|
||||||
this.bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
|
if (this.bukkitChunk == null) {
|
||||||
|
this.bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package org.bukkit.craftbukkit;
|
package org.bukkit.craftbukkit;
|
||||||
|
|
||||||
import com.google.common.collect.MapMaker;
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
import net.minecraft.server.ChunkPosition;
|
import net.minecraft.server.ChunkPosition;
|
||||||
|
|
||||||
|
import net.minecraft.server.EmptyChunk;
|
||||||
import net.minecraft.server.WorldServer;
|
import net.minecraft.server.WorldServer;
|
||||||
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
@ -19,13 +18,14 @@ import net.minecraft.server.WorldChunkManager;
|
|||||||
|
|
||||||
public class CraftChunk implements Chunk {
|
public class CraftChunk implements Chunk {
|
||||||
private WeakReference<net.minecraft.server.Chunk> weakChunk;
|
private WeakReference<net.minecraft.server.Chunk> weakChunk;
|
||||||
private final ConcurrentMap<Integer, Block> cache = new MapMaker().softValues().makeMap();
|
|
||||||
private WorldServer worldServer;
|
private WorldServer worldServer;
|
||||||
private int x;
|
private int x;
|
||||||
private int z;
|
private int z;
|
||||||
|
|
||||||
public CraftChunk(net.minecraft.server.Chunk chunk) {
|
public CraftChunk(net.minecraft.server.Chunk chunk) {
|
||||||
this.weakChunk = new WeakReference<net.minecraft.server.Chunk>(chunk);
|
if(!(chunk instanceof EmptyChunk)) {
|
||||||
|
this.weakChunk = new WeakReference<net.minecraft.server.Chunk>(chunk);
|
||||||
|
}
|
||||||
worldServer = (WorldServer) getHandle().world;
|
worldServer = (WorldServer) getHandle().world;
|
||||||
x = getHandle().x;
|
x = getHandle().x;
|
||||||
z = getHandle().z;
|
z = getHandle().z;
|
||||||
@ -39,7 +39,9 @@ public class CraftChunk implements Chunk {
|
|||||||
net.minecraft.server.Chunk c = weakChunk.get();
|
net.minecraft.server.Chunk c = weakChunk.get();
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
c = worldServer.getChunkAt(x, z);
|
c = worldServer.getChunkAt(x, z);
|
||||||
weakChunk = new WeakReference<net.minecraft.server.Chunk>(c);
|
if(!(c instanceof EmptyChunk)) {
|
||||||
|
weakChunk = new WeakReference<net.minecraft.server.Chunk>(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@ -62,18 +64,7 @@ public class CraftChunk implements Chunk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Block getBlock(int x, int y, int z) {
|
public Block getBlock(int x, int y, int z) {
|
||||||
int pos = (x & 0xF) << 11 | (z & 0xF) << 7 | (y & 0x7F);
|
return new CraftBlock(this, (getX() << 4) | (x & 0xF), y & 0x7F, (getZ() << 4) | (z & 0xF));
|
||||||
Block block = this.cache.get(pos);
|
|
||||||
if (block == null) {
|
|
||||||
Block newBlock = new CraftBlock(this, (getX() << 4) | (x & 0xF), y & 0x7F, (getZ() << 4) | (z & 0xF));
|
|
||||||
Block oldBlock = this.cache.put(pos, newBlock);
|
|
||||||
if (oldBlock == null) {
|
|
||||||
block = newBlock;
|
|
||||||
} else {
|
|
||||||
block = oldBlock;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return block;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entity[] getEntities() {
|
public Entity[] getEntities() {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren