From f886320c4457576d7359c5bd85095912a2bf112e Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 30 Sep 2021 13:17:15 +0100 Subject: [PATCH] SurfaceMask should be copied properly. #1331 --- .../core/function/mask/AdjacentAnyMask.java | 13 ++++++++++--- .../core/function/mask/SurfaceMask.java | 8 ++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/AdjacentAnyMask.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/AdjacentAnyMask.java index 43aaed3dc..39bb0c41d 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/AdjacentAnyMask.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/AdjacentAnyMask.java @@ -12,8 +12,8 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask { private final CachedMask mask; private final MutableBlockVector3 mutable; - private final int minY; - private final int maxY; + final int minY; + final int maxY; public AdjacentAnyMask(Mask mask, int minY, int maxY) { this.mask = CachedMask.cache(mask); @@ -22,6 +22,13 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask { this.maxY = maxY; } + AdjacentAnyMask(CachedMask mask, int minY, int maxY) { + this.mask = CachedMask.cache(mask); + mutable = new MutableBlockVector3(); + this.minY = minY; + this.maxY = maxY; + } + @Override public void reset() { mutable.setComponents(0, 0, 0); @@ -59,7 +66,7 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask { @Override public Mask copy() { - return new AdjacentAnyMask(mask.copy(), minY, maxY); + return new AdjacentAnyMask((CachedMask) mask.copy(), minY, maxY); } } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/SurfaceMask.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/SurfaceMask.java index 36fe46edb..6e31526a8 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/SurfaceMask.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/SurfaceMask.java @@ -12,6 +12,10 @@ public class SurfaceMask extends AdjacentAnyMask { super(getMask(extent), extent.getMinY(), extent.getMaxY()); } + private SurfaceMask(CachedMask mask, int minY, int maxY) { + super(mask, minY, maxY); + } + public static AbstractExtentMask getMask(Extent extent) { return new BlockMaskBuilder() .addTypes(BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR) @@ -26,8 +30,8 @@ public class SurfaceMask extends AdjacentAnyMask { @Override public Mask copy() { - // The mask is not mutable. There is no need to clone it. - return this; + // CachedMask (super getParentMask) should not be used from multiple threads. + return new SurfaceMask(getParentMask(), minY, maxY); } }