From dc465f7d3c3bbb0e75197b0226a44c11221bb83a Mon Sep 17 00:00:00 2001 From: IronApollo Date: Mon, 7 Sep 2020 21:46:54 -0400 Subject: [PATCH] Reformat, fix RichParser suggestions --- .../boydti/fawe/object/mask/AngleMask.java | 28 +++++++++---------- .../boydti/fawe/object/mask/ROCAngleMask.java | 10 +++---- .../boydti/fawe/object/mask/SurfaceMask.java | 6 ++-- .../extension/factory/MaskFactory.java | 27 +++++++++++++++++- .../extension/factory/parser/RichParser.java | 8 +++--- .../parser/mask/AdjacentMaskParser.java | 8 +++--- .../factory/parser/mask/RadiusMaskParser.java | 5 ++-- 7 files changed, 58 insertions(+), 34 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java index f5f48d698..4d5fba6bb 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java @@ -94,32 +94,32 @@ public class AngleMask extends SolidBlockMask implements ResettableMask { boolean aboveMin; lastY = y; slope = - Math.abs(getHeight(extent, x + distance, y, z) - getHeight(extent, x - distance, y, z)) - * ADJACENT_MOD; + Math.abs(getHeight(extent, x + distance, y, z) - getHeight(extent, x - distance, y, z)) + * ADJACENT_MOD; if (checkFirst) { if (slope >= min) { return lastValue = true; } slope = Math.max(slope, Math.abs( - getHeight(extent, x, y, z + distance) - getHeight(extent, x, y, z - distance)) - * ADJACENT_MOD); + getHeight(extent, x, y, z + distance) - getHeight(extent, x, y, z - distance)) + * ADJACENT_MOD); slope = Math.max(slope, Math.abs( - getHeight(extent, x + distance, y, z + distance) - getHeight(extent, - x - distance, y, z - distance)) * DIAGONAL_MOD); + getHeight(extent, x + distance, y, z + distance) - getHeight(extent, + x - distance, y, z - distance)) * DIAGONAL_MOD); slope = Math.max(slope, Math.abs( - getHeight(extent, x - distance, y, z + distance) - getHeight(extent, - x + distance, y, z - distance)) * DIAGONAL_MOD); + getHeight(extent, x - distance, y, z + distance) - getHeight(extent, + x + distance, y, z - distance)) * DIAGONAL_MOD); return lastValue = (slope >= min); } else { slope = Math.max(slope, Math.abs( - getHeight(extent, x, y, z + distance) - getHeight(extent, x, y, z - distance)) - * ADJACENT_MOD); + getHeight(extent, x, y, z + distance) - getHeight(extent, x, y, z - distance)) + * ADJACENT_MOD); slope = Math.max(slope, Math.abs( - getHeight(extent, x + distance, y, z + distance) - getHeight(extent, - x - distance, y, z - distance)) * DIAGONAL_MOD); + getHeight(extent, x + distance, y, z + distance) - getHeight(extent, + x - distance, y, z - distance)) * DIAGONAL_MOD); slope = Math.max(slope, Math.abs( - getHeight(extent, x - distance, y, z + distance) - getHeight(extent, - x + distance, y, z - distance)) * DIAGONAL_MOD); + getHeight(extent, x - distance, y, z + distance) - getHeight(extent, + x + distance, y, z - distance)) * DIAGONAL_MOD); return lastValue = (slope >= min && slope <= max); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ROCAngleMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ROCAngleMask.java index ee7f542d2..a7da74224 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ROCAngleMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ROCAngleMask.java @@ -14,19 +14,19 @@ public class ROCAngleMask extends AngleMask { int base = getHeight(extent, x, y, z); double slope = - (getHeight(extent, x + distance, y, z) - base - (base - getHeight(extent, x - distance, y, z))) - * ADJACENT_MOD; + (getHeight(extent, x + distance, y, z) - base - (base - getHeight(extent, x - distance, y, z))) + * ADJACENT_MOD; double tmp = (getHeight(extent, x, y, z + distance) - base - (base - getHeight(extent, x, y, - z - distance))) * ADJACENT_MOD; + z - distance))) * ADJACENT_MOD; if (Math.abs(tmp) > Math.abs(slope)) slope = tmp; tmp = (getHeight(extent, x + distance, y, z + distance) - base - (base - getHeight(extent, x - distance, y, - z - distance))) * DIAGONAL_MOD; + z - distance))) * DIAGONAL_MOD; if (Math.abs(tmp) > Math.abs(slope)) slope = tmp; tmp = (getHeight(extent, x - distance, y, z + distance) - base - (base - getHeight(extent, x + distance, y, - z - distance))) * DIAGONAL_MOD; + z - distance))) * DIAGONAL_MOD; if (Math.abs(tmp) > Math.abs(slope)) slope = tmp; return lastValue = slope >= min && slope <= max; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java index 3413e6878..9534be6dc 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java @@ -13,9 +13,9 @@ public class SurfaceMask extends AdjacentAnyMask { public static AbstractExtentMask getMask(Extent extent) { return new BlockMaskBuilder() - .addTypes(BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR) - .addAll(b -> !b.getMaterial().isMovementBlocker()) - .build(extent); + .addTypes(BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR) + .addAll(b -> !b.getMaterial().isMovementBlocker()) + .build(extent); } @Override 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 211817d9e..52ce3ba43 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 @@ -20,7 +20,32 @@ package com.sk89q.worldedit.extension.factory; import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.extension.factory.parser.mask.*; +import com.sk89q.worldedit.extension.factory.parser.mask.AdjacentMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.AirMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.AngleMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.BiomeMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.BlockCategoryMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.BlockStateMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.BlocksMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.ExistingMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.ExpressionMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.ExtremaMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.FalseMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.LazyRegionMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.LiquidMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.NegateMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.NoiseMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.OffsetMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.ROCAngleMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.RegionMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.SimplexMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.SolidMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.SurfaceMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.TrueMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.WallMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.XAxisMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.YAxisMaskParser; +import com.sk89q.worldedit.extension.factory.parser.mask.ZAxisMaskParser; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.NoMatchException; import com.sk89q.worldedit.extension.input.ParserContext; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/RichParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/RichParser.java index 7c19f55b0..5d625826d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/RichParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/RichParser.java @@ -36,7 +36,7 @@ public abstract class RichParser extends InputParser { @Override public Stream getSuggestions(String input) { // we don't even want to start suggesting if it's not meant to be this parser result - if (input.length() > this.required.length() && !input.startsWith(this.required)) { + if (input.length() >= this.required.length() && !input.startsWith(this.required)) { return Stream.empty(); } // suggest until the first [ as long as it isn't fully typed @@ -45,11 +45,11 @@ public abstract class RichParser extends InputParser { } // we know that it is at least "" String[] strings = extractArguments(input.substring(this.prefix.length()), false); - StringJoiner joiner = new StringJoiner(","); + StringBuilder builder = new StringBuilder(); for (int i = 0; i < strings.length - 1; i++) { - joiner.add("[" + strings[i] + "]"); + builder.append('[').append(strings[i]).append(']'); } - String previous = this.prefix + joiner; + String previous = this.prefix + builder; return getSuggestions(strings[strings.length - 1], strings.length - 1).map(s -> previous + "[" + s + "]"); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/AdjacentMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/AdjacentMaskParser.java index 0dd9f768c..128c51d9a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/AdjacentMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/AdjacentMaskParser.java @@ -14,12 +14,12 @@ import java.util.stream.Stream; public class AdjacentMaskParser extends RichParser { public AdjacentMaskParser(WorldEdit worldEdit) { - super(worldEdit,"~"); + super(worldEdit, "~"); } @Override protected Stream getSuggestions(String argumentInput, int index) { - if(index == 0){ + if (index == 0) { return worldEdit.getMaskFactory().getSuggestions(argumentInput).stream(); } else if (index == 1 || index == 2) { return this.suggestPositiveDoubles(argumentInput); @@ -29,7 +29,7 @@ public class AdjacentMaskParser extends RichParser { @Override protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException { - if(arguments.length == 0) return null; + if (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; @@ -40,6 +40,6 @@ public class AdjacentMaskParser extends RichParser { if (max >= 8 && min == 1) { return new AdjacentAnyMask(subMask); } - return new AdjacentMask(subMask, (int) min, (int) max); + return new AdjacentMask(subMask, min, max); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/RadiusMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/RadiusMaskParser.java index 9caa169e9..bfc78863a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/RadiusMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/RadiusMaskParser.java @@ -18,7 +18,7 @@ public class RadiusMaskParser extends RichParser { @Override protected Stream getSuggestions(String argumentInput, int index) { - if(index == 0 || index == 1){ + if (index == 0 || index == 1) { return suggestPositiveDoubles(argumentInput); } return Stream.empty(); @@ -26,10 +26,9 @@ public class RadiusMaskParser extends RichParser { @Override protected Mask parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException { - if(arguments.length < 2) return null; + if (arguments.length < 2) return null; int min = Integer.parseInt(arguments[0]); int max = Integer.parseInt(arguments[1]); - System.out.println("radius: " + min + " | " + max); return new RadiusMask(min, max); } }