From a9d06fbe84058d5673e0c2ca40d16b24a0ce5554 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 18 Dec 2022 10:14:08 +0100 Subject: [PATCH] FAWEMaskParser_GENERIC.java --- .../linkage/types/FAWEMaskParser_GENERIC.java | 41 +++++++++++++ .../types/FAWEPatternParser_GENERIC.java | 41 +++++++++++++ .../mask/above/FAWEAboveMaskParser.java | 10 +--- .../mask/below/FAWEBelowMaskParser.java | 10 +--- .../mask/checkerboard/CheckerboardMask.java | 1 + .../FAWECheckerboardMaskParser.java | 11 +--- .../checkerboard3d/Checkerboard3DMask.java | 1 + .../FAWECheckerboard3DMaskParser.java | 11 +--- .../mask/grid/FAWEGridMaskParser.java | 11 +--- .../gradient/FAWEGradientPatternParser.java | 57 +------------------ .../worldedit/utils/FAWEMaskParser.java | 33 +++++++++++ .../worldedit/utils/FAWEPatternParser.java | 33 +++++++++++ 12 files changed, 168 insertions(+), 92 deletions(-) create mode 100644 BauSystem_Linkage/src/de/steamwar/linkage/types/FAWEMaskParser_GENERIC.java create mode 100644 BauSystem_Linkage/src/de/steamwar/linkage/types/FAWEPatternParser_GENERIC.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/utils/FAWEMaskParser.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/utils/FAWEPatternParser.java diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/FAWEMaskParser_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/FAWEMaskParser_GENERIC.java new file mode 100644 index 00000000..fac3093e --- /dev/null +++ b/BauSystem_Linkage/src/de/steamwar/linkage/types/FAWEMaskParser_GENERIC.java @@ -0,0 +1,41 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.linkage.types; + +import de.steamwar.linkage.LinkageType; +import de.steamwar.linkage.plan.BuildPlan; +import de.steamwar.linkage.plan.MethodBuilder; + +import javax.lang.model.element.TypeElement; + +public class FAWEMaskParser_GENERIC implements LinkageType { + + @Override + public String method() { + return "link"; + } + + @Override + public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) { + methodBuilder.addLine("if (org.bukkit.Bukkit.getPluginManager().getPlugin(\"FastAsyncWorldEdit\") != null) {"); + methodBuilder.addLine(" " + s + ";"); + methodBuilder.addLine("}"); + } +} diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/FAWEPatternParser_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/FAWEPatternParser_GENERIC.java new file mode 100644 index 00000000..60a1a4ea --- /dev/null +++ b/BauSystem_Linkage/src/de/steamwar/linkage/types/FAWEPatternParser_GENERIC.java @@ -0,0 +1,41 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.linkage.types; + +import de.steamwar.linkage.LinkageType; +import de.steamwar.linkage.plan.BuildPlan; +import de.steamwar.linkage.plan.MethodBuilder; + +import javax.lang.model.element.TypeElement; + +public class FAWEPatternParser_GENERIC implements LinkageType { + + @Override + public String method() { + return "link"; + } + + @Override + public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) { + methodBuilder.addLine("if (org.bukkit.Bukkit.getPluginManager().getPlugin(\"FastAsyncWorldEdit\") != null) {"); + methodBuilder.addLine(" " + s + ";"); + methodBuilder.addLine("}"); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/above/FAWEAboveMaskParser.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/above/FAWEAboveMaskParser.java index dc9476c6..d25dcdeb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/above/FAWEAboveMaskParser.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/above/FAWEAboveMaskParser.java @@ -19,27 +19,23 @@ package de.steamwar.bausystem.features.worldedit.mask.above; -import com.fastasyncworldedit.core.extension.factory.parser.RichParser; 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 de.steamwar.bausystem.utils.WorldEditUtils; +import de.steamwar.bausystem.features.worldedit.utils.FAWEMaskParser; import de.steamwar.linkage.Linked; import de.steamwar.linkage.PluginCheck; -import de.steamwar.linkage.api.Plain; import javax.annotation.Nonnull; import java.util.stream.Stream; @Linked -@PluginCheck("FastAsyncWorldEdit") -public class FAWEAboveMaskParser extends RichParser implements Plain { +public class FAWEAboveMaskParser extends FAWEMaskParser { public FAWEAboveMaskParser() { - super(WorldEdit.getInstance(), "#above"); - WorldEditUtils.addMaskParser(this); + super("#above"); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/below/FAWEBelowMaskParser.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/below/FAWEBelowMaskParser.java index 2de798c4..bc7cb34c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/below/FAWEBelowMaskParser.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/below/FAWEBelowMaskParser.java @@ -19,27 +19,23 @@ package de.steamwar.bausystem.features.worldedit.mask.below; -import com.fastasyncworldedit.core.extension.factory.parser.RichParser; 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 de.steamwar.bausystem.utils.WorldEditUtils; +import de.steamwar.bausystem.features.worldedit.utils.FAWEMaskParser; import de.steamwar.linkage.Linked; import de.steamwar.linkage.PluginCheck; -import de.steamwar.linkage.api.Plain; import javax.annotation.Nonnull; import java.util.stream.Stream; @Linked -@PluginCheck("FastAsyncWorldEdit") -public class FAWEBelowMaskParser extends RichParser implements Plain { +public class FAWEBelowMaskParser extends FAWEMaskParser { public FAWEBelowMaskParser() { - super(WorldEdit.getInstance(), "#below"); - WorldEditUtils.addMaskParser(this); + super("#below"); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard/CheckerboardMask.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard/CheckerboardMask.java index 646b169c..a4a726a1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard/CheckerboardMask.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard/CheckerboardMask.java @@ -32,6 +32,7 @@ public class CheckerboardMask implements Mask { @Override public boolean test(BlockVector3 vector) { + if (size == 0) return true; return (vector.getBlockX() / size + vector.getBlockZ() / size) % 2 == 0; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard/FAWECheckerboardMaskParser.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard/FAWECheckerboardMaskParser.java index fe4984e0..323a3ba0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard/FAWECheckerboardMaskParser.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard/FAWECheckerboardMaskParser.java @@ -19,27 +19,22 @@ package de.steamwar.bausystem.features.worldedit.mask.checkerboard; -import com.fastasyncworldedit.core.extension.factory.parser.RichParser; -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 de.steamwar.bausystem.utils.WorldEditUtils; +import de.steamwar.bausystem.features.worldedit.utils.FAWEMaskParser; import de.steamwar.linkage.Linked; import de.steamwar.linkage.PluginCheck; -import de.steamwar.linkage.api.Plain; import javax.annotation.Nonnull; import java.util.stream.Stream; @Linked -@PluginCheck("FastAsyncWorldEdit") -public class FAWECheckerboardMaskParser extends RichParser implements Plain { +public class FAWECheckerboardMaskParser extends FAWEMaskParser { public FAWECheckerboardMaskParser() { - super(WorldEdit.getInstance(), "#checkerboard"); - WorldEditUtils.addMaskParser(this); + super("#checkerboard"); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard3d/Checkerboard3DMask.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard3d/Checkerboard3DMask.java index 6695b612..41d7573b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard3d/Checkerboard3DMask.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard3d/Checkerboard3DMask.java @@ -32,6 +32,7 @@ public class Checkerboard3DMask implements Mask { @Override public boolean test(BlockVector3 vector) { + if (size == 0) return true; return (vector.getBlockX() / size + vector.getBlockY() / size + vector.getBlockZ() / size) % 2 == 0; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard3d/FAWECheckerboard3DMaskParser.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard3d/FAWECheckerboard3DMaskParser.java index 10e1eafe..d4303d12 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard3d/FAWECheckerboard3DMaskParser.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/checkerboard3d/FAWECheckerboard3DMaskParser.java @@ -19,27 +19,22 @@ package de.steamwar.bausystem.features.worldedit.mask.checkerboard3d; -import com.fastasyncworldedit.core.extension.factory.parser.RichParser; -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 de.steamwar.bausystem.utils.WorldEditUtils; +import de.steamwar.bausystem.features.worldedit.utils.FAWEMaskParser; import de.steamwar.linkage.Linked; import de.steamwar.linkage.PluginCheck; -import de.steamwar.linkage.api.Plain; import javax.annotation.Nonnull; import java.util.stream.Stream; @Linked -@PluginCheck("FastAsyncWorldEdit") -public class FAWECheckerboard3DMaskParser extends RichParser implements Plain { +public class FAWECheckerboard3DMaskParser extends FAWEMaskParser { public FAWECheckerboard3DMaskParser() { - super(WorldEdit.getInstance(), "#checkerboard3d"); - WorldEditUtils.addMaskParser(this); + super("#checkerboard3d"); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/grid/FAWEGridMaskParser.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/grid/FAWEGridMaskParser.java index 8ca46641..f0d4a867 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/grid/FAWEGridMaskParser.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/mask/grid/FAWEGridMaskParser.java @@ -19,27 +19,22 @@ package de.steamwar.bausystem.features.worldedit.mask.grid; -import com.fastasyncworldedit.core.extension.factory.parser.RichParser; -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 de.steamwar.bausystem.utils.WorldEditUtils; +import de.steamwar.bausystem.features.worldedit.utils.FAWEMaskParser; import de.steamwar.linkage.Linked; import de.steamwar.linkage.PluginCheck; -import de.steamwar.linkage.api.Plain; import javax.annotation.Nonnull; import java.util.stream.Stream; @Linked -@PluginCheck("FastAsyncWorldEdit") -public class FAWEGridMaskParser extends RichParser implements Plain { +public class FAWEGridMaskParser extends FAWEMaskParser { public FAWEGridMaskParser() { - super(WorldEdit.getInstance(), "#grid"); - WorldEditUtils.addMaskParser(this); + super("#grid"); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/pattern/gradient/FAWEGradientPatternParser.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/pattern/gradient/FAWEGradientPatternParser.java index a1f0e450..15b311e5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/pattern/gradient/FAWEGradientPatternParser.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/pattern/gradient/FAWEGradientPatternParser.java @@ -19,77 +19,26 @@ package de.steamwar.bausystem.features.worldedit.pattern.gradient; -import com.fastasyncworldedit.core.extension.factory.parser.RichParser; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.regions.Region; +import de.steamwar.bausystem.features.worldedit.utils.FAWEPatternParser; import de.steamwar.bausystem.utils.WorldEditUtils; import de.steamwar.linkage.Linked; -import de.steamwar.linkage.PluginCheck; -import de.steamwar.linkage.api.Plain; import org.bukkit.Axis; import javax.annotation.Nonnull; import java.util.stream.Stream; @Linked -@PluginCheck("FastAsyncWorldEdit") -public class FAWEGradientPatternParser extends RichParser implements Plain { +public class FAWEGradientPatternParser extends FAWEPatternParser { public FAWEGradientPatternParser() { - super(WorldEdit.getInstance(), "#gradient"); - WorldEditUtils.addPatternParser(this); + super("#gradient"); } - /* - @Override - public Pattern parseFromInput(String s, ParserContext parserContext) throws InputParseException { - System.out.println("parse " + s); - if (!s.startsWith("#gradient")) return null; - Extent extent = parserContext.requireExtent(); - Axis axis = null; - if (s.startsWith("#gradientx")) { - axis = Axis.X; - } else if (s.startsWith("#gradienty")) { - axis = Axis.Y; - } else if (s.startsWith("#gradientz")) { - axis = Axis.Z; - } - if (axis == null) { - throw new InputParseException("No axis given for gradient pattern"); - } - s = s.substring(10); - if (!s.startsWith("[") && s.endsWith("]")) { - throw new InputParseException("No pattern given for gradient pattern"); - } - s = s.substring(1, s.length() - 1); - String[] patterns = s.split("]\\["); - if (patterns.length < 2) { - throw new InputParseException("Not enough patterns given for gradient pattern"); - } - if (patterns.length > 2) { - throw new InputParseException("Too many patterns given for gradient pattern"); - } - Pattern from = WorldEditUtils.getPatternFactory().parseFromInput(patterns[0], parserContext); - Pattern to = WorldEditUtils.getPatternFactory().parseFromInput(patterns[1], parserContext); - int size = 0; - switch (axis) { - case X: - size = extent.getMaximumPoint().getBlockX() - extent.getMinimumPoint().getBlockX(); - break; - case Y: - size = extent.getMaximumPoint().getBlockY() - extent.getMinimumPoint().getBlockY(); - break; - case Z: - size = extent.getMaximumPoint().getBlockZ() - extent.getMinimumPoint().getBlockZ(); - break; - } - return new GradientPattern(axis, from, to, extent.getMinimumPoint(), size); - } - */ - @Override protected Stream getSuggestions(String input, int index) { if (index == 0) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/utils/FAWEMaskParser.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/utils/FAWEMaskParser.java new file mode 100644 index 00000000..1a2f54ee --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/utils/FAWEMaskParser.java @@ -0,0 +1,33 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.worldedit.utils; + +import com.fastasyncworldedit.core.extension.factory.parser.RichParser; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.function.mask.Mask; +import de.steamwar.bausystem.utils.WorldEditUtils; + +public abstract class FAWEMaskParser extends RichParser { + + protected FAWEMaskParser(String... aliases) { + super(WorldEdit.getInstance(), aliases); + WorldEditUtils.addMaskParser(this); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/utils/FAWEPatternParser.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/utils/FAWEPatternParser.java new file mode 100644 index 00000000..9894933c --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/utils/FAWEPatternParser.java @@ -0,0 +1,33 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.worldedit.utils; + +import com.fastasyncworldedit.core.extension.factory.parser.RichParser; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.function.pattern.Pattern; +import de.steamwar.bausystem.utils.WorldEditUtils; + +public abstract class FAWEPatternParser extends RichParser { + + protected FAWEPatternParser(String... aliases) { + super(WorldEdit.getInstance(), aliases); + WorldEditUtils.addPatternParser(this); + } +}