From 7a9549b75af7ba4440e9b01d4e9b258773859939 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Mon, 8 Nov 2021 15:49:43 +0000 Subject: [PATCH] Unmerge wall/"besides / |" masks --- .../factory/parser/mask/BesideMaskParser.java | 47 +++++++++++++++++++ .../factory/parser/mask/WallMaskParser.java | 45 +++++++----------- .../extension/factory/MaskFactory.java | 2 + 3 files changed, 67 insertions(+), 27 deletions(-) create mode 100644 worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/BesideMaskParser.java diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/BesideMaskParser.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/BesideMaskParser.java new file mode 100644 index 000000000..954b9f53d --- /dev/null +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/BesideMaskParser.java @@ -0,0 +1,47 @@ +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.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.Mask; + +import javax.annotation.Nonnull; +import java.util.stream.Stream; + +public class BesideMaskParser extends RichParser { + + public BesideMaskParser(WorldEdit worldEdit) { + super(worldEdit, "#beside", "|"); + } + + @Override + 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/extension/factory/parser/mask/WallMaskParser.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/mask/WallMaskParser.java index 12b9b240e..306ab21ce 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,47 +1,38 @@ 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.stream.Stream; +import java.util.List; -public class WallMaskParser extends RichParser { +public class WallMaskParser extends SimpleInputParser { + + private static final List aliases = ImmutableList.of("#wall"); public WallMaskParser(WorldEdit worldEdit) { - super(worldEdit, "#wall", "|"); + super(worldEdit); } @Override - 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(); + public List getMatchedAliases() { + return aliases; } @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); + 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) + ); } } 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 863f9c1c1..24c674f0b 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,6 +22,7 @@ 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.BesideMaskParser; 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; @@ -106,6 +107,7 @@ public final class MaskFactory extends AbstractFactory { // Mask Parsers from FAWE register(new AdjacentMaskParser(worldEdit)); register(new AngleMaskParser(worldEdit)); + register(new BesideMaskParser(worldEdit)); register(new ExtremaMaskParser(worldEdit)); register(new FalseMaskParser(worldEdit)); register(new LiquidMaskParser(worldEdit));