From 2239d14a01d08efea5deb92b9c39164d0a0bc338 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Sat, 21 Jul 2018 20:35:23 +1000 Subject: [PATCH] Fixed //replace and masks with states. --- .../sk89q/worldedit/function/mask/BlockMask.java | 8 +++++++- .../worldedit/registry/state/AbstractProperty.java | 13 +++++++++++++ .../com/sk89q/worldedit/world/block/BlockState.java | 12 +++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java index 772b64942..f44ce27e6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java @@ -95,7 +95,13 @@ public class BlockMask extends AbstractExtentMask { @Override public boolean test(Vector vector) { BlockStateHolder block = getExtent().getBlock(vector); - return blocks.contains(block) || blocks.contains(block); + for (BlockStateHolder testBlock : blocks) { + if (testBlock.equalsFuzzy(block)) { + return true; + } + } + + return false; } @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/AbstractProperty.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/AbstractProperty.java index 905d0466b..8079bae0e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/AbstractProperty.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/AbstractProperty.java @@ -53,4 +53,17 @@ public abstract class AbstractProperty implements Property { checkState(this.name == null, "name already set"); this.name = name; } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Property)) { + return false; + } + return getName().equals(((Property) obj).getName()); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index 94159c223..7adfdded5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -31,9 +31,12 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; /** @@ -167,7 +170,7 @@ public class BlockState implements BlockStateHolder { return false; } - List differingProperties = new ArrayList<>(); + Set differingProperties = new HashSet<>(); for (Object state : o.getStates().keySet()) { if (getState((Property) state) == null) { differingProperties.add((Property) state); @@ -179,8 +182,11 @@ public class BlockState implements BlockStateHolder { } } - for (Property property : differingProperties) { - if (!getState(property).equals(o.getState(property))) { + for (Property property : getStates().keySet()) { + if (differingProperties.contains(property)) { + continue; + } + if (!Objects.equals(getState(property), o.getState(property))) { return false; } }