From 569fdc3861093694df226fb1da04928b112ca862 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Tue, 17 Aug 2021 17:03:25 +0100 Subject: [PATCH] Reimplement radius mask, fix wall mask --- .../factory/parser/mask/RadiusMaskParser.java | 4 +- .../factory/parser/mask/WallMaskParser.java | 42 +++++++++++++------ .../core/function/mask/RadiusMask.java | 4 +- .../extension/factory/MaskFactory.java | 5 ++- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/RadiusMaskParser.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/RadiusMaskParser.java index efbb3ad72..8a57c73af 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/RadiusMaskParser.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/RadiusMaskParser.java @@ -20,14 +20,14 @@ public class RadiusMaskParser extends RichParser { @Override protected Stream getSuggestions(String argumentInput, int index) { if (index == 0 || index == 1) { - return SuggestionHelper.suggestPositiveDoubles(argumentInput); + return SuggestionHelper.suggestPositiveIntegers(argumentInput); } return Stream.empty(); } @Override protected Mask parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException { - if (arguments.length < 2) { + if (arguments.length != 2) { return null; } int min = Integer.parseInt(arguments[0]); diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/WallMaskParser.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/WallMaskParser.java index 0142213e9..95cd7e53f 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/WallMaskParser.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/WallMaskParser.java @@ -1,22 +1,21 @@ package com.fastasyncworldedit.core.extension.factory.parser.mask; +import com.fastasyncworldedit.core.extension.factory.parser.RichParser; import com.fastasyncworldedit.core.function.mask.WallMask; import com.google.common.collect.ImmutableList; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.command.util.SuggestionHelper; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.ParserContext; -import com.sk89q.worldedit.function.mask.BlockMask; -import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.Mask; -import com.sk89q.worldedit.function.mask.MaskIntersection; -import com.sk89q.worldedit.internal.registry.SimpleInputParser; -import com.sk89q.worldedit.world.block.BlockTypes; +import javax.annotation.Nonnull; import java.util.List; +import java.util.stream.Stream; -public class WallMaskParser extends SimpleInputParser { +public class WallMaskParser extends RichParser { - private final List aliases = ImmutableList.of("#wall"); + private final List aliases = ImmutableList.of("#wall", "|"); public WallMaskParser(WorldEdit worldEdit) { super(worldEdit); @@ -28,11 +27,30 @@ public class WallMaskParser extends SimpleInputParser { } @Override - public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException { - return new MaskIntersection( - new ExistingBlockMask(context.getExtent()), - new WallMask(new BlockMask(context.getExtent(), BlockTypes.AIR.getDefaultState().toBaseBlock()), 1, 8) - ); + protected Stream getSuggestions(final String argumentInput, final int index) { + if (index == 0) { + return worldEdit.getMaskFactory().getSuggestions(argumentInput).stream(); + } else if (index == 1 || index == 2) { + return SuggestionHelper.suggestPositiveDoubles(argumentInput); + } + return Stream.empty(); + } + + @Override + protected Mask parseFromInput(@Nonnull final String[] arguments, final ParserContext context) throws InputParseException { + if (arguments.length > 3 || arguments.length == 0) { + return null; + } + Mask subMask = worldEdit.getMaskFactory().parseFromInput(arguments[0], context); + int min = arguments.length > 1 ? Integer.parseInt(arguments[1]) : -1; + int max = arguments.length > 2 ? Integer.parseInt(arguments[2]) : -1; + if (min == -1 && max == -1) { + min = 1; + max = 8; + } else if (max == -1) { + max = min; + } + return new WallMask(subMask, min, max); } } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/RadiusMask.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/RadiusMask.java index 473089337..b99e56ddc 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/RadiusMask.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/function/mask/RadiusMask.java @@ -6,9 +6,9 @@ import com.sk89q.worldedit.math.BlockVector3; public class RadiusMask extends AbstractMask implements ResettableMask { - private transient BlockVector3 pos; private final int minSqr; private final int maxSqr; + private transient BlockVector3 pos; public RadiusMask(int min, int max) { this.minSqr = min * min; @@ -47,7 +47,7 @@ public class RadiusMask extends AbstractMask implements ResettableMask { @Override public Mask copy() { - return new RadiusMask(minSqr, maxSqr); + return new RadiusMask((Integer) minSqr, (Integer) maxSqr); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java index 388ea4d83..bf53d101e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java @@ -22,11 +22,12 @@ package com.sk89q.worldedit.extension.factory; import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.extension.factory.parser.mask.AdjacentMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.AngleMaskParser; -import com.fastasyncworldedit.core.extension.factory.parser.mask.RichMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.ExtremaMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.FalseMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.LiquidMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.ROCAngleMaskParser; +import com.fastasyncworldedit.core.extension.factory.parser.mask.RadiusMaskParser; +import com.fastasyncworldedit.core.extension.factory.parser.mask.RichMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.RichOffsetMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.SimplexMaskParser; import com.fastasyncworldedit.core.extension.factory.parser.mask.SurfaceAngleMaskParser; @@ -108,7 +109,7 @@ public final class MaskFactory extends AbstractFactory { register(new ExtremaMaskParser(worldEdit)); register(new FalseMaskParser(worldEdit)); register(new LiquidMaskParser(worldEdit)); - //register(new RadiusMaskParser(worldEdit)); TODO: Adapt to work with FAWE's Chunk I/O + register(new RadiusMaskParser(worldEdit)); register(new RichOffsetMaskParser(worldEdit)); register(new ROCAngleMaskParser(worldEdit)); register(new SimplexMaskParser(worldEdit));