From 696349884b8f09430eba0c4a9847805e3e6c002c Mon Sep 17 00:00:00 2001 From: Tahg Date: Wed, 5 Oct 2011 11:31:23 -0400 Subject: [PATCH] don't store weak references for EmptyChunks or cache CraftBlocks --- src/main/java/net/minecraft/server/Chunk.java | 10 +++++--- .../org/bukkit/craftbukkit/CraftChunk.java | 25 ++++++------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java index 939fa69f90..82955f656a 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -56,10 +56,12 @@ public class Chunk { Arrays.fill(this.c, -999); // CraftBukkit start - org.bukkit.craftbukkit.CraftWorld cworld = this.world.getWorld(); - this.bukkitChunk = (cworld == null) ? null : cworld.popPreservedChunk(i, j); - if (this.bukkitChunk == null) { - this.bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this); + if (!(this instanceof EmptyChunk)) { + org.bukkit.craftbukkit.CraftWorld cworld = this.world.getWorld(); + this.bukkitChunk = (cworld == null) ? null : cworld.popPreservedChunk(i, j); + if (this.bukkitChunk == null) { + this.bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this); + } } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java index 543fb0e603..3e9fcac93b 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java @@ -1,10 +1,9 @@ package org.bukkit.craftbukkit; -import com.google.common.collect.MapMaker; import java.lang.ref.WeakReference; -import java.util.concurrent.ConcurrentMap; import net.minecraft.server.ChunkPosition; +import net.minecraft.server.EmptyChunk; import net.minecraft.server.WorldServer; import org.bukkit.Chunk; @@ -19,13 +18,14 @@ import net.minecraft.server.WorldChunkManager; public class CraftChunk implements Chunk { private WeakReference weakChunk; - private final ConcurrentMap cache = new MapMaker().softValues().makeMap(); private WorldServer worldServer; private int x; private int z; public CraftChunk(net.minecraft.server.Chunk chunk) { - this.weakChunk = new WeakReference(chunk); + if(!(chunk instanceof EmptyChunk)) { + this.weakChunk = new WeakReference(chunk); + } worldServer = (WorldServer) getHandle().world; x = getHandle().x; z = getHandle().z; @@ -39,7 +39,9 @@ public class CraftChunk implements Chunk { net.minecraft.server.Chunk c = weakChunk.get(); if (c == null) { c = worldServer.getChunkAt(x, z); - weakChunk = new WeakReference(c); + if(!(c instanceof EmptyChunk)) { + weakChunk = new WeakReference(c); + } } return c; } @@ -62,18 +64,7 @@ public class CraftChunk implements Chunk { } public Block getBlock(int x, int y, int z) { - int pos = (x & 0xF) << 11 | (z & 0xF) << 7 | (y & 0x7F); - 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; + return new CraftBlock(this, (getX() << 4) | (x & 0xF), y & 0x7F, (getZ() << 4) | (z & 0xF)); } public Entity[] getEntities() {