From bc6315fb247e2cfc3398cd52a44f71cfe0dd5ae9 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Mon, 29 Aug 2011 17:31:08 -0700 Subject: [PATCH] Fixed getting and setting of blocks in unloaded chunks --- src/main/java/com/sk89q/worldedit/EditSession.java | 4 ++++ src/main/java/com/sk89q/worldedit/LocalWorld.java | 7 +++++++ src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 8993e72a1..9fd43d5f9 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -162,6 +162,8 @@ public class EditSession { return false; } + world.checkLoadedChuck(pt); + // No invalid blocks if (!world.isValidBlockType(type)) { return false; @@ -414,6 +416,8 @@ public class EditSession { * @return BaseBlock */ public BaseBlock rawGetBlock(Vector pt) { + world.checkLoadedChuck(pt); + int type = world.getBlockType(pt); int data = world.getBlockData(pt); diff --git a/src/main/java/com/sk89q/worldedit/LocalWorld.java b/src/main/java/com/sk89q/worldedit/LocalWorld.java index dd0ff5852..1e71370bf 100644 --- a/src/main/java/com/sk89q/worldedit/LocalWorld.java +++ b/src/main/java/com/sk89q/worldedit/LocalWorld.java @@ -349,6 +349,13 @@ public abstract class LocalWorld { return type >= 0 && type < 96; } + /** + * Checks if the chunk pt is in is loaded. if not, loads the chunk + * + * @param pt Position to check + */ + public abstract void checkLoadedChuck(Vector pt); + /** * Compare if the other world is equal. * diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 628f831ee..2584ee4c3 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -673,6 +673,13 @@ public class BukkitWorld extends LocalWorld { return type <= 255 && Material.getMaterial(type) != null; } + @Override + public void checkLoadedChuck(Vector pt) { + if (!world.isChunkLoaded(pt.getBlockX() >> 4, pt.getBlockZ() >> 4)) { + world.loadChunk(pt.getBlockX() >> 4, pt.getBlockZ() >> 4); + } + } + @Override public boolean equals(Object other) { if (!(other instanceof BukkitWorld)) {