From 02de3209807b28c8ba7f1b9096549994ced38209 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sat, 19 Oct 2013 11:43:01 +0200 Subject: [PATCH 1/2] Introduced AbstractMask as a superclass to all implementors of the Mask interface. --- .../java/com/sk89q/worldedit/masks/AbstractMask.java | 11 +++++++++++ .../java/com/sk89q/worldedit/masks/BiomeTypeMask.java | 7 +------ .../java/com/sk89q/worldedit/masks/BlockMask.java | 7 +------ .../java/com/sk89q/worldedit/masks/CombinedMask.java | 2 +- .../com/sk89q/worldedit/masks/ExistingBlockMask.java | 7 +------ .../java/com/sk89q/worldedit/masks/InvertedMask.java | 2 +- src/main/java/com/sk89q/worldedit/masks/Mask.java | 4 +++- .../java/com/sk89q/worldedit/masks/RandomMask.java | 8 +------- .../java/com/sk89q/worldedit/masks/RegionMask.java | 7 +------ .../com/sk89q/worldedit/masks/UnderOverlayMask.java | 2 +- 10 files changed, 22 insertions(+), 35 deletions(-) create mode 100644 src/main/java/com/sk89q/worldedit/masks/AbstractMask.java diff --git a/src/main/java/com/sk89q/worldedit/masks/AbstractMask.java b/src/main/java/com/sk89q/worldedit/masks/AbstractMask.java new file mode 100644 index 000000000..0be57ccab --- /dev/null +++ b/src/main/java/com/sk89q/worldedit/masks/AbstractMask.java @@ -0,0 +1,11 @@ +package com.sk89q.worldedit.masks; + +import com.sk89q.worldedit.LocalPlayer; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.Vector; + +public abstract class AbstractMask implements Mask { + @Override + public void prepare(LocalSession session, LocalPlayer player, Vector target) { + } +} diff --git a/src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java b/src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java index d86ac3334..c7d36e92b 100644 --- a/src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/BiomeTypeMask.java @@ -5,12 +5,10 @@ import java.util.Set; import com.sk89q.worldedit.BiomeType; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector2D; -public class BiomeTypeMask implements Mask { +public class BiomeTypeMask extends AbstractMask { private final Set biomes; public BiomeTypeMask() { @@ -21,9 +19,6 @@ public class BiomeTypeMask implements Mask { this.biomes = biomes; } - public void prepare(LocalSession session, LocalPlayer player, Vector target) { - } - public boolean matches2D(EditSession editSession, Vector2D pos) { BiomeType biome = editSession.getWorld().getBiome(pos); return biomes.contains(biome); diff --git a/src/main/java/com/sk89q/worldedit/masks/BlockMask.java b/src/main/java/com/sk89q/worldedit/masks/BlockMask.java index 95bca93c2..e852a9990 100644 --- a/src/main/java/com/sk89q/worldedit/masks/BlockMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/BlockMask.java @@ -5,12 +5,10 @@ import java.util.HashSet; 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.blocks.BaseBlock; -public class BlockMask implements Mask { +public class BlockMask extends AbstractMask { private final Set blocks; public BlockMask() { @@ -34,9 +32,6 @@ public class BlockMask implements Mask { blocks.addAll(blocks); } - public void prepare(LocalSession session, LocalPlayer player, Vector target) { - } - @Override public boolean matches(EditSession editSession, Vector pos) { BaseBlock block = editSession.getBlock(pos); diff --git a/src/main/java/com/sk89q/worldedit/masks/CombinedMask.java b/src/main/java/com/sk89q/worldedit/masks/CombinedMask.java index 148557830..fb12c8246 100644 --- a/src/main/java/com/sk89q/worldedit/masks/CombinedMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/CombinedMask.java @@ -26,7 +26,7 @@ import com.sk89q.worldedit.LocalPlayer; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.Vector; -public class CombinedMask implements Mask { +public class CombinedMask extends AbstractMask { private final List masks = new ArrayList(); public CombinedMask() { diff --git a/src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java b/src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java index d32de39fa..ea9e8f448 100644 --- a/src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/ExistingBlockMask.java @@ -20,15 +20,10 @@ package com.sk89q.worldedit.masks; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BlockID; -public class ExistingBlockMask implements Mask { - public void prepare(LocalSession session, LocalPlayer player, Vector target) { - } - +public class ExistingBlockMask extends AbstractMask { @Override public boolean matches(EditSession editSession, Vector pos) { return editSession.getBlockType(pos) != BlockID.AIR; diff --git a/src/main/java/com/sk89q/worldedit/masks/InvertedMask.java b/src/main/java/com/sk89q/worldedit/masks/InvertedMask.java index e58db6ed3..9ffc5213e 100644 --- a/src/main/java/com/sk89q/worldedit/masks/InvertedMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/InvertedMask.java @@ -5,7 +5,7 @@ import com.sk89q.worldedit.LocalPlayer; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.Vector; -public class InvertedMask implements Mask { +public class InvertedMask extends AbstractMask { private final Mask mask; public InvertedMask(Mask mask) { diff --git a/src/main/java/com/sk89q/worldedit/masks/Mask.java b/src/main/java/com/sk89q/worldedit/masks/Mask.java index 277e61f94..d5a448736 100644 --- a/src/main/java/com/sk89q/worldedit/masks/Mask.java +++ b/src/main/java/com/sk89q/worldedit/masks/Mask.java @@ -26,7 +26,9 @@ import com.sk89q.worldedit.Vector; /** * Base matcher for the block filtering framework. Implementing classes - * can be used to filter blocks to set or replace + * can be used to filter blocks to set or replace. + *

+ * Do NOT implement this interface. Extend {@link AbstractMask} instead. * * @author sk89q */ diff --git a/src/main/java/com/sk89q/worldedit/masks/RandomMask.java b/src/main/java/com/sk89q/worldedit/masks/RandomMask.java index 3425c6035..65c71af47 100644 --- a/src/main/java/com/sk89q/worldedit/masks/RandomMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/RandomMask.java @@ -1,21 +1,15 @@ package com.sk89q.worldedit.masks; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.Vector; -public class RandomMask implements Mask { +public class RandomMask extends AbstractMask { private final double ratio; public RandomMask(double ratio) { this.ratio = ratio; } - @Override - public void prepare(LocalSession session, LocalPlayer player, Vector target) { - } - @Override public boolean matches(EditSession editSession, Vector pos) { return Math.random() < ratio; diff --git a/src/main/java/com/sk89q/worldedit/masks/RegionMask.java b/src/main/java/com/sk89q/worldedit/masks/RegionMask.java index f9260dc07..b734e7ae3 100644 --- a/src/main/java/com/sk89q/worldedit/masks/RegionMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/RegionMask.java @@ -20,21 +20,16 @@ package com.sk89q.worldedit.masks; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.LocalPlayer; -import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.regions.Region; -public class RegionMask implements Mask { +public class RegionMask extends AbstractMask { private final Region region; public RegionMask(Region region) { this.region = region.clone(); } - public void prepare(LocalSession session, LocalPlayer player, Vector target) { - } - @Override public boolean matches(EditSession editSession, Vector pos) { return region.contains(pos); diff --git a/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java b/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java index c84bbf47e..7c77a75da 100644 --- a/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java +++ b/src/main/java/com/sk89q/worldedit/masks/UnderOverlayMask.java @@ -31,7 +31,7 @@ import com.sk89q.worldedit.blocks.BaseBlock; * * @author 1337 */ -public class UnderOverlayMask implements Mask { +public class UnderOverlayMask extends AbstractMask { private final int yMod; private Mask mask; From 627e029fbb7eca1614cbabe47c0bc4cbef81951f Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Tue, 29 Oct 2013 08:04:52 +0100 Subject: [PATCH 2/2] Added a SolidBlockMask (#solid). --- src/main/java/com/sk89q/worldedit/WorldEdit.java | 3 +++ .../com/sk89q/worldedit/masks/SolidBlockMask.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/main/java/com/sk89q/worldedit/masks/SolidBlockMask.java diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index afda8b67a..ea89a7845 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -84,6 +84,7 @@ import com.sk89q.worldedit.masks.InvertedMask; import com.sk89q.worldedit.masks.Mask; import com.sk89q.worldedit.masks.RandomMask; import com.sk89q.worldedit.masks.RegionMask; +import com.sk89q.worldedit.masks.SolidBlockMask; import com.sk89q.worldedit.masks.UnderOverlayMask; import com.sk89q.worldedit.patterns.BlockChance; import com.sk89q.worldedit.patterns.ClipboardPattern; @@ -731,6 +732,8 @@ public class WorldEdit { case '#': if (component.equalsIgnoreCase("#existing")) { return new ExistingBlockMask(); + } else if (component.equalsIgnoreCase("#solid")) { + return new SolidBlockMask(); } else if (component.equalsIgnoreCase("#dregion") || component.equalsIgnoreCase("#dselection") || component.equalsIgnoreCase("#dsel")) { diff --git a/src/main/java/com/sk89q/worldedit/masks/SolidBlockMask.java b/src/main/java/com/sk89q/worldedit/masks/SolidBlockMask.java new file mode 100644 index 000000000..f78170efc --- /dev/null +++ b/src/main/java/com/sk89q/worldedit/masks/SolidBlockMask.java @@ -0,0 +1,15 @@ +package com.sk89q.worldedit.masks; + +import com.sk89q.worldedit.EditSession; +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 { + @Override + public boolean matches(EditSession editSession, Vector pos) { + return !BlockType.canPassThrough(editSession.getBlockType(pos), editSession.getBlockData(pos)); + } +}