From 5b7b46593cbdee284ad27a0360e5bd18b9b360d6 Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Thu, 28 Jul 2011 00:32:58 -0400 Subject: [PATCH] Added various utility methods to make chunk handling easier. Thanks Meaglin! --- .../org/bukkit/craftbukkit/CraftChunk.java | 26 ++++++++++++++++++- .../org/bukkit/craftbukkit/CraftWorld.java | 4 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java index cf99b8dc77..adea00a116 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java @@ -109,6 +109,30 @@ public class CraftChunk implements Chunk { return entities; } + public boolean isLoaded() { + return getWorld().isChunkLoaded(this); + } + + public boolean load() { + return getWorld().loadChunk(getX(), getZ(), true); + } + + public boolean load(boolean generate) { + return getWorld().loadChunk(getX(), getZ(), generate); + } + + public boolean unload() { + return getWorld().unloadChunk(getX(), getZ()); + } + + public boolean unload(boolean save) { + return getWorld().unloadChunk(getX(), getZ(), save); + } + + public boolean unload(boolean save, boolean safe) { + return getWorld().unloadChunk(getX(), getZ(), save, safe); + } + public ChunkSnapshot getChunkSnapshot() { return getChunkSnapshot(true, false, false); } @@ -200,4 +224,4 @@ public class CraftChunk implements Chunk { } return new EmptyChunkSnapshot(x, z, world.getName(), world.getFullTime(), biome, biomeTemp, biomeRain); } -} \ No newline at end of file +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 7acb5aa15c..74e48d6217 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -120,6 +120,10 @@ public class CraftWorld implements World { loadChunk(x, z, true); } + public boolean unloadChunk(Chunk chunk) { + return unloadChunk(chunk.getX(), chunk.getZ()); + } + public boolean unloadChunk(int x, int z) { return unloadChunk(x, z, true); }