diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index db294e957..b01a2522e 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -190,12 +190,6 @@ public boolean rawSetBlock(Vector pt, BaseBlock block) { return false; } - if (mask != null) { - if (!mask.matches(this, pt)) { - return false; - } - } - final int existing = world.getBlockType(pt); // Clear the container block so that it doesn't drop items @@ -259,6 +253,12 @@ public boolean setBlock(Vector pt, BaseBlock block) throws MaxChangedBlocksException { BlockVector blockPt = pt.toBlockVector(); + if (mask != null) { + if (!mask.matches(this, blockPt)) { + return false; + } + } + // if (!original.containsKey(blockPt)) { original.put(blockPt, getBlock(pt)); diff --git a/src/main/java/com/sk89q/worldedit/commands/SnapshotUtilCommands.java b/src/main/java/com/sk89q/worldedit/commands/SnapshotUtilCommands.java index cfeb5e430..7dde042b2 100644 --- a/src/main/java/com/sk89q/worldedit/commands/SnapshotUtilCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/SnapshotUtilCommands.java @@ -140,10 +140,10 @@ public void restore(CommandContext args, LocalSession session, LocalPlayer playe try { // Restore snapshot - SnapshotRestore restore = new SnapshotRestore(chunkStore, region); + SnapshotRestore restore = new SnapshotRestore(chunkStore, editSession, region); //player.print(restore.getChunksAffected() + " chunk(s) will be loaded."); - restore.restore(editSession); + restore.restore(); if (restore.hadTotalFailure()) { String error = restore.getLastErrorMessage(); diff --git a/src/main/java/com/sk89q/worldedit/snapshots/SnapshotRestore.java b/src/main/java/com/sk89q/worldedit/snapshots/SnapshotRestore.java index 4b20aabe4..5f76d3c35 100644 --- a/src/main/java/com/sk89q/worldedit/snapshots/SnapshotRestore.java +++ b/src/main/java/com/sk89q/worldedit/snapshots/SnapshotRestore.java @@ -47,12 +47,16 @@ public class SnapshotRestore { /** * Store a list of chunks that are needed and the points in them. */ - private Map> neededChunks = + private final Map> neededChunks = new LinkedHashMap>(); /** * Chunk store. */ - private ChunkStore chunkStore; + private final ChunkStore chunkStore; + /** + * Edit session. + */ + private final EditSession editSession; /** * Count of the number of missing chunks. */ @@ -69,11 +73,13 @@ public class SnapshotRestore { /** * Construct the snapshot restore operation. * - * @param chunkStore - * @param region + * @param chunkStore The {@link ChunkStore} to restore from + * @param editSession The {@link EditSession} to restore to + * @param region The {@link Region} to restore to */ - public SnapshotRestore(ChunkStore chunkStore, Region region) { + public SnapshotRestore(ChunkStore chunkStore, EditSession editSession, Region region) { this.chunkStore = chunkStore; + this.editSession = editSession; if (region instanceof CuboidRegion) { findNeededCuboidChunks(region); @@ -83,9 +89,9 @@ public SnapshotRestore(ChunkStore chunkStore, Region region) { } /** - * Find needed chunks in the cuboid of the region. + * Find needed chunks in the axis-aligned bounding box of the region. * - * @param region + * @param region The {@link Region} to iterate */ private void findNeededCuboidChunks(Region region) { Vector min = region.getMinimumPoint(); @@ -97,14 +103,7 @@ private void findNeededCuboidChunks(Region region) { for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) { for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) { Vector pos = new Vector(x, y, z); - BlockVector2D chunkPos = ChunkStore.toChunk(pos); - - // Unidentified chunk - if (!neededChunks.containsKey(chunkPos)) { - neededChunks.put(chunkPos, new ArrayList()); - } - - neededChunks.get(chunkPos).add(pos); + checkAndAddBlock(pos); } } } @@ -113,23 +112,30 @@ private void findNeededCuboidChunks(Region region) { /** * Find needed chunks in the region. * - * @param region + * @param region The {@link Region} to iterate */ private void findNeededChunks(Region region) { // First, we need to group points by chunk so that we only need // to keep one chunk in memory at any given moment for (Vector pos : region) { - BlockVector2D chunkPos = ChunkStore.toChunk(pos); - - // Unidentified chunk - if (!neededChunks.containsKey(chunkPos)) { - neededChunks.put(chunkPos, new ArrayList()); - } - - neededChunks.get(chunkPos).add(pos); + checkAndAddBlock(pos); } } + private void checkAndAddBlock(Vector pos) { + if (editSession.getMask() != null && !editSession.getMask().matches(editSession, pos)) + return; + + BlockVector2D chunkPos = ChunkStore.toChunk(pos); + + // Unidentified chunk + if (!neededChunks.containsKey(chunkPos)) { + neededChunks.put(chunkPos, new ArrayList()); + } + + neededChunks.get(chunkPos).add(pos); + } + /** * Get the number of chunks that are needed. * @@ -142,11 +148,9 @@ public int getChunksAffected() { /** * Restores to world. * - * @param editSession * @throws MaxChangedBlocksException */ - public void restore(EditSession editSession) - throws MaxChangedBlocksException { + public void restore() throws MaxChangedBlocksException { missingChunks = new ArrayList(); errorChunks = new ArrayList();