diff options
author | VictorD <victor.danell@gmail.com> | 2011-02-20 23:22:28 +0100 |
---|---|---|
committer | VictorD <victor.danell@gmail.com> | 2011-02-20 23:22:28 +0100 |
commit | bf9a55049e6be249856d07b1bda99552b0f902f7 (patch) | |
tree | 86f93e2b9bdf6dac7403fbd5edba065bdc36aa45 /src/main/java/org | |
parent | cec04a7360ef0baf7dfdc3cc2af2be02c54403c9 (diff) | |
download | craftbukkit-bf9a55049e6be249856d07b1bda99552b0f902f7.tar craftbukkit-bf9a55049e6be249856d07b1bda99552b0f902f7.tar.gz craftbukkit-bf9a55049e6be249856d07b1bda99552b0f902f7.tar.lz craftbukkit-bf9a55049e6be249856d07b1bda99552b0f902f7.tar.xz craftbukkit-bf9a55049e6be249856d07b1bda99552b0f902f7.zip |
Second part of NPE and arctan update :3
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftChunk.java | 31 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftWorld.java | 5 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/TrigMath.java | 3 |
3 files changed, 24 insertions, 15 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java index 592e1203..c9469f5d 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit; +import java.lang.ref.WeakReference; import java.util.HashMap; import net.minecraft.server.WorldServer; @@ -11,27 +12,38 @@ import org.bukkit.block.Block; import org.bukkit.craftbukkit.block.CraftBlock; public class CraftChunk implements Chunk { - private net.minecraft.server.Chunk chunk; + private WeakReference<net.minecraft.server.Chunk> weakChunk; private final HashMap<Integer, Block> cache = new HashMap<Integer, Block>(); - + private WorldServer worldServer; + private int x; + private int z; + public CraftChunk(net.minecraft.server.Chunk chunk) { - this.chunk = chunk; + this.weakChunk = new WeakReference<net.minecraft.server.Chunk>(chunk); + worldServer = (WorldServer) getHandle().d; + x = getHandle().j; + z = getHandle().k; } public World getWorld() { - return ((WorldServer) chunk.d).getWorld(); + return worldServer.getWorld(); } public net.minecraft.server.Chunk getHandle() { - return chunk; + net.minecraft.server.Chunk c = weakChunk.get(); + if (c == null) { + weakChunk = new WeakReference<net.minecraft.server.Chunk>(worldServer.c(x,z)); + c = weakChunk.get(); + } + return c; } public int getX() { - return chunk.j; + return x; } public int getZ() { - return chunk.k; + return z; } @Override @@ -48,8 +60,5 @@ public class CraftChunk implements Chunk { } return block; } - - public void breakLink() { - this.chunk = null; - } } + diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 2f3fe705..aca52517 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -47,12 +47,11 @@ public class CraftWorld implements World { } public void preserveChunk( CraftChunk chunk ) { - chunk.breakLink(); - unloadedChunks.put( chunk.getX() << 16 + chunk.getZ(), chunk ); + unloadedChunks.put( (chunk.getX() << 16) + chunk.getZ(), chunk ); } public CraftChunk popPreservedChunk( int x, int z ) { - return unloadedChunks.remove( x << 16 + z ); + return unloadedChunks.remove( (x << 16) + z ); } public Block getBlockAt(int x, int y, int z) { diff --git a/src/main/java/org/bukkit/craftbukkit/TrigMath.java b/src/main/java/org/bukkit/craftbukkit/TrigMath.java index 0d207b37..2a623bf0 100644 --- a/src/main/java/org/bukkit/craftbukkit/TrigMath.java +++ b/src/main/java/org/bukkit/craftbukkit/TrigMath.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit; /** - * Got this code from a post by user aioobe on stackoverflow.com + * Credits for this class goes to user aioobe on stackoverflow.com + * Source: http://stackoverflow.com/questions/4454630/j2me-calculate-the-the-distance-between-2-latitude-and-longitude * */ public class TrigMath { |