diff --git a/src/main/java/com/sk89q/worldedit/masks/BlockMask.java b/src/main/java/com/sk89q/worldedit/masks/BlockMask.java
index ee52d511a..692501ad7 100644
--- a/src/main/java/com/sk89q/worldedit/masks/BlockMask.java
+++ b/src/main/java/com/sk89q/worldedit/masks/BlockMask.java
@@ -1,6 +1,7 @@
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
+import com.sk89q.worldedit.Extent;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
@@ -8,7 +9,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
-public class BlockMask extends AbstractMask {
+public class BlockMask extends ExtentAwareMask {
private final Set blocks;
@@ -42,7 +43,8 @@ public class BlockMask extends AbstractMask {
@Override
public boolean matches(EditSession editSession, Vector pos) {
- BaseBlock block = editSession.getBlock(pos);
+ Extent extent = getExtent(editSession);
+ BaseBlock block = extent.getBlock(pos);
return blocks.contains(block)
|| blocks.contains(new BaseBlock(block.getType(), -1));
}
diff --git a/src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java b/src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java
index ea9e8f448..8a536195f 100644
--- a/src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java
+++ b/src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java
@@ -23,9 +23,9 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID;
-public class ExistingBlockMask extends AbstractMask {
+public class ExistingBlockMask extends ExtentAwareMask {
@Override
public boolean matches(EditSession editSession, Vector pos) {
- return editSession.getBlockType(pos) != BlockID.AIR;
+ return getExtent(editSession).getBlockType(pos) != BlockID.AIR;
}
}
diff --git a/src/main/java/com/sk89q/worldedit/masks/ExtentAwareMask.java b/src/main/java/com/sk89q/worldedit/masks/ExtentAwareMask.java
new file mode 100644
index 000000000..4b86f9d25
--- /dev/null
+++ b/src/main/java/com/sk89q/worldedit/masks/ExtentAwareMask.java
@@ -0,0 +1,71 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q
+ * Copyright (C) WorldEdit team and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.sk89q.worldedit.masks;
+
+import com.sk89q.worldedit.EditSession;
+import com.sk89q.worldedit.Extent;
+
+/**
+ * Extended by masks to make them potentially use an {@link Extent} rather than
+ * the {@link EditSession}.
+ *
+ * At the moment, masks are coupled to {@link EditSession} when they should
+ * not be. However, because a change to {@link Mask} would cause massive breakage in
+ * the API, that change is deferred until further notice and this class exists as
+ * an opt-in mixin for adding support for {@link Extent}s.
+ */
+public abstract class ExtentAwareMask extends AbstractMask {
+
+ private Extent extent;
+
+ /**
+ * Get the extent that will be used for lookups.
+ *
+ * @return the extent, or null if the {@link EditSession} is to be used
+ */
+ public Extent getExtent() {
+ return extent;
+ }
+
+ /**
+ * Set the extent that will be used for lookups.
+ *
+ * @param extent the extent, or null if the {@link EditSession} is to be used
+ */
+ public void setExtent(Extent extent) {
+ this.extent = extent;
+ }
+
+ /**
+ * Get the extent to use for operations. Subclasses should call this method
+ * rather than access the passed {@link EditSession} directly.
+ *
+ * @param editSession the passed in {@link EditSession}
+ * @return an extent
+ */
+ protected Extent getExtent(EditSession editSession) {
+ if (extent != null) {
+ return extent;
+ } else {
+ return editSession;
+ }
+ }
+
+}
diff --git a/src/main/java/com/sk89q/worldedit/masks/FuzzyBlockMask.java b/src/main/java/com/sk89q/worldedit/masks/FuzzyBlockMask.java
index 4b34aab89..fe35ec30f 100644
--- a/src/main/java/com/sk89q/worldedit/masks/FuzzyBlockMask.java
+++ b/src/main/java/com/sk89q/worldedit/masks/FuzzyBlockMask.java
@@ -20,6 +20,7 @@
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
+import com.sk89q.worldedit.Extent;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
@@ -30,7 +31,7 @@ import java.util.Set;
* Uses {@link BaseBlock#containsFuzzy(java.util.Collection, BaseBlock)} to
* match blocks.
*/
-public class FuzzyBlockMask extends AbstractMask {
+public class FuzzyBlockMask extends ExtentAwareMask {
private final Set filter;
@@ -58,7 +59,8 @@ public class FuzzyBlockMask extends AbstractMask {
@Override
public boolean matches(EditSession editSession, Vector pos) {
- BaseBlock compare = new BaseBlock(editSession.getBlockType(pos), editSession.getBlockData(pos));
+ Extent extent = getExtent(editSession);
+ BaseBlock compare = new BaseBlock(extent.getBlockType(pos), extent.getBlockData(pos));
return BaseBlock.containsFuzzy(filter, compare);
}
}
diff --git a/src/main/java/com/sk89q/worldedit/masks/Mask.java b/src/main/java/com/sk89q/worldedit/masks/Mask.java
index d5a448736..ce18cbece 100644
--- a/src/main/java/com/sk89q/worldedit/masks/Mask.java
+++ b/src/main/java/com/sk89q/worldedit/masks/Mask.java
@@ -48,8 +48,8 @@ public interface Mask {
* that position matches the filter. Block information is not provided
* as getting a BaseBlock has unneeded overhead in most block querying
* situations (enumerating a chest's contents is a waste, for example).
- *
- * @param editSession
+ *
+ * @param editSession
* @param pos
* @return
*/
diff --git a/src/main/java/com/sk89q/worldedit/masks/SolidBlockMask.java b/src/main/java/com/sk89q/worldedit/masks/SolidBlockMask.java
index f78170efc..9414cfaf8 100644
--- a/src/main/java/com/sk89q/worldedit/masks/SolidBlockMask.java
+++ b/src/main/java/com/sk89q/worldedit/masks/SolidBlockMask.java
@@ -1,15 +1,17 @@
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
+import com.sk89q.worldedit.Extent;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockType;
/**
* Works like {@link ExistingBlockMask}, except also dealing with non-solid non-air blocks the same way as with air.
*/
-public class SolidBlockMask extends AbstractMask {
+public class SolidBlockMask extends ExtentAwareMask {
@Override
public boolean matches(EditSession editSession, Vector pos) {
- return !BlockType.canPassThrough(editSession.getBlockType(pos), editSession.getBlockData(pos));
+ Extent extent = getExtent(editSession);
+ return !BlockType.canPassThrough(extent.getBlockType(pos), extent.getBlockData(pos));
}
}
diff --git a/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java b/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java
index 7c77a75da..d7cf29da9 100644
--- a/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java
+++ b/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java
@@ -21,17 +21,14 @@ package com.sk89q.worldedit.masks;
import java.util.Set;
-import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.LocalPlayer;
-import com.sk89q.worldedit.LocalSession;
-import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
*
* @author 1337
*/
-public class UnderOverlayMask extends AbstractMask {
+public class UnderOverlayMask extends ExtentAwareMask {
private final int yMod;
private Mask mask;
@@ -68,6 +65,7 @@ public class UnderOverlayMask extends AbstractMask {
@Override
public boolean matches(EditSession editSession, Vector pos) {
- return !mask.matches(editSession, pos) && mask.matches(editSession, pos.add(0, yMod, 0));
+ Extent extent = getExtent(editSession);
+ return !mask.matches(extent, pos) && mask.matches(extent, pos.add(0, yMod, 0));
}
}