From 8a425cc435542e1d2280b54b1b304833ab6baccd Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 4 Feb 2023 11:26:50 +0100 Subject: [PATCH 01/22] Prevent Water from being pasted using /tb --- .../bausystem/utils/FlatteningWrapper15.java | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index cadcb72a..52fd6a92 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -142,36 +142,32 @@ public class FlatteningWrapper15 implements FlatteningWrapper { if (pasteOptions.getColor() != Color.YELLOW) { changeColor(clipboard, pasteOptions.getColor()); } - if (pasteOptions.isOnlyColors()) { - Set blocks = new HashSet<>(); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_wool"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_terracotta"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_glazed_terracotta"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass_pane"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete_powder"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_carpet"); - - e.setMask(new Mask() { - @Override - public boolean test(BlockVector3 blockVector3) { - BaseBlock block = clipboard.getFullBlock(blockVector3); - String blockName = block.toString().toLowerCase(); - return blocks.contains(blockName); + e.setMask(new Mask() { + @Override + public boolean test(BlockVector3 blockVector3) { + Set blocks = new HashSet<>(); + if (pasteOptions.isOnlyColors()) { + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_wool"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_terracotta"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_glazed_terracotta"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass_pane"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete_powder"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_carpet"); } - @Nullable - @Override - public Mask2D toMask2D() { - return null; - } + BaseBlock block = clipboard.getFullBlock(blockVector3); + String blockName = block.toString().toLowerCase(); + return blockName.equals("minecraft:water") || blocks.contains(blockName); + } - public Mask copy() { - return this; - } - }); - } + @Nullable + @Override + public Mask2D toMask2D() { + return null; + } + }); ClipboardHolder ch = new ClipboardHolder(clipboard); BlockVector3 dimensions = clipboard.getDimensions(); -- 2.39.2 From 3d8a6e95fabd71041ebebd97c77bffc6fe3f530b Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 4 Feb 2023 11:54:37 +0100 Subject: [PATCH 02/22] fixed mistake --- .../src/de/steamwar/bausystem/utils/FlatteningWrapper15.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index 52fd6a92..7ea83656 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -159,7 +159,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper { BaseBlock block = clipboard.getFullBlock(blockVector3); String blockName = block.toString().toLowerCase(); - return blockName.equals("minecraft:water") || blocks.contains(blockName); + return !blockName.equals("minecraft:water") || blocks.contains(blockName); } @Nullable -- 2.39.2 From cdc0dbea86647e499099b23d3f2f420a0ada63f8 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 4 Feb 2023 11:56:52 +0100 Subject: [PATCH 03/22] fixed mistake 2 --- .../bausystem/utils/FlatteningWrapper15.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index 7ea83656..7cbe7348 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -142,21 +142,21 @@ public class FlatteningWrapper15 implements FlatteningWrapper { if (pasteOptions.getColor() != Color.YELLOW) { changeColor(clipboard, pasteOptions.getColor()); } + + Set blocks = new HashSet<>(); + if (pasteOptions.isOnlyColors()) { + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_wool"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_terracotta"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_glazed_terracotta"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass_pane"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete_powder"); + blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_carpet"); + } e.setMask(new Mask() { @Override public boolean test(BlockVector3 blockVector3) { - Set blocks = new HashSet<>(); - if (pasteOptions.isOnlyColors()) { - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_wool"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_terracotta"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_glazed_terracotta"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass_pane"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete_powder"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_carpet"); - } - BaseBlock block = clipboard.getFullBlock(blockVector3); String blockName = block.toString().toLowerCase(); return !blockName.equals("minecraft:water") || blocks.contains(blockName); -- 2.39.2 From d2a3483d31baf4a3425cc16a914a71679900a975 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 4 Feb 2023 12:12:10 +0100 Subject: [PATCH 04/22] added check if it actually is a tb --- .../bausystem/utils/FlatteningWrapper15.java | 3 ++- .../bausystem/features/region/TestblockCommand.java | 2 +- .../de/steamwar/bausystem/region/PasteOptions.java | 2 ++ .../src/de/steamwar/bausystem/region/Region.java | 12 ++++++------ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index 7cbe7348..b1d4ddf2 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -159,7 +159,8 @@ public class FlatteningWrapper15 implements FlatteningWrapper { public boolean test(BlockVector3 blockVector3) { BaseBlock block = clipboard.getFullBlock(blockVector3); String blockName = block.toString().toLowerCase(); - return !blockName.equals("minecraft:water") || blocks.contains(blockName); + if (pasteOptions.isTestBlock() && blockName.equals("minecraft.water")) return true; + return blocks.contains(blockName); } @Nullable diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index a677e4df..8527371d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -86,7 +86,7 @@ public class TestblockCommand extends SWCommand { } try { - region.reset(node, RegionType.TESTBLOCK, regionExtensionType); + region.reset(node, RegionType.TESTBLOCK, regionExtensionType, true); RegionUtils.message(region, "REGION_TB_DONE"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java index e28a02d8..c782a06b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java @@ -67,4 +67,6 @@ public class PasteOptions { * Used in 1.15 */ private final int waterLevel; + + private final boolean testBlock; } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 2d3fdc04..2b518c87 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -425,8 +425,8 @@ public class Region { reset(null, regionType, regionExtensionType, false); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType) throws IOException { - reset(schematic, regionType, regionExtensionType, false); + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean isTestBlock) throws IOException { + reset(schematic, regionType, regionExtensionType, false, isTestBlock); } public void reset(File file) { @@ -435,11 +435,11 @@ public class Region { undoSessions.push(editSession); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir) throws IOException { - reset(schematic, regionType, regionExtensionType, ignoreAir, false); + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean isTestBlock) throws IOException { + reset(schematic, regionType, regionExtensionType, ignoreAir, false, isTestBlock); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors) throws IOException { + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors, boolean isTestBlock) throws IOException { if (!hasReset(regionType)) { return; } @@ -447,7 +447,7 @@ public class Region { regionExtensionType = RegionExtensionType.NORMAL; } - PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel); + PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel, isTestBlock); Point pastePoint; File tempFile = null; -- 2.39.2 From 5c8b70fc128f90b11fc5c3f4b08de7287bfaafee Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 4 Feb 2023 12:15:45 +0100 Subject: [PATCH 05/22] added check if it actually is a tb --- .../bausystem/features/region/TestblockCommand.java | 2 +- BauSystem_Main/src/de/steamwar/bausystem/region/Region.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index 8527371d..2db16400 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -57,7 +57,7 @@ public class TestblockCommand extends SWCommand { Region region = regionCheck(p); if (region == null) return; try { - region.reset(RegionType.TESTBLOCK, regionExtensionType); + region.reset(RegionType.TESTBLOCK, regionExtensionType, true); RegionUtils.message(region, "REGION_TB_DONE"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 2b518c87..e2787034 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -421,8 +421,8 @@ public class Region { reset(schematic, regionType, RegionExtensionType.NORMAL, false); } - public void reset(RegionType regionType, RegionExtensionType regionExtensionType) throws IOException { - reset(null, regionType, regionExtensionType, false); + public void reset(RegionType regionType, RegionExtensionType regionExtensionType, boolean isTestBlock) throws IOException { + reset(null, regionType, regionExtensionType, isTestBlock); } public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean isTestBlock) throws IOException { @@ -430,7 +430,7 @@ public class Region { } public void reset(File file) { - EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, false, false, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel)); + EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, false, false, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel, false)); initSessions(); undoSessions.push(editSession); } -- 2.39.2 From 4bae6b8d43ea0987c4cdd56f4160699c90a5c075 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 6 Feb 2023 09:37:34 +0100 Subject: [PATCH 06/22] finally working waterremover when doing /tb idk --- .../bausystem/utils/FlatteningWrapper15.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index b1d4ddf2..fb02039e 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -43,6 +43,7 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.region.PasteOptions; import de.steamwar.bausystem.region.Point; @@ -143,8 +144,9 @@ public class FlatteningWrapper15 implements FlatteningWrapper { changeColor(clipboard, pasteOptions.getColor()); } + Set blocks = new HashSet<>(); - if (pasteOptions.isOnlyColors()) { + { blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_wool"); blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_terracotta"); blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_glazed_terracotta"); @@ -154,13 +156,15 @@ public class FlatteningWrapper15 implements FlatteningWrapper { blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete_powder"); blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_carpet"); } + e.setMask(new Mask() { @Override public boolean test(BlockVector3 blockVector3) { BaseBlock block = clipboard.getFullBlock(blockVector3); String blockName = block.toString().toLowerCase(); - if (pasteOptions.isTestBlock() && blockName.equals("minecraft.water")) return true; - return blocks.contains(blockName); + if (blocks.contains(blockName) && pasteOptions.isOnlyColors()) return true; + if (pasteOptions.isTestBlock() && blockName.startsWith("minecraft:water")) return false; + return true; } @Nullable @@ -168,6 +172,9 @@ public class FlatteningWrapper15 implements FlatteningWrapper { public Mask2D toMask2D() { return null; } + public Mask copy() { + return this; + } }); ClipboardHolder ch = new ClipboardHolder(clipboard); @@ -182,7 +189,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper { } if (pasteOptions.isReset()) { - e.setBlocks((Region) new CuboidRegion(toBlockVector3(pasteOptions.getMinPoint()), toBlockVector3(pasteOptions.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock()); + e.setBlocks(new CuboidRegion(toBlockVector3(pasteOptions.getMinPoint()), toBlockVector3(pasteOptions.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock()); if (pasteOptions.getWaterLevel() != 0) { e.setBlocks((Region) new CuboidRegion(toBlockVector3(pasteOptions.getMinPoint()), toBlockVector3(pasteOptions.getMaxPoint()).withY(pasteOptions.getWaterLevel())), Objects.requireNonNull(BlockTypes.WATER).getDefaultState().toBaseBlock()); } -- 2.39.2 From 55a63dacaf6b596dc1ae1b3cd8f525d512044c6c Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 6 Feb 2023 21:38:12 +0100 Subject: [PATCH 07/22] es kann sein das da was fehlt, da ich mit den commits durcheinander gekommen bin --- .../bausystem/utils/FlatteningWrapper15.java | 10 ++++++-- .../features/region/TestblockCommand.java | 4 ++-- .../bausystem/region/PasteOptions.java | 24 ------------------- .../de/steamwar/bausystem/region/Region.java | 16 ++++++------- 4 files changed, 18 insertions(+), 36 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index fb02039e..c64ae034 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -19,6 +19,8 @@ package de.steamwar.bausystem.utils; +import com.google.common.collect.ImmutableMap; +import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; @@ -42,8 +44,9 @@ import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; -import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.region.PasteOptions; import de.steamwar.bausystem.region.Point; @@ -61,7 +64,10 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.util.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; import java.util.logging.Level; public class FlatteningWrapper15 implements FlatteningWrapper { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index 2db16400..a677e4df 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -57,7 +57,7 @@ public class TestblockCommand extends SWCommand { Region region = regionCheck(p); if (region == null) return; try { - region.reset(RegionType.TESTBLOCK, regionExtensionType, true); + region.reset(RegionType.TESTBLOCK, regionExtensionType); RegionUtils.message(region, "REGION_TB_DONE"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); @@ -86,7 +86,7 @@ public class TestblockCommand extends SWCommand { } try { - region.reset(node, RegionType.TESTBLOCK, regionExtensionType, true); + region.reset(node, RegionType.TESTBLOCK, regionExtensionType); RegionUtils.message(region, "REGION_TB_DONE"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java index c782a06b..fe64f44c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java @@ -28,44 +28,20 @@ import lombok.Getter; @AllArgsConstructor public class PasteOptions { - /** - * Used in 1.15 - */ private final boolean rotate; - /** - * Used in 1.15 - */ private final boolean ignoreAir; - /** - * Used in 1.15 - */ private final Color color; - /** - * Used in 1.15 - */ private final boolean onlyColors; - /** - * Used in 1.15 - */ private final boolean reset; - /** - * Used in 1.15 - */ private final Point minPoint; - /** - * Used in 1.15 - */ private final Point maxPoint; - /** - * Used in 1.15 - */ private final int waterLevel; private final boolean testBlock; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index e2787034..2f79be02 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -421,12 +421,12 @@ public class Region { reset(schematic, regionType, RegionExtensionType.NORMAL, false); } - public void reset(RegionType regionType, RegionExtensionType regionExtensionType, boolean isTestBlock) throws IOException { - reset(null, regionType, regionExtensionType, isTestBlock); + public void reset(RegionType regionType, RegionExtensionType regionExtensionType) throws IOException { + reset(null, regionType, regionExtensionType); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean isTestBlock) throws IOException { - reset(schematic, regionType, regionExtensionType, false, isTestBlock); + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType) throws IOException { + reset(schematic, regionType, regionExtensionType, false); } public void reset(File file) { @@ -435,11 +435,11 @@ public class Region { undoSessions.push(editSession); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean isTestBlock) throws IOException { - reset(schematic, regionType, regionExtensionType, ignoreAir, false, isTestBlock); + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir) throws IOException { + reset(schematic, regionType, regionExtensionType, ignoreAir, false); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors, boolean isTestBlock) throws IOException { + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors) throws IOException { if (!hasReset(regionType)) { return; } @@ -447,7 +447,7 @@ public class Region { regionExtensionType = RegionExtensionType.NORMAL; } - PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel, isTestBlock); + PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel, regionType == RegionType.TESTBLOCK); Point pastePoint; File tempFile = null; -- 2.39.2 From 5d55784f7987e19378410b56403003aeb043c9e2 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 16 Feb 2023 21:53:52 +0100 Subject: [PATCH 08/22] sollte jetzt auch mit waterlogged blocks gehen --- .../steamwar/bausystem/utils/FlatteningWrapper15.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index c64ae034..3545dd1a 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -19,8 +19,6 @@ package de.steamwar.bausystem.utils; -import com.google.common.collect.ImmutableMap; -import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; @@ -45,11 +43,11 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.region.PasteOptions; import de.steamwar.bausystem.region.Point; +import net.minecraft.server.v1_15_R1.AreaFactory; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; @@ -169,7 +167,12 @@ public class FlatteningWrapper15 implements FlatteningWrapper { BaseBlock block = clipboard.getFullBlock(blockVector3); String blockName = block.toString().toLowerCase(); if (blocks.contains(blockName) && pasteOptions.isOnlyColors()) return true; - if (pasteOptions.isTestBlock() && blockName.startsWith("minecraft:water")) return false; + if (pasteOptions.isTestBlock()) { + if (blockName.startsWith("minecraft:water")) return false; + if (block.toString().toLowerCase().contains("waterlogged=true")) return false; + } + + return true; } -- 2.39.2 From 2f66580e60df33eada3d57b15a41836816b37aba Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 18 Feb 2023 13:41:02 +0100 Subject: [PATCH 09/22] sollte jetzt klappen, ich werde versuchen mehr in die devlabs rein zuschauen --- .../steamwar/bausystem/utils/FlatteningWrapper15.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index 3545dd1a..4e7e57ac 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -34,6 +34,7 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operations; +import com.sk89q.worldedit.function.pattern.WaterloggedRemover; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.regions.CuboidRegion; @@ -42,12 +43,10 @@ import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.region.PasteOptions; import de.steamwar.bausystem.region.Point; -import net.minecraft.server.v1_15_R1.AreaFactory; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; @@ -166,10 +165,15 @@ public class FlatteningWrapper15 implements FlatteningWrapper { public boolean test(BlockVector3 blockVector3) { BaseBlock block = clipboard.getFullBlock(blockVector3); String blockName = block.toString().toLowerCase(); + if (blocks.contains(blockName) && pasteOptions.isOnlyColors()) return true; if (pasteOptions.isTestBlock()) { if (blockName.startsWith("minecraft:water")) return false; - if (block.toString().toLowerCase().contains("waterlogged=true")) return false; + if (blockName.contains("waterlogged=true")) try { + e.setBlock(blockVector3, new WaterloggedRemover(clipboard).applyBlock(blockVector3)); + } catch (WorldEditException ex) { + throw new RuntimeException(ex); + } } -- 2.39.2 From 1fe2394e0141bb870df19edbe8e61508ac155028 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Thu, 27 Jul 2023 01:08:55 +0200 Subject: [PATCH 10/22] Add option for tnt less pasting --- .../bausystem/utils/FlatteningWrapper15.java | 2 +- .../features/region/TestblockCommand.java | 6 ++++-- .../bausystem/region/PasteOptions.java | 2 ++ .../de/steamwar/bausystem/region/Region.java | 18 +++++++++--------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index 4e7e57ac..5acf6d52 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -147,7 +147,6 @@ public class FlatteningWrapper15 implements FlatteningWrapper { changeColor(clipboard, pasteOptions.getColor()); } - Set blocks = new HashSet<>(); { blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_wool"); @@ -174,6 +173,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper { } catch (WorldEditException ex) { throw new RuntimeException(ex); } + if (blockName.startsWith("minecraft:tnt")) return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index a677e4df..e7ddb346 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -57,7 +57,7 @@ public class TestblockCommand extends SWCommand { Region region = regionCheck(p); if (region == null) return; try { - region.reset(RegionType.TESTBLOCK, regionExtensionType); + region.reset(RegionType.TESTBLOCK, regionExtensionType, regionExtensionType == null); RegionUtils.message(region, "REGION_TB_DONE"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); @@ -86,7 +86,7 @@ public class TestblockCommand extends SWCommand { } try { - region.reset(node, RegionType.TESTBLOCK, regionExtensionType); + region.reset(node, RegionType.TESTBLOCK, regionExtensionType,true); RegionUtils.message(region, "REGION_TB_DONE"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); @@ -101,6 +101,8 @@ public class TestblockCommand extends SWCommand { showModeParameterTypesMap.put("-n", RegionExtensionType.NORMAL); showModeParameterTypesMap.put("-extension", RegionExtensionType.EXTENSION); showModeParameterTypesMap.put("-e", RegionExtensionType.EXTENSION); + showModeParameterTypesMap.put("-t", null); + showModeParameterTypesMap.put("-tnt", null); List tabCompletes = new ArrayList<>(showModeParameterTypesMap.keySet()); return SWCommandUtils.createMapper(s -> showModeParameterTypesMap.getOrDefault(s, null), s -> tabCompletes); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java index fe64f44c..ca151b54 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java @@ -45,4 +45,6 @@ public class PasteOptions { private final int waterLevel; private final boolean testBlock; + + private final boolean removeTNT; } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 2f79be02..83928d91 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -421,25 +421,25 @@ public class Region { reset(schematic, regionType, RegionExtensionType.NORMAL, false); } - public void reset(RegionType regionType, RegionExtensionType regionExtensionType) throws IOException { - reset(null, regionType, regionExtensionType); + public void reset(RegionType regionType, RegionExtensionType regionExtensionType,boolean removeTNT) throws IOException { + reset(null, regionType, regionExtensionType,removeTNT); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType) throws IOException { - reset(schematic, regionType, regionExtensionType, false); + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType,boolean removeTNT) throws IOException { + reset(schematic, regionType, regionExtensionType, false,removeTNT); } public void reset(File file) { - EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, false, false, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel, false)); + EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, false, false, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel, false,false)); initSessions(); undoSessions.push(editSession); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir) throws IOException { - reset(schematic, regionType, regionExtensionType, ignoreAir, false); + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean removeTNT) throws IOException { + reset(schematic, regionType, regionExtensionType, ignoreAir, false,removeTNT); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors) throws IOException { + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors,boolean removeTNT) throws IOException { if (!hasReset(regionType)) { return; } @@ -447,7 +447,7 @@ public class Region { regionExtensionType = RegionExtensionType.NORMAL; } - PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel, regionType == RegionType.TESTBLOCK); + PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel, regionType == RegionType.TESTBLOCK,removeTNT); Point pastePoint; File tempFile = null; -- 2.39.2 From 9ad455ea2d133d25c31872b1633737192ed0f8c4 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Thu, 27 Jul 2023 01:09:52 +0200 Subject: [PATCH 11/22] fix logic flaw --- .../src/de/steamwar/bausystem/utils/FlatteningWrapper15.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index 5acf6d52..00455db9 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -173,7 +173,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper { } catch (WorldEditException ex) { throw new RuntimeException(ex); } - if (blockName.startsWith("minecraft:tnt")) return false; + if (blockName.startsWith("minecraft:tnt") && pasteOptions.isRemoveTNT()) return false; } -- 2.39.2 From edfc331d034ae2df85b6e3a380c91d45b7dbc1e9 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Thu, 27 Jul 2023 15:43:55 +0200 Subject: [PATCH 12/22] Use parameters --- .../features/region/TestblockCommand.java | 123 +++++++++++++++--- 1 file changed, 107 insertions(+), 16 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index e7ddb346..ec6d5562 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -21,6 +21,9 @@ package de.steamwar.bausystem.features.region; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.features.tracer.TraceCommand; +import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; +import de.steamwar.bausystem.features.tracer.show.ShowModeParameterType; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.utils.RegionExtensionType; @@ -29,16 +32,18 @@ import de.steamwar.command.*; import de.steamwar.linkage.Linked; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; +import java.util.function.Supplier; import java.util.logging.Level; +import java.util.stream.Collectors; @Linked public class TestblockCommand extends SWCommand { @@ -86,7 +91,7 @@ public class TestblockCommand extends SWCommand { } try { - region.reset(node, RegionType.TESTBLOCK, regionExtensionType,true); + region.reset(node, RegionType.TESTBLOCK, regionExtensionType,false); RegionUtils.message(region, "REGION_TB_DONE"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); @@ -94,18 +99,47 @@ public class TestblockCommand extends SWCommand { } } - @ClassMapper(value = RegionExtensionType.class, local = true) - private TypeMapper regionExtensionTypeTypeMapper() { - Map showModeParameterTypesMap = new HashMap<>(); - showModeParameterTypesMap.put("-normal", RegionExtensionType.NORMAL); - showModeParameterTypesMap.put("-n", RegionExtensionType.NORMAL); - showModeParameterTypesMap.put("-extension", RegionExtensionType.EXTENSION); - showModeParameterTypesMap.put("-e", RegionExtensionType.EXTENSION); - showModeParameterTypesMap.put("-t", null); - showModeParameterTypesMap.put("-tnt", null); + @ClassMapper(value = TestblockParamaterType.class, local = true) + private TypeMapper testblockParamaterTypeMapper() { + Map> testblockParamaterTypeListMap = new EnumMap<>(TestblockParamaterType.class); + for (TestblockParamaterType value : TestblockParamaterType.values()) { + testblockParamaterTypeListMap.put(value, value.getTabCompletes()); + } - List tabCompletes = new ArrayList<>(showModeParameterTypesMap.keySet()); - return SWCommandUtils.createMapper(s -> showModeParameterTypesMap.getOrDefault(s, null), s -> tabCompletes); + Map testblockParameterTypesMap = new HashMap<>(); + testblockParamaterTypeListMap.forEach((k, v) -> v.forEach(s -> testblockParameterTypesMap.put(s, k))); + + return new TypeMapper() { + @Override + public TestblockParamaterType map(CommandSender commandSender, PreviousArguments previousArguments, String s) { + return testblockParameterTypesMap.get(s); + } + + @Override + public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { + Set testblockParameterTypeSet = new HashSet<>(); + previousArguments.getAll(TestblockParamaterType.class).forEach(showModeType -> { + testblockParameterTypeSet.addAll(Arrays.asList(showModeType.removed.get())); + }); + Arrays.stream(previousArguments.userArgs).map(testblockParameterTypesMap::get).forEach(testblockParameterTypeSet::add); + testblockParameterTypeSet.remove(null); + + Set removed = testblockParameterTypeSet.stream() + .map(TestblockParamaterType::getRemoved) + .map(Supplier::get) + .flatMap(Arrays::stream) + .collect(Collectors.toSet()); + + List tabCompletes = new ArrayList<>(); + for (Map.Entry> entry : testblockParamaterTypeListMap.entrySet()) { + if (removed.contains(entry.getKey()) || testblockParameterTypeSet.contains(entry.getKey())) { + continue; + } + tabCompletes.addAll(entry.getValue()); + } + return tabCompletes; + } + }; } @ClassValidator(value = Player.class, local = true) @@ -144,4 +178,61 @@ public class TestblockCommand extends SWCommand { } }; } + + private enum TestblockParamaterType { + NORMAL(TestblockParameter::enableWater, Arrays.asList("-n","-normal"), "EXTENSION"), + EXTENSION(TestblockParameter::enableExtension, Arrays.asList("-e", "-extension"), "NORMAL"), + TNT(TestblockParameter::enableTNT, Arrays.asList("-t", "-interpolate-x", "-tnt")), + WATER(TestblockParameter::enableWater, Arrays.asList("-w", "-water")); + + @Getter + private final Consumer testblockParameterConsumer; + + @Getter + private List tabCompletes; + + @Getter + private final Supplier removed; + private AtomicReference cached = new AtomicReference<>(); + + TestblockParamaterType(Consumer testblockParameterConsumer, List tabCompletes, String... removed) { + this.testblockParameterConsumer = testblockParameterConsumer; + this.tabCompletes = tabCompletes; + this.removed = () -> { + if (cached.get() == null) { + TestblockParamaterType[] showModeParameterTypes = new TestblockParamaterType[removed.length]; + for (int i = 0; i < removed.length; i++) { + showModeParameterTypes[i] = TestblockParamaterType.valueOf(removed[i]); + } + cached.set(showModeParameterTypes); + return showModeParameterTypes; + } + return cached.get(); + }; + } + } + + @Getter + private class TestblockParameter { + private boolean water = false; + private boolean tnt = false; + private boolean extension = false; + private boolean normal = false; + + public void enableWater() { + this.water = true; + } + + public void enableTNT() { + this.tnt = true; + } + + public void enableExtension() { + this.extension = true; + } + + public void enableNormal() { + this.normal = true; + } + } } -- 2.39.2 From d8b93e976f6d8c0781b9d472c466d84b7ac551a0 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Fri, 28 Jul 2023 21:41:56 +0200 Subject: [PATCH 13/22] Implement Testblock Command --- .../features/region/TestblockCommand.java | 114 ++++++++---------- .../region/items/TestblockBauGuiItem.java | 2 +- .../bausystem/region/PasteOptions.java | 2 + .../de/steamwar/bausystem/region/Region.java | 26 +--- 4 files changed, 55 insertions(+), 89 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index ec6d5562..67c741ce 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -52,46 +52,30 @@ public class TestblockCommand extends SWCommand { super("testblock", "tb", "dummy"); } - @Register(description = "REGION_TB_HELP_RESET") - public void genericTestblockCommand(Player p) { - genericTestblockCommand(p, RegionExtensionType.NORMAL); - } - - @Register(description = "REGION_TB_HELP_RESET_EXTENSION") - public void genericTestblockCommand(@Validator Player p, RegionExtensionType regionExtensionType) { - Region region = regionCheck(p); - if (region == null) return; - try { - region.reset(RegionType.TESTBLOCK, regionExtensionType, regionExtensionType == null); - RegionUtils.message(region, "REGION_TB_DONE"); - } catch (IOException e) { - BauSystem.MESSAGE.send("REGION_TB_ERROR", p); - Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e); - } - } - - @Register(description = "REGION_TB_HELP_SCHEMATIC") - public void schematicTestblockCommand(Player p, @Mapper("withPublic") SchematicNode node) { - schematicTestblockCommand(p, node, RegionExtensionType.NORMAL); - } - @Register - public void schematicTestblockCommand(Player p, RegionExtensionType regionExtensionType, @Mapper("withPublic") SchematicNode node) { - schematicTestblockCommand(p, node, regionExtensionType); + public void schematicTestblockCommand(@Validator Player p,@OptionalValue("") @Mapper("withPublic") @AllowNull SchematicNode node,TestblockParameter... testblockParameters) { + boolean isExtension = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.extension); + boolean isIgnoreAir = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.ignoreAir); + boolean isOnlyColor = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.onlyColor); + boolean replaceTNT = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.tnt); + boolean replaceWater = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.water); + + resetRegion(p,node,isExtension ? RegionExtensionType.EXTENSION : RegionExtensionType.NORMAL,isIgnoreAir,isOnlyColor,replaceTNT,replaceWater); } - @Register(description = "REGION_TB_HELP_SCHEMATIC_EXTENSION") - public void schematicTestblockCommand(@Validator Player p, @Mapper("withPublic") SchematicNode node, RegionExtensionType regionExtensionType) { + private void resetRegion(Player p,SchematicNode node, RegionExtensionType regionExtensionType,boolean ignoreAir,boolean onlyColors, boolean removeTNT, boolean removeWater) { Region region = regionCheck(p); if (region == null) return; - if(node.isDir()) { - BauSystem.MESSAGE.send("ONLY_SCHEMS", p); - return; - } + if(node != null) { + if(node.isDir()) { + BauSystem.MESSAGE.send("ONLY_SCHEMS", p); + return; + } + } try { - region.reset(node, RegionType.TESTBLOCK, regionExtensionType,false); + region.reset(node,RegionType.TESTBLOCK, regionExtensionType,ignoreAir,onlyColors,removeTNT,removeWater); RegionUtils.message(region, "REGION_TB_DONE"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); @@ -99,39 +83,39 @@ public class TestblockCommand extends SWCommand { } } - @ClassMapper(value = TestblockParamaterType.class, local = true) - private TypeMapper testblockParamaterTypeMapper() { - Map> testblockParamaterTypeListMap = new EnumMap<>(TestblockParamaterType.class); - for (TestblockParamaterType value : TestblockParamaterType.values()) { - testblockParamaterTypeListMap.put(value, value.getTabCompletes()); + @ClassMapper(value = TestblockParameterType.class, local = true) + private TypeMapper testblockParameterTypeMapper() { + Map> testblockParameterTypeListMap = new EnumMap<>(TestblockParameterType.class); + for (TestblockParameterType value : TestblockParameterType.values()) { + testblockParameterTypeListMap.put(value, value.getTabCompletes()); } - Map testblockParameterTypesMap = new HashMap<>(); - testblockParamaterTypeListMap.forEach((k, v) -> v.forEach(s -> testblockParameterTypesMap.put(s, k))); + Map testblockParameterTypesMap = new HashMap<>(); + testblockParameterTypeListMap.forEach((k, v) -> v.forEach(s -> testblockParameterTypesMap.put(s, k))); - return new TypeMapper() { + return new TypeMapper() { @Override - public TestblockParamaterType map(CommandSender commandSender, PreviousArguments previousArguments, String s) { + public TestblockParameterType map(CommandSender commandSender, PreviousArguments previousArguments, String s) { return testblockParameterTypesMap.get(s); } @Override public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { - Set testblockParameterTypeSet = new HashSet<>(); - previousArguments.getAll(TestblockParamaterType.class).forEach(showModeType -> { + Set testblockParameterTypeSet = new HashSet<>(); + previousArguments.getAll(TestblockParameterType.class).forEach(showModeType -> { testblockParameterTypeSet.addAll(Arrays.asList(showModeType.removed.get())); }); Arrays.stream(previousArguments.userArgs).map(testblockParameterTypesMap::get).forEach(testblockParameterTypeSet::add); testblockParameterTypeSet.remove(null); - Set removed = testblockParameterTypeSet.stream() - .map(TestblockParamaterType::getRemoved) + Set removed = testblockParameterTypeSet.stream() + .map(TestblockParameterType::getRemoved) .map(Supplier::get) .flatMap(Arrays::stream) .collect(Collectors.toSet()); List tabCompletes = new ArrayList<>(); - for (Map.Entry> entry : testblockParamaterTypeListMap.entrySet()) { + for (Map.Entry> entry : testblockParameterTypeListMap.entrySet()) { if (removed.contains(entry.getKey()) || testblockParameterTypeSet.contains(entry.getKey())) { continue; } @@ -144,9 +128,7 @@ public class TestblockCommand extends SWCommand { @ClassValidator(value = Player.class, local = true) public TypeValidator validator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "REGION_TB_NO_PERMS"); - }; + return (commandSender, player, messageSender) -> !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "REGION_TB_NO_PERMS"); } private Region regionCheck(Player player) { @@ -179,11 +161,12 @@ public class TestblockCommand extends SWCommand { }; } - private enum TestblockParamaterType { - NORMAL(TestblockParameter::enableWater, Arrays.asList("-n","-normal"), "EXTENSION"), - EXTENSION(TestblockParameter::enableExtension, Arrays.asList("-e", "-extension"), "NORMAL"), - TNT(TestblockParameter::enableTNT, Arrays.asList("-t", "-interpolate-x", "-tnt")), - WATER(TestblockParameter::enableWater, Arrays.asList("-w", "-water")); + private enum TestblockParameterType { + EXTENSION(TestblockParameter::enableExtension, Arrays.asList("-e", "-extension")), + TNT(TestblockParameter::enableTNT, Arrays.asList("-t", "-tnt")), + WATER(TestblockParameter::enableWater, Arrays.asList("-w", "-water")), + IGNORE_AIR(TestblockParameter::enableIgnoreAir, Arrays.asList("-ig", "-ignore_air")), + ONLY_COLOR(TestblockParameter::enableOnlyColor, Arrays.asList("-o","-color","-only_color")); @Getter private final Consumer testblockParameterConsumer; @@ -192,17 +175,17 @@ public class TestblockCommand extends SWCommand { private List tabCompletes; @Getter - private final Supplier removed; - private AtomicReference cached = new AtomicReference<>(); + private final Supplier removed; + private AtomicReference cached = new AtomicReference<>(); - TestblockParamaterType(Consumer testblockParameterConsumer, List tabCompletes, String... removed) { + TestblockParameterType(Consumer testblockParameterConsumer, List tabCompletes, String... removed) { this.testblockParameterConsumer = testblockParameterConsumer; this.tabCompletes = tabCompletes; this.removed = () -> { if (cached.get() == null) { - TestblockParamaterType[] showModeParameterTypes = new TestblockParamaterType[removed.length]; + TestblockParameterType[] showModeParameterTypes = new TestblockParameterType[removed.length]; for (int i = 0; i < removed.length; i++) { - showModeParameterTypes[i] = TestblockParamaterType.valueOf(removed[i]); + showModeParameterTypes[i] = TestblockParameterType.valueOf(removed[i]); } cached.set(showModeParameterTypes); return showModeParameterTypes; @@ -212,12 +195,13 @@ public class TestblockCommand extends SWCommand { } } - @Getter - private class TestblockParameter { + public static class TestblockParameter { private boolean water = false; private boolean tnt = false; private boolean extension = false; - private boolean normal = false; + private boolean onlyColor = false; + + private boolean ignoreAir = false; public void enableWater() { this.water = true; @@ -231,8 +215,8 @@ public class TestblockCommand extends SWCommand { this.extension = true; } - public void enableNormal() { - this.normal = true; - } + public void enableOnlyColor() { this.onlyColor = true; } + + public void enableIgnoreAir() { this.ignoreAir = true; } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockBauGuiItem.java index 2b3b863a..07ede055 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockBauGuiItem.java @@ -51,7 +51,7 @@ public class TestblockBauGuiItem extends BauGuiItem { public boolean click(ClickType click, Player p) { if (click == ClickType.LEFT) { p.closeInventory(); - testblockCommand.genericTestblockCommand(p); + testblockCommand.schematicTestblockCommand(p,null); } else { SchematicSelector selector = new SchematicSelector(p, SchematicSelector.selectSchematic(), node -> { p.closeInventory(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java index ca151b54..ec8186f4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java @@ -47,4 +47,6 @@ public class PasteOptions { private final boolean testBlock; private final boolean removeTNT; + + private final boolean removeWater; } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 83928d91..040a7f99 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -413,33 +413,13 @@ public class Region { } } - public void reset(RegionType regionType) throws IOException { - reset(null, regionType); - } - - public void reset(SchematicNode schematic, RegionType regionType) throws IOException { - reset(schematic, regionType, RegionExtensionType.NORMAL, false); - } - - public void reset(RegionType regionType, RegionExtensionType regionExtensionType,boolean removeTNT) throws IOException { - reset(null, regionType, regionExtensionType,removeTNT); - } - - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType,boolean removeTNT) throws IOException { - reset(schematic, regionType, regionExtensionType, false,removeTNT); - } - public void reset(File file) { - EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, false, false, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel, false,false)); + EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, false, false, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel, false,false,false)); initSessions(); undoSessions.push(editSession); } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean removeTNT) throws IOException { - reset(schematic, regionType, regionExtensionType, ignoreAir, false,removeTNT); - } - - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors,boolean removeTNT) throws IOException { + public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors,boolean removeTNT, boolean removeWater) throws IOException { if (!hasReset(regionType)) { return; } @@ -447,7 +427,7 @@ public class Region { regionExtensionType = RegionExtensionType.NORMAL; } - PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel, regionType == RegionType.TESTBLOCK,removeTNT); + PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel, regionType == RegionType.TESTBLOCK,removeTNT,removeWater); Point pastePoint; File tempFile = null; -- 2.39.2 From 8a01394092c973e52c42b1f11fc64238b0b7c8e7 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Fri, 28 Jul 2023 21:52:07 +0200 Subject: [PATCH 14/22] Make things actually build --- .../de/steamwar/bausystem/features/region/ColorCommand.java | 2 +- .../steamwar/bausystem/features/region/RegionCommand.java | 4 ++-- .../de/steamwar/bausystem/features/region/ResetCommand.java | 5 +++-- .../bausystem/features/region/TestblockCommand.java | 6 ++++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java index 1213a314..06c63753 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java @@ -64,7 +64,7 @@ public class ColorCommand extends SWCommand { } region.set(Flag.COLOR, color); try { - region.reset(null, RegionType.NORMAL, RegionExtensionType.NORMAL, true, true); + region.reset(null, RegionType.NORMAL, RegionExtensionType.NORMAL, true, true,false,false); RegionUtils.message(region, "REGION_REGION_COLORED"); RegionUtils.message(region, "REGION_REGION_COLORED_FAILED"); } catch (IOException e) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java index 0288fbae..11100c81 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java @@ -99,7 +99,7 @@ public class RegionCommand extends SWCommand { if(checkGlobalRegion(region, p)) return; try { - region.reset(null, RegionType.NORMAL, RegionExtensionType.NORMAL, true, false); + region.reset(null, RegionType.NORMAL, RegionExtensionType.NORMAL, true, false,false,false); RegionUtils.message(region, "REGION_REGION_RESTORED"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_REGION_FAILED_RESTORE", p); @@ -118,7 +118,7 @@ public class RegionCommand extends SWCommand { } try { - region.reset(node, RegionType.NORMAL, RegionExtensionType.NORMAL, true); + region.reset(node, RegionType.NORMAL, RegionExtensionType.NORMAL, true,false,false,false); RegionUtils.message(region, "REGION_REGION_RESTORED"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_REGION_FAILED_RESTORE", p); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java index d057d59f..97bd6711 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; +import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; @@ -54,7 +55,7 @@ public class ResetCommand extends SWCommand { Region region = regionCheck(p); if (region == null) return; try { - region.reset(null, RegionType.NORMAL); + region.reset(null,RegionType.NORMAL, RegionExtensionType.NORMAL,false,false,false,false); RegionUtils.message(region, "REGION_RESET_RESETED"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_RESET_ERROR", p); @@ -80,7 +81,7 @@ public class ResetCommand extends SWCommand { return; } try { - region.reset(node, RegionType.NORMAL); + region.reset(node, RegionType.NORMAL,RegionExtensionType.NORMAL,false,false,false,false); RegionUtils.message(region, "REGION_RESET_RESETED"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_RESET_ERROR", p); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index 9bff99b4..00fe8fc8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -26,10 +26,12 @@ import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; -import de.steamwar.command.*; +import de.steamwar.command.PreviousArguments; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; +import de.steamwar.command.TypeValidator; import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; -import de.steamwar.command.PreviousArguments; import de.steamwar.sql.Punishment; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; -- 2.39.2 From ad55b25cf05fc185365c27ecf678b8bfc55fe3f8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 28 Jul 2023 22:16:55 +0200 Subject: [PATCH 15/22] Fix TestblockCommand Signed-off-by: yoyosource --- .../features/region/TestblockCommand.java | 95 ++++++++++--------- 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index 00fe8fc8..df29c1df 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -59,26 +59,27 @@ public class TestblockCommand extends SWCommand { } @Register - public void schematicTestblockCommand(@Validator Player p,@OptionalValue("") @Mapper("withPublic") @AllowNull SchematicNode node,TestblockParameter... testblockParameters) { - boolean isExtension = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.extension); - boolean isIgnoreAir = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.ignoreAir); - boolean isOnlyColor = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.onlyColor); - boolean replaceTNT = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.tnt); - boolean replaceWater = Arrays.stream(testblockParameters).anyMatch(testblockParameter -> testblockParameter.water); + public void schematicTestblockCommand(@Validator Player p, @OptionalValue("") @Mapper("withPublic") @AllowNull SchematicNode node, TestblockParameterType... testblockParameterTypes) { + Set testblockParameterTypesSet = new HashSet<>(Arrays.asList(testblockParameterTypes)); + boolean isExtension = testblockParameterTypesSet.contains(TestblockParameterType.EXTENSION); + boolean isIgnoreAir = testblockParameterTypesSet.contains(TestblockParameterType.IGNORE_AIR); + boolean isOnlyColor = testblockParameterTypesSet.contains(TestblockParameterType.ONLY_COLOR); + boolean replaceTNT = testblockParameterTypesSet.contains(TestblockParameterType.TNT); + boolean replaceWater = testblockParameterTypesSet.contains(TestblockParameterType.WATER); - resetRegion(p,node,isExtension ? RegionExtensionType.EXTENSION : RegionExtensionType.NORMAL,isIgnoreAir,isOnlyColor,replaceTNT,replaceWater); + resetRegion(p, node, isExtension ? RegionExtensionType.EXTENSION : RegionExtensionType.NORMAL, isIgnoreAir, isOnlyColor, replaceTNT, replaceWater); } - private void resetRegion(Player p,SchematicNode node, RegionExtensionType regionExtensionType,boolean ignoreAir,boolean onlyColors, boolean removeTNT, boolean removeWater) { + private void resetRegion(Player p, SchematicNode node, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors, boolean removeTNT, boolean removeWater) { Region region = regionCheck(p); if (region == null) return; - if(node != null) { - if(node.isDir()) { - BauSystem.MESSAGE.send("ONLY_SCHEMS", p); - return; - } - } + if (node != null) { + if (node.isDir()) { + BauSystem.MESSAGE.send("ONLY_SCHEMS", p); + return; + } + } if (bauServer.getOwner() != p.getUniqueId()) { if (Punishment.isPunished(SteamwarUser.get(p.getUniqueId()), Punishment.PunishmentType.NoSchemSharing, punishment -> BauSystem.MESSAGE.parse("REGION_TB_NO_SCHEMSHARING", p, punishment.getEndTime()))) { @@ -89,7 +90,7 @@ public class TestblockCommand extends SWCommand { } try { - region.reset(node,RegionType.TESTBLOCK, regionExtensionType,ignoreAir,onlyColors,removeTNT,removeWater); + region.reset(node, RegionType.TESTBLOCK, regionExtensionType, ignoreAir, onlyColors, removeTNT, removeWater); RegionUtils.message(region, "REGION_TB_DONE"); } catch (IOException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); @@ -98,7 +99,7 @@ public class TestblockCommand extends SWCommand { } @ClassMapper(value = TestblockParameterType.class, local = true) - private TypeMapper testblockParameterTypeMapper() { + public TypeMapper testblockParameterTypeMapper() { Map> testblockParameterTypeListMap = new EnumMap<>(TestblockParameterType.class); for (TestblockParameterType value : TestblockParameterType.values()) { testblockParameterTypeListMap.put(value, value.getTabCompletes()); @@ -117,7 +118,7 @@ public class TestblockCommand extends SWCommand { public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { Set testblockParameterTypeSet = new HashSet<>(); previousArguments.getAll(TestblockParameterType.class).forEach(showModeType -> { - testblockParameterTypeSet.addAll(Arrays.asList(showModeType.removed.get())); + testblockParameterTypeSet.addAll(Arrays.asList(showModeType.getRemoved().get())); }); Arrays.stream(previousArguments.userArgs).map(testblockParameterTypesMap::get).forEach(testblockParameterTypeSet::add); testblockParameterTypeSet.remove(null); @@ -167,7 +168,7 @@ public class TestblockCommand extends SWCommand { @Override public SchematicNode map(CommandSender commandSender, PreviousArguments previousArguments, String s) { SchematicNode node = SchematicNode.getNodeFromPath(SteamwarUser.get(((Player) commandSender).getUniqueId()), s); - if(node == null) { + if (node == null) { node = SchematicNode.getNodeFromPath(SteamwarUser.get(0), s); } return node; @@ -175,12 +176,41 @@ public class TestblockCommand extends SWCommand { }; } - private enum TestblockParameterType { + public static class TestblockParameter { + private boolean water = false; + private boolean tnt = false; + private boolean extension = false; + private boolean onlyColor = false; + + private boolean ignoreAir = false; + + public void enableWater() { + this.water = true; + } + + public void enableTNT() { + this.tnt = true; + } + + public void enableExtension() { + this.extension = true; + } + + public void enableOnlyColor() { + this.onlyColor = true; + } + + public void enableIgnoreAir() { + this.ignoreAir = true; + } + } + + public enum TestblockParameterType { EXTENSION(TestblockParameter::enableExtension, Arrays.asList("-e", "-extension")), TNT(TestblockParameter::enableTNT, Arrays.asList("-t", "-tnt")), WATER(TestblockParameter::enableWater, Arrays.asList("-w", "-water")), IGNORE_AIR(TestblockParameter::enableIgnoreAir, Arrays.asList("-ig", "-ignore_air")), - ONLY_COLOR(TestblockParameter::enableOnlyColor, Arrays.asList("-o","-color","-only_color")); + ONLY_COLOR(TestblockParameter::enableOnlyColor, Arrays.asList("-o", "-color", "-only_color")); @Getter private final Consumer testblockParameterConsumer; @@ -208,29 +238,4 @@ public class TestblockCommand extends SWCommand { }; } } - - public static class TestblockParameter { - private boolean water = false; - private boolean tnt = false; - private boolean extension = false; - private boolean onlyColor = false; - - private boolean ignoreAir = false; - - public void enableWater() { - this.water = true; - } - - public void enableTNT() { - this.tnt = true; - } - - public void enableExtension() { - this.extension = true; - } - - public void enableOnlyColor() { this.onlyColor = true; } - - public void enableIgnoreAir() { this.ignoreAir = true; } - } } -- 2.39.2 From b02eda9fe8c2ed1a543c2b10160e0ad1e1cb0fcb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 28 Jul 2023 22:54:19 +0200 Subject: [PATCH 16/22] Fix TestblockCommand Signed-off-by: yoyosource --- .../bausystem/features/region/TestblockCommand.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index df29c1df..64164912 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -59,8 +59,14 @@ public class TestblockCommand extends SWCommand { } @Register - public void schematicTestblockCommand(@Validator Player p, @OptionalValue("") @Mapper("withPublic") @AllowNull SchematicNode node, TestblockParameterType... testblockParameterTypes) { + public void schematicTestblockCommand(@Validator Player p, TestblockParameterType... testblockParameterTypes) { + schematicTestblockCommand(p, null, testblockParameterTypes); + } + + @Register + public void schematicTestblockCommand(@Validator Player p, @Mapper("withPublic") SchematicNode node, TestblockParameterType... testblockParameterTypes) { Set testblockParameterTypesSet = new HashSet<>(Arrays.asList(testblockParameterTypes)); + System.out.println(testblockParameterTypesSet); boolean isExtension = testblockParameterTypesSet.contains(TestblockParameterType.EXTENSION); boolean isIgnoreAir = testblockParameterTypesSet.contains(TestblockParameterType.IGNORE_AIR); boolean isOnlyColor = testblockParameterTypesSet.contains(TestblockParameterType.ONLY_COLOR); -- 2.39.2 From 814a5f43641c78fda87933694656afbe6f3bfc34 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 29 Jul 2023 12:47:48 +0200 Subject: [PATCH 17/22] Add PasteBuilder as the new alternative to pasting via region.reset Signed-off-by: yoyosource --- .../bausystem/utils/FlatteningWrapper15.java | 136 ++++++++++++++++-- .../features/region/TestblockCommand.java | 1 - .../bausystem/region/PasteOptions.java | 2 + .../bausystem/utils/FlatteningWrapper.java | 6 +- .../bausystem/utils/PasteBuilder.java | 116 +++++++++++++++ 5 files changed, 245 insertions(+), 16 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index 4b69606e..e45f3cdc 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -65,6 +65,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Objects; import java.util.Set; +import java.util.function.BiPredicate; import java.util.logging.Level; public class FlatteningWrapper15 implements FlatteningWrapper { @@ -113,6 +114,75 @@ public class FlatteningWrapper15 implements FlatteningWrapper { WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, toBlockVector3(minPoint), toBlockVector3(maxPoint))); } + @Override + public Clipboard loadSchematic(File file) { + Clipboard clipboard; + try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) { + clipboard = reader.read(); + } catch (NullPointerException | IOException e) { + throw new SecurityException("Bausystem schematic not found", e); + } + return clipboard; + } + + @Override + public EditSession paste(PasteBuilder pasteBuilder) { + try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { + Clipboard clipboard = pasteBuilder.getClipboard(); + + BlockVector3 minimum = clipboard.getRegion().getMinimumPoint(); + for (int x = 0; x < clipboard.getDimensions().getX(); x++) { + for (int y = 0; y < clipboard.getDimensions().getY(); y++) { + for (int z = 0; z < clipboard.getDimensions().getZ(); z++) { + BlockVector3 pos = minimum.add(x, y, z); + pasteBuilder.getMappers().forEach(mapper -> mapper.accept(clipboard, pos)); + } + } + } + + e.setMask(new Mask() { + @Override + public boolean test(BlockVector3 blockVector3) { + if (pasteBuilder.getPredicates().isEmpty()) return true; + BaseBlock block = clipboard.getFullBlock(blockVector3); + String blockName = block.toString().toLowerCase(); + for (BiPredicate predicate : pasteBuilder.getPredicates()) { + if (!predicate.test(block, blockName)) return false; + } + return true; + } + + @Nullable + @Override + public Mask2D toMask2D() { + return null; + } + }); + + ClipboardHolder ch = new ClipboardHolder(clipboard); + BlockVector3 dimensions = clipboard.getDimensions(); + BlockVector3 v = BlockVector3.at(pasteBuilder.getPastPoint().getX(), pasteBuilder.getPastPoint().getY(), pasteBuilder.getPastPoint().getZ()); + BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); + if (pasteBuilder.isRotate()) { + ch.setTransform(new AffineTransform().rotateY(180)); + v = v.add(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset.multiply(-1, 1, -1)).subtract(0, 0, 1); + } else { + v = v.subtract(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset); + } + + if (pasteBuilder.isReset()) { + e.setBlocks(new CuboidRegion(toBlockVector3(pasteBuilder.getMinPoint()), toBlockVector3(pasteBuilder.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock()); + if (pasteBuilder.getWaterLevel() != 0) { + e.setBlocks(new CuboidRegion(toBlockVector3(pasteBuilder.getMinPoint()), toBlockVector3(pasteBuilder.getMaxPoint()).withY(pasteBuilder.getWaterLevel())), Objects.requireNonNull(BlockTypes.WATER).getDefaultState().toBaseBlock()); + } + } + Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(pasteBuilder.isIgnoreAir()).build()); + return e; + } catch (WorldEditException e) { + throw new SecurityException(e.getMessage(), e); + } + } + private static final BaseBlock WOOL = Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock(); private static final BaseBlock CLAY = Objects.requireNonNull(BlockTypes.PINK_TERRACOTTA).getDefaultState().toBaseBlock(); private static final BaseBlock GLAZED = Objects.requireNonNull(BlockTypes.PINK_GLAZED_TERRACOTTA).getDefaultState().toBaseBlock(); @@ -141,6 +211,12 @@ public class FlatteningWrapper15 implements FlatteningWrapper { if (pasteOptions.getColor() != Color.PINK) { changeColor(clipboard, pasteOptions.getColor()); } + if (pasteOptions.isTestBlock() && pasteOptions.isRemoveTNT()) { + removeTNT(clipboard); + } + if (pasteOptions.isTestBlock() && pasteOptions.isRemoveWater()) { + removeWater(clipboard); + } Set blocks = new HashSet<>(); { @@ -160,18 +236,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper { BaseBlock block = clipboard.getFullBlock(blockVector3); String blockName = block.toString().toLowerCase(); - if (blocks.contains(blockName) && pasteOptions.isOnlyColors()) return true; - if (pasteOptions.isTestBlock()) { - if (blockName.startsWith("minecraft:water")) return false; - if (blockName.contains("waterlogged=true")) try { - e.setBlock(blockVector3, new WaterloggedRemover(clipboard).applyBlock(blockVector3)); - } catch (WorldEditException ex) { - throw new RuntimeException(ex); - } - if (blockName.startsWith("minecraft:tnt") && pasteOptions.isRemoveTNT()) return false; - } - - + if (pasteOptions.isOnlyColors()) return blocks.contains(blockName); return true; } @@ -209,7 +274,6 @@ public class FlatteningWrapper15 implements FlatteningWrapper { } } - @Override public void changeColor(Clipboard clipboard, Color color) throws WorldEditException { BlockVector3 minimum = clipboard.getRegion().getMinimumPoint(); BaseBlock wool = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_wool")).getDefaultState().toBaseBlock(); @@ -248,6 +312,52 @@ public class FlatteningWrapper15 implements FlatteningWrapper { } } + public void removeTNT(Clipboard clipboard) throws WorldEditException { + BlockVector3 minimum = clipboard.getRegion().getMinimumPoint(); + BaseBlock tnt = Objects.requireNonNull(BlockTypes.get("tnt")).getDefaultState().toBaseBlock(); + BaseBlock air = Objects.requireNonNull(BlockTypes.get("air")).getDefaultState().toBaseBlock(); + + for (int x = 0; x < clipboard.getDimensions().getX(); x++) { + for (int y = 0; y < clipboard.getDimensions().getY(); y++) { + for (int z = 0; z < clipboard.getDimensions().getZ(); z++) { + BlockVector3 pos = minimum.add(x, y, z); + BaseBlock block = clipboard.getFullBlock(pos); + + if (block.equals(tnt)) { + clipboard.setBlock(pos, air); + } + } + } + } + } + + public void removeWater(Clipboard clipboard) throws WorldEditException { + BlockVector3 minimum = clipboard.getRegion().getMinimumPoint(); + BaseBlock water = Objects.requireNonNull(BlockTypes.get("water")).getDefaultState().toBaseBlock(); + BaseBlock air = Objects.requireNonNull(BlockTypes.get("air")).getDefaultState().toBaseBlock(); + WaterloggedRemover waterloggedRemover = new WaterloggedRemover(clipboard); + + for (int x = 0; x < clipboard.getDimensions().getX(); x++) { + for (int y = 0; y < clipboard.getDimensions().getY(); y++) { + for (int z = 0; z < clipboard.getDimensions().getZ(); z++) { + BlockVector3 pos = minimum.add(x, y, z); + BaseBlock block = clipboard.getFullBlock(pos); + + if (block.equals(water)) { + clipboard.setBlock(pos, air); + } else { + String blockName = block.getBlockType().getName(); + if (blockName.equals("Water")) { + clipboard.setBlock(pos, air); + } else if (blockName.contains("waterlogged=true")) { + clipboard.setBlock(pos, waterloggedRemover.applyBlock(pos)); + } + } + } + } + } + } + @Override public boolean backup(Point minPoint, Point maxPoint, File file) { BukkitWorld bukkitWorld = new BukkitWorld(Bukkit.getWorlds().get(0)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index 64164912..5fc76808 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -66,7 +66,6 @@ public class TestblockCommand extends SWCommand { @Register public void schematicTestblockCommand(@Validator Player p, @Mapper("withPublic") SchematicNode node, TestblockParameterType... testblockParameterTypes) { Set testblockParameterTypesSet = new HashSet<>(Arrays.asList(testblockParameterTypes)); - System.out.println(testblockParameterTypesSet); boolean isExtension = testblockParameterTypesSet.contains(TestblockParameterType.EXTENSION); boolean isIgnoreAir = testblockParameterTypesSet.contains(TestblockParameterType.IGNORE_AIR); boolean isOnlyColor = testblockParameterTypesSet.contains(TestblockParameterType.ONLY_COLOR); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java index ec8186f4..5be73fe6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java @@ -22,10 +22,12 @@ package de.steamwar.bausystem.region; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.ToString; @Getter @Builder @AllArgsConstructor +@ToString public class PasteOptions { private final boolean rotate; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java index 430bfe90..e80c4027 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java @@ -46,9 +46,11 @@ public interface FlatteningWrapper { boolean isWorldEditCommand(String command); void setSelection(Player p, Point minPoint, Point maxPoint); + Clipboard loadSchematic(File file); + EditSession paste(PasteBuilder pasteBuilder); + EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions); - EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions); - void changeColor(Clipboard clipboard, Color color) throws WorldEditException; + EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions); boolean backup(Point minPoint, Point maxPoint, File file); boolean inWater(World world, Vector tntPosition); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java new file mode 100644 index 00000000..b06cb221 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java @@ -0,0 +1,116 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.utils; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BaseBlock; +import de.steamwar.bausystem.region.Point; +import de.steamwar.sql.SchematicData; +import de.steamwar.sql.SchematicNode; +import lombok.Getter; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.function.BiConsumer; +import java.util.function.BiPredicate; + +@Getter +public class PasteBuilder { + + private final Clipboard clipboard; + private Point pastPoint; + private boolean rotate; + private boolean ignoreAir; + private boolean reset; + private Point minPoint; + private Point maxPoint; + private int waterLevel; + private List> predicates = new ArrayList<>(); + private List> mappers = new ArrayList<>(); + + public PasteBuilder(SchematicNode schematic) { + try { + this.clipboard = new SchematicData(schematic).load(); + } catch (IOException e) { + throw new SecurityException(e); + } + } + + public PasteBuilder(Clipboard clipboard) { + this.clipboard = clipboard; + } + + public PasteBuilder(File file) { + this.clipboard = FlatteningWrapper.impl.loadSchematic(file); + } + + public PasteBuilder pastePoint(Point point) { + this.pastPoint = point; + return this; + } + + public PasteBuilder rotate() { + this.rotate = true; + return this; + } + + public PasteBuilder ignoreAir() { + this.ignoreAir = true; + return this; + } + + public PasteBuilder reset() { + this.reset = true; + return this; + } + + public PasteBuilder minPoint(Point point) { + this.minPoint = point; + return this; + } + + public PasteBuilder maxPoint(Point point) { + this.maxPoint = point; + return this; + } + + public PasteBuilder waterLevel(int waterLevel) { + this.waterLevel = waterLevel; + return this; + } + + public PasteBuilder only(BiPredicate predicate) { + predicates.add(predicate); + return this; + } + + public PasteBuilder map(BiConsumer mapper) { + mappers.add(mapper); + return this; + } + + public EditSession run() { + return FlatteningWrapper.impl.paste(this); + } +} -- 2.39.2 From 3e27a0b36679144f3b499e78edbd6459481249c5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 30 Jul 2023 21:02:33 +0200 Subject: [PATCH 18/22] Update PasteBuilder and usages Signed-off-by: yoyosource --- .../bausystem/utils/FlatteningWrapper15.java | 47 +++-- .../features/backup/BackupCommand.java | 14 +- .../features/region/ColorCommand.java | 8 +- .../features/region/RegionCommand.java | 13 +- .../features/region/ResetCommand.java | 11 +- .../features/region/TestblockCommand.java | 14 +- .../de/steamwar/bausystem/region/Region.java | 76 +++---- .../bausystem/region/RegionUtils.java | 8 - .../bausystem/utils/PasteBuilder.java | 188 ++++++++++++++++-- 9 files changed, 277 insertions(+), 102 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index e45f3cdc..4b28c421 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -130,34 +130,37 @@ public class FlatteningWrapper15 implements FlatteningWrapper { try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { Clipboard clipboard = pasteBuilder.getClipboard(); - BlockVector3 minimum = clipboard.getRegion().getMinimumPoint(); - for (int x = 0; x < clipboard.getDimensions().getX(); x++) { - for (int y = 0; y < clipboard.getDimensions().getY(); y++) { - for (int z = 0; z < clipboard.getDimensions().getZ(); z++) { - BlockVector3 pos = minimum.add(x, y, z); - pasteBuilder.getMappers().forEach(mapper -> mapper.accept(clipboard, pos)); + if (!pasteBuilder.getMappers().isEmpty()) { + BlockVector3 minimum = clipboard.getRegion().getMinimumPoint(); + for (int x = 0; x < clipboard.getDimensions().getX(); x++) { + for (int y = 0; y < clipboard.getDimensions().getY(); y++) { + for (int z = 0; z < clipboard.getDimensions().getZ(); z++) { + BlockVector3 pos = minimum.add(x, y, z); + pasteBuilder.getMappers().forEach(mapper -> mapper.accept(clipboard, pos)); + } } } } - e.setMask(new Mask() { - @Override - public boolean test(BlockVector3 blockVector3) { - if (pasteBuilder.getPredicates().isEmpty()) return true; - BaseBlock block = clipboard.getFullBlock(blockVector3); - String blockName = block.toString().toLowerCase(); - for (BiPredicate predicate : pasteBuilder.getPredicates()) { - if (!predicate.test(block, blockName)) return false; + if (!pasteBuilder.getPredicates().isEmpty()) { + e.setMask(new Mask() { + @Override + public boolean test(BlockVector3 blockVector3) { + BaseBlock block = clipboard.getFullBlock(blockVector3); + String blockName = block.toString().toLowerCase(); + for (BiPredicate predicate : pasteBuilder.getPredicates()) { + if (!predicate.test(block, blockName)) return false; + } + return true; } - return true; - } - @Nullable - @Override - public Mask2D toMask2D() { - return null; - } - }); + @Nullable + @Override + public Mask2D toMask2D() { + return null; + } + }); + } ClipboardHolder ch = new ClipboardHolder(clipboard); BlockVector3 dimensions = clipboard.getDimensions(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java index 9799b628..38bfe194 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/backup/BackupCommand.java @@ -19,10 +19,15 @@ package de.steamwar.bausystem.features.backup; +import com.sk89q.worldedit.EditSession; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; import de.steamwar.bausystem.region.tags.Tag; +import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; @@ -85,7 +90,14 @@ public class BackupCommand extends SWCommand { BauSystem.MESSAGE.send("BACKUP_LOAD_FAILURE", p); return; } - region.reset(backupFile); + EditSession editSession = new PasteBuilder(new PasteBuilder.FileProvider(backupFile)) + .pastePoint(region.getMinPoint().add(region.getPrototype().getSizeX() / 2, 0, region.getPrototype().getSizeZ() / 2)) + .color(region.getPlain(Flag.COLOR, ColorMode.class).getColor()) + .minPoint(region.getMinPoint()) + .maxPoint(region.getMaxPoint()) + .waterLevel(region.getWaterLevel()) + .run(); + region.remember(editSession); BauSystem.MESSAGE.send("BACKUP_LOAD", p); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java index 06c63753..b625b70c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java @@ -27,6 +27,7 @@ import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; import de.steamwar.linkage.Linked; @@ -64,10 +65,13 @@ public class ColorCommand extends SWCommand { } region.set(Flag.COLOR, color); try { - region.reset(null, RegionType.NORMAL, RegionExtensionType.NORMAL, true, true,false,false); + PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL))) + .ignoreAir(true) + .onlyColors(); + region.reset(pasteBuilder, RegionType.NORMAL, RegionExtensionType.NORMAL); RegionUtils.message(region, "REGION_REGION_COLORED"); RegionUtils.message(region, "REGION_REGION_COLORED_FAILED"); - } catch (IOException e) { + } catch (SecurityException e) { BauSystem.MESSAGE.send("REGION_REGION_FAILED_COLORED", p); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java index 11100c81..cf8522c6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java @@ -27,6 +27,7 @@ import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; @@ -99,9 +100,11 @@ public class RegionCommand extends SWCommand { if(checkGlobalRegion(region, p)) return; try { - region.reset(null, RegionType.NORMAL, RegionExtensionType.NORMAL, true, false,false,false); + PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL))) + .ignoreAir(true); + region.reset(pasteBuilder, RegionType.NORMAL, RegionExtensionType.NORMAL); RegionUtils.message(region, "REGION_REGION_RESTORED"); - } catch (IOException e) { + } catch (SecurityException e) { BauSystem.MESSAGE.send("REGION_REGION_FAILED_RESTORE", p); Bukkit.getLogger().log(Level.WARNING, "Failed restore", e); } @@ -118,9 +121,11 @@ public class RegionCommand extends SWCommand { } try { - region.reset(node, RegionType.NORMAL, RegionExtensionType.NORMAL, true,false,false,false); + PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.SchematicProvider(node)) + .ignoreAir(true); + region.reset(pasteBuilder, RegionType.NORMAL, RegionExtensionType.NORMAL); RegionUtils.message(region, "REGION_REGION_RESTORED"); - } catch (IOException e) { + } catch (SecurityException e) { BauSystem.MESSAGE.send("REGION_REGION_FAILED_RESTORE", p); Bukkit.getLogger().log(Level.WARNING, "Failed restore", e); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java index a020ee33..64c7252d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java @@ -27,6 +27,7 @@ import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; import de.steamwar.linkage.Linked; @@ -55,9 +56,10 @@ public class ResetCommand extends SWCommand { Region region = regionCheck(p); if (region == null) return; try { - region.reset(null,RegionType.NORMAL, RegionExtensionType.NORMAL,false,false,false,false); + PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL))) + region.reset(pasteBuilder, RegionType.NORMAL, RegionExtensionType.NORMAL); RegionUtils.message(region, "REGION_RESET_RESETED"); - } catch (IOException e) { + } catch (SecurityException e) { BauSystem.MESSAGE.send("REGION_RESET_ERROR", p); Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e); } @@ -82,9 +84,10 @@ public class ResetCommand extends SWCommand { return; } try { - region.reset(node, RegionType.NORMAL,RegionExtensionType.NORMAL,false,false,false,false); + PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.SchematicProvider(node)); + region.reset(pasteBuilder, RegionType.NORMAL, RegionExtensionType.NORMAL); RegionUtils.message(region, "REGION_RESET_RESETED"); - } catch (IOException e) { + } catch (SecurityException e) { BauSystem.MESSAGE.send("REGION_RESET_ERROR", p); Bukkit.getLogger().log(Level.WARNING, "Failed reset", e); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index ba419662..132e7cac 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -24,8 +24,11 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; @@ -96,9 +99,16 @@ public class TestblockCommand extends SWCommand { } try { - region.reset(node, RegionType.TESTBLOCK, regionExtensionType, ignoreAir, onlyColors, removeTNT, removeWater); + PasteBuilder.ClipboardProvider clipboardProvider = node == null ? new PasteBuilder.FileProvider(region.getResetFile(RegionType.TESTBLOCK)) : new PasteBuilder.SchematicProvider(node); + PasteBuilder pasteBuilder = new PasteBuilder(clipboardProvider) + .ignoreAir(ignoreAir) + .onlyColors(onlyColors) + .removeTNT(removeTNT) + .removeWater(removeWater) + .color(region.getPlain(Flag.COLOR, ColorMode.class).getColor()); + region.reset(pasteBuilder, RegionType.TESTBLOCK, regionExtensionType); RegionUtils.message(region, "REGION_TB_DONE"); - } catch (IOException e) { + } catch (SecurityException e) { BauSystem.MESSAGE.send("REGION_TB_ERROR", p); Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 040a7f99..dd234713 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -22,19 +22,17 @@ package de.steamwar.bausystem.region; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitWorld; -import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.flags.Flag; -import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; import de.steamwar.bausystem.region.tags.Tag; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.shared.SizedStack; import de.steamwar.bausystem.utils.FlatteningWrapper; +import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.core.Core; -import de.steamwar.sql.SchematicData; -import de.steamwar.sql.SchematicNode; +import de.steamwar.sql.SchematicType; import lombok.AccessLevel; import lombok.Getter; import lombok.NonNull; @@ -45,7 +43,6 @@ import yapion.hierarchy.types.YAPIONType; import yapion.hierarchy.types.YAPIONValue; import java.io.File; -import java.io.IOException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; @@ -53,8 +50,6 @@ import java.util.function.ObjIntConsumer; import java.util.function.Predicate; import java.util.stream.Collectors; -import static de.steamwar.bausystem.region.RegionUtils.paste; - @Getter public class Region { @@ -413,13 +408,22 @@ public class Region { } } - public void reset(File file) { - EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, false, false, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel, false,false,false)); - initSessions(); - undoSessions.push(editSession); + public File getResetFile(RegionType regionType) { + if (!hasReset(regionType)) { + return null; + } + switch (regionType) { + case TESTBLOCK: + return prototype.getSkinMap().get(skin).getTestblockSchematicFile(); + case BUILD: + return prototype.getSkinMap().get(skin).getBuildSchematicFile(); + default: + case NORMAL: + return prototype.getSkinMap().get(skin).getSchematicFile(); + } } - public void reset(SchematicNode schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors,boolean removeTNT, boolean removeWater) throws IOException { + public void reset(PasteBuilder pasteBuilder, RegionType regionType, RegionExtensionType regionExtensionType) { if (!hasReset(regionType)) { return; } @@ -427,54 +431,50 @@ public class Region { regionExtensionType = RegionExtensionType.NORMAL; } - PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemtype().fightType() || schematic.getSchemtype().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), onlyColors, regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel, regionType == RegionType.TESTBLOCK,removeTNT,removeWater); + pasteBuilder.reset(regionExtensionType == RegionExtensionType.EXTENSION) + .minPoint(getMinPoint(regionType, regionExtensionType)) + .maxPoint(getMaxPoint(regionType, regionExtensionType)) + .waterLevel(waterLevel); + if (pasteBuilder.getClipboardProvider().is(PasteBuilder.SchematicProvider.class)) { + SchematicType schematicType = pasteBuilder.getClipboardProvider().as(PasteBuilder.SchematicProvider.class).getSchematic().getSchemtype(); + pasteBuilder.rotate(schematicType.fightType() || schematicType.check()); + } - Point pastePoint; - File tempFile = null; - Clipboard clipboard = null; switch (regionType) { case BUILD: - pastePoint = minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2); - if (schematic == null) { - tempFile = prototype.getSkinMap().get(skin).getBuildSchematicFile(); - } + pasteBuilder.pastePoint(minPointBuild.add(prototype.getBuild().getSizeX() / 2, 0, prototype.getBuild().getSizeZ() / 2)); break; case TESTBLOCK: - pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, 0); - if (schematic == null) { - tempFile = prototype.getSkinMap().get(skin).getTestblockSchematicFile(); + Point pastePoint = minPointTestblock.add(prototype.getTestblock().getSizeX() / 2, 0, 0); + if (!pasteBuilder.getClipboardProvider().is(PasteBuilder.SchematicProvider.class)) { pastePoint = pastePoint.add(0, 0, prototype.getTestblock().getSizeZ() / 2); } else { - clipboard = new SchematicData(schematic).load(); - int dz = Math.abs(clipboard.getOrigin().getZ() - clipboard.getMinimumPoint().getZ()); + int dz = Math.abs(pasteBuilder.getClipboard().getOrigin().getZ() - pasteBuilder.getClipboard().getMinimumPoint().getZ()); if (dz < 2 || dz > prototype.getTestblock().getSizeZ()) { pastePoint = pastePoint.add(0, 0, prototype.getTestblock().getSizeZ() / 2); - } else if (clipboard.getDimensions().getZ() != prototype.getTestblock().getSizeZ()) { - pastePoint = pastePoint.add(0, 0, clipboard.getDimensions().getZ() / 2 - (clipboard.getOrigin().getZ() - clipboard.getMinimumPoint().getZ()) - 1); + } else if (pasteBuilder.getClipboard().getDimensions().getZ() != prototype.getTestblock().getSizeZ()) { + pastePoint = pastePoint.add(0, 0, pasteBuilder.getClipboard().getDimensions().getZ() / 2 - (pasteBuilder.getClipboard().getOrigin().getZ() - pasteBuilder.getClipboard().getMinimumPoint().getZ()) - 1); } else { pastePoint = pastePoint.add(0, 0, prototype.getTestblock().getSizeZ() / 2); } - if (schematic.getSchemtype().getKuerzel().equalsIgnoreCase("wg")) { + SchematicType schematicType = pasteBuilder.getClipboardProvider().as(PasteBuilder.SchematicProvider.class).getSchematic().getSchemtype(); + if (schematicType.getKuerzel().equalsIgnoreCase("wg")) { pastePoint = pastePoint.add(0, 0, 1); } } + pasteBuilder.pastePoint(pastePoint); break; default: case NORMAL: - pastePoint = minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2); - if (schematic == null) { - tempFile = prototype.getSkinMap().get(skin).getSchematicFile(); - } + pasteBuilder.pastePoint(minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2)); break; } - EditSession editSession = null; - if (schematic != null) { - editSession = paste(clipboard != null ? clipboard : new SchematicData(schematic).load(), pastePoint, pasteOptions); - } else { - editSession = paste(tempFile, pastePoint, pasteOptions); - } + initSessions(); + undoSessions.push(pasteBuilder.run()); + } + public void remember(EditSession editSession) { initSessions(); undoSessions.push(editSession); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/RegionUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/region/RegionUtils.java index 3f81b60a..e30c3ed9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/RegionUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/RegionUtils.java @@ -81,14 +81,6 @@ public class RegionUtils { }); } - static EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) { - return FlatteningWrapper.impl.paste(file, pastePoint, pasteOptions); - } - - static EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) { - return FlatteningWrapper.impl.paste(clipboard, pastePoint, pasteOptions); - } - static void save(Region region) { if (region.getPrototype() != null) { region.regionData.add("prototype", region.getPrototype().getName()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java index b06cb221..3dddc008 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/PasteBuilder.java @@ -21,24 +21,29 @@ package de.steamwar.bausystem.utils; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.function.pattern.WaterloggedRemover; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockTypes; +import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.region.Point; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import lombok.Getter; +import lombok.NonNull; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.function.BiConsumer; import java.util.function.BiPredicate; @Getter public class PasteBuilder { - private final Clipboard clipboard; + private final ClipboardProvider clipboardProvider; private Point pastPoint; private boolean rotate; private boolean ignoreAir; @@ -49,20 +54,8 @@ public class PasteBuilder { private List> predicates = new ArrayList<>(); private List> mappers = new ArrayList<>(); - public PasteBuilder(SchematicNode schematic) { - try { - this.clipboard = new SchematicData(schematic).load(); - } catch (IOException e) { - throw new SecurityException(e); - } - } - - public PasteBuilder(Clipboard clipboard) { - this.clipboard = clipboard; - } - - public PasteBuilder(File file) { - this.clipboard = FlatteningWrapper.impl.loadSchematic(file); + public PasteBuilder(@NonNull ClipboardProvider clipboardProvider) { + this.clipboardProvider = clipboardProvider; } public PasteBuilder pastePoint(Point point) { @@ -70,18 +63,18 @@ public class PasteBuilder { return this; } - public PasteBuilder rotate() { - this.rotate = true; + public PasteBuilder rotate(boolean rotate) { + this.rotate = rotate; return this; } - public PasteBuilder ignoreAir() { - this.ignoreAir = true; + public PasteBuilder ignoreAir(boolean ignoreAir) { + this.ignoreAir = ignoreAir; return this; } - public PasteBuilder reset() { - this.reset = true; + public PasteBuilder reset(boolean reset) { + this.reset = reset; return this; } @@ -110,7 +103,160 @@ public class PasteBuilder { return this; } + public PasteBuilder color(Color color) { + if (color == Color.PINK) return this; + + BaseBlock WOOL = Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock(); + BaseBlock CLAY = Objects.requireNonNull(BlockTypes.PINK_TERRACOTTA).getDefaultState().toBaseBlock(); + BaseBlock GLAZED = Objects.requireNonNull(BlockTypes.PINK_GLAZED_TERRACOTTA).getDefaultState().toBaseBlock(); + BaseBlock GLASS = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS).getDefaultState().toBaseBlock(); + BaseBlock GLASS_PANE = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS_PANE).getDefaultState().toBaseBlock(); + BaseBlock CONCRETE = Objects.requireNonNull(BlockTypes.PINK_CONCRETE).getDefaultState().toBaseBlock(); + BaseBlock CONCRETE_POWDER = Objects.requireNonNull(BlockTypes.PINK_CONCRETE_POWDER).getDefaultState().toBaseBlock(); + BaseBlock CARPET = Objects.requireNonNull(BlockTypes.PINK_CARPET).getDefaultState().toBaseBlock(); + + BaseBlock wool = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_wool")).getDefaultState().toBaseBlock(); + BaseBlock clay = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_terracotta")).getDefaultState().toBaseBlock(); + BaseBlock glazed = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_glazed_terracotta")).getDefaultState().toBaseBlock(); + BaseBlock glass = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_stained_glass")).getDefaultState().toBaseBlock(); + BaseBlock glassPane = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_stained_glass_pane")).getDefaultState().toBaseBlock(); + BaseBlock carpet = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_carpet")).getDefaultState().toBaseBlock(); + BaseBlock concrete = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_concrete")).getDefaultState().toBaseBlock(); + BaseBlock concretePowder = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_concrete_powder")).getDefaultState().toBaseBlock(); + + return map((clipboard, blockVector3) -> { + BaseBlock block = clipboard.getFullBlock(blockVector3); + if (block.equals(WOOL)) { + clipboard.setBlock(blockVector3, wool); + } else if (block.equals(CLAY)) { + clipboard.setBlock(blockVector3, clay); + } else if (block.equals(GLAZED)) { + clipboard.setBlock(blockVector3, glazed); + } else if (block.equals(GLASS)) { + clipboard.setBlock(blockVector3, glass); + } else if (block.equals(GLASS_PANE)) { + clipboard.setBlock(blockVector3, glassPane); + } else if (block.equals(CARPET)) { + clipboard.setBlock(blockVector3, carpet); + } else if (block.equals(CONCRETE)) { + clipboard.setBlock(blockVector3, concrete); + } else if (block.equals(CONCRETE_POWDER)) { + clipboard.setBlock(blockVector3, concretePowder); + } + }); + } + + public PasteBuilder onlyColors(boolean onlyColors) { + if (!onlyColors) return this; + return only((baseBlock, s) -> { + return s.endsWith("_wool") || s.endsWith("_terracotta") || s.endsWith("_glazed_terracotta") || s.endsWith("_stained_glass") || s.endsWith("_stained_glass_pane") || s.endsWith("_carpet") || s.endsWith("_concrete") || s.endsWith("_concrete_powder"); + }); + } + + public PasteBuilder removeTNT(boolean removeTNT) { + if (!removeTNT) return this; + BaseBlock tnt = Objects.requireNonNull(BlockTypes.get("tnt")).getDefaultState().toBaseBlock(); + BaseBlock air = Objects.requireNonNull(BlockTypes.get("air")).getDefaultState().toBaseBlock(); + + return map((clipboard, blockVector3) -> { + BaseBlock baseBlock = clipboard.getFullBlock(blockVector3); + if (baseBlock.equals(tnt)) { + clipboard.setBlock(blockVector3, air); + } + }); + } + + public PasteBuilder removeWater(boolean removeWater) { + if (!removeWater) return this; + BaseBlock water = Objects.requireNonNull(BlockTypes.get("water")).getDefaultState().toBaseBlock(); + BaseBlock air = Objects.requireNonNull(BlockTypes.get("air")).getDefaultState().toBaseBlock(); + WaterloggedRemover waterloggedRemover = new WaterloggedRemover(getClipboard()); + + return map((clipboard, blockVector3) -> { + BaseBlock baseBlock = clipboard.getFullBlock(blockVector3); + if (baseBlock.equals(water)) { + clipboard.setBlock(blockVector3, air); + return; + } + String blockName = clipboard.getFullBlock(blockVector3).getBlockType().getName(); + if (blockName.equals("Water")) { + clipboard.setBlock(blockVector3, air); + return; + } + clipboard.setBlock(blockVector3, waterloggedRemover.applyBlock(blockVector3)); + }); + } + + public Clipboard getClipboard() { + return clipboardProvider.getClipboard(); + } + public EditSession run() { + if (pastPoint == null) { + throw new IllegalStateException("pastePoint is null"); + } return FlatteningWrapper.impl.paste(this); } + + public interface ClipboardProvider { + Clipboard getClipboard(); + + default boolean is(Class clazz) { + return clazz.isInstance(this); + } + + default T as(Class clazz) { + return clazz.cast(this); + } + } + + @Getter + public static class FileProvider implements ClipboardProvider { + private final File file; + private final Clipboard clipboard; + + public FileProvider(File file) { + this.file = file; + this.clipboard = FlatteningWrapper.impl.loadSchematic(file); + } + + @Override + public Clipboard getClipboard() { + return clipboard; + } + } + + @Getter + public static class SchematicProvider implements ClipboardProvider { + private final SchematicNode schematic; + private final Clipboard clipboard; + + public SchematicProvider(SchematicNode schematic) { + this.schematic = schematic; + try { + this.clipboard = new SchematicData(schematic).load(); + } catch (IOException e) { + throw new SecurityException(e); + } + } + + @Override + public Clipboard getClipboard() { + return clipboard; + } + } + + @Getter + public static class ClipboardProviderImpl implements ClipboardProvider { + private final Clipboard clipboard; + + public ClipboardProviderImpl(Clipboard clipboard) { + this.clipboard = clipboard; + } + + @Override + public Clipboard getClipboard() { + return clipboard; + } + } } -- 2.39.2 From fc03ba67e5a5e641f794f67f800e8c7ee6446741 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 30 Jul 2023 21:04:07 +0200 Subject: [PATCH 19/22] Hotfix ResetCommand Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/region/ResetCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java index 64c7252d..bcb46110 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java @@ -56,7 +56,7 @@ public class ResetCommand extends SWCommand { Region region = regionCheck(p); if (region == null) return; try { - PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL))) + PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL))); region.reset(pasteBuilder, RegionType.NORMAL, RegionExtensionType.NORMAL); RegionUtils.message(region, "REGION_RESET_RESETED"); } catch (SecurityException e) { -- 2.39.2 From 7f3c0d2fd0b28a3013fbb198fb9290dbf64ecddd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 30 Jul 2023 21:14:12 +0200 Subject: [PATCH 20/22] Fix stuff Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/region/ColorCommand.java | 2 +- .../bausystem/features/region/items/TestblockBauGuiItem.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java index b625b70c..bf7aa7c0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java @@ -67,7 +67,7 @@ public class ColorCommand extends SWCommand { try { PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL))) .ignoreAir(true) - .onlyColors(); + .onlyColors(true); region.reset(pasteBuilder, RegionType.NORMAL, RegionExtensionType.NORMAL); RegionUtils.message(region, "REGION_REGION_COLORED"); RegionUtils.message(region, "REGION_REGION_COLORED_FAILED"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockBauGuiItem.java index 07ede055..7b0f25e0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockBauGuiItem.java @@ -51,7 +51,7 @@ public class TestblockBauGuiItem extends BauGuiItem { public boolean click(ClickType click, Player p) { if (click == ClickType.LEFT) { p.closeInventory(); - testblockCommand.schematicTestblockCommand(p,null); + testblockCommand.schematicTestblockCommand(p); } else { SchematicSelector selector = new SchematicSelector(p, SchematicSelector.selectSchematic(), node -> { p.closeInventory(); -- 2.39.2 From ca907a74785835677654b542e1c3ed177758fde6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 16 Aug 2023 21:19:12 +0200 Subject: [PATCH 21/22] Remove unused api and cleanup rest Signed-off-by: yoyosource --- .../bausystem/utils/FlatteningWrapper15.java | 194 ------------------ .../bausystem/region/PasteOptions.java | 54 ----- .../bausystem/utils/FlatteningWrapper.java | 9 - 3 files changed, 257 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index 4b28c421..df3f0cc1 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -34,18 +34,14 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operations; -import com.sk89q.worldedit.function.pattern.WaterloggedRemover; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.regions.CuboidRegion; -import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; -import de.steamwar.bausystem.region.Color; -import de.steamwar.bausystem.region.PasteOptions; import de.steamwar.bausystem.region.Point; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -186,181 +182,6 @@ public class FlatteningWrapper15 implements FlatteningWrapper { } } - private static final BaseBlock WOOL = Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock(); - private static final BaseBlock CLAY = Objects.requireNonNull(BlockTypes.PINK_TERRACOTTA).getDefaultState().toBaseBlock(); - private static final BaseBlock GLAZED = Objects.requireNonNull(BlockTypes.PINK_GLAZED_TERRACOTTA).getDefaultState().toBaseBlock(); - private static final BaseBlock GLASS = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS).getDefaultState().toBaseBlock(); - private static final BaseBlock GLASS_PANE = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS_PANE).getDefaultState().toBaseBlock(); - private static final BaseBlock CONCRETE = Objects.requireNonNull(BlockTypes.PINK_CONCRETE).getDefaultState().toBaseBlock(); - private static final BaseBlock CONCRETE_POWDER = Objects.requireNonNull(BlockTypes.PINK_CONCRETE_POWDER).getDefaultState().toBaseBlock(); - private static final BaseBlock CARPET = Objects.requireNonNull(BlockTypes.PINK_CARPET).getDefaultState().toBaseBlock(); - - @Override - public EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) { - Clipboard clipboard; - try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) { - clipboard = reader.read(); - } catch (NullPointerException | IOException e) { - throw new SecurityException("Bausystem schematic not found", e); - } - - EditSession editSession = paste(clipboard, pastePoint, pasteOptions); - return editSession; - } - - @Override - public EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) { - try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { - if (pasteOptions.getColor() != Color.PINK) { - changeColor(clipboard, pasteOptions.getColor()); - } - if (pasteOptions.isTestBlock() && pasteOptions.isRemoveTNT()) { - removeTNT(clipboard); - } - if (pasteOptions.isTestBlock() && pasteOptions.isRemoveWater()) { - removeWater(clipboard); - } - - Set blocks = new HashSet<>(); - { - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_wool"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_terracotta"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_glazed_terracotta"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_stained_glass_pane"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_concrete_powder"); - blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_carpet"); - } - - e.setMask(new Mask() { - @Override - public boolean test(BlockVector3 blockVector3) { - BaseBlock block = clipboard.getFullBlock(blockVector3); - String blockName = block.toString().toLowerCase(); - - if (pasteOptions.isOnlyColors()) return blocks.contains(blockName); - return true; - } - - @Nullable - @Override - public Mask2D toMask2D() { - return null; - } - public Mask copy() { - return this; - } - }); - - ClipboardHolder ch = new ClipboardHolder(clipboard); - BlockVector3 dimensions = clipboard.getDimensions(); - BlockVector3 v = BlockVector3.at(pastePoint.getX(), pastePoint.getY(), pastePoint.getZ()); - BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); - if (pasteOptions.isRotate()) { - ch.setTransform(new AffineTransform().rotateY(180)); - v = v.add(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset.multiply(-1, 1, -1)).subtract(0, 0, 1); - } else { - v = v.subtract(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset); - } - - if (pasteOptions.isReset()) { - e.setBlocks(new CuboidRegion(toBlockVector3(pasteOptions.getMinPoint()), toBlockVector3(pasteOptions.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock()); - if (pasteOptions.getWaterLevel() != 0) { - e.setBlocks((Region) new CuboidRegion(toBlockVector3(pasteOptions.getMinPoint()), toBlockVector3(pasteOptions.getMaxPoint()).withY(pasteOptions.getWaterLevel())), Objects.requireNonNull(BlockTypes.WATER).getDefaultState().toBaseBlock()); - } - } - Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(pasteOptions.isIgnoreAir()).build()); - return e; - } catch (WorldEditException e) { - throw new SecurityException(e.getMessage(), e); - } - } - - public void changeColor(Clipboard clipboard, Color color) throws WorldEditException { - BlockVector3 minimum = clipboard.getRegion().getMinimumPoint(); - BaseBlock wool = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_wool")).getDefaultState().toBaseBlock(); - BaseBlock clay = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_terracotta")).getDefaultState().toBaseBlock(); - BaseBlock glazed = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_glazed_terracotta")).getDefaultState().toBaseBlock(); - BaseBlock glass = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_stained_glass")).getDefaultState().toBaseBlock(); - BaseBlock glassPane = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_stained_glass_pane")).getDefaultState().toBaseBlock(); - BaseBlock carpet = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_carpet")).getDefaultState().toBaseBlock(); - BaseBlock concrete = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_concrete")).getDefaultState().toBaseBlock(); - BaseBlock concretePowder = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_concrete_powder")).getDefaultState().toBaseBlock(); - - for (int x = 0; x < clipboard.getDimensions().getX(); x++) { - for (int y = 0; y < clipboard.getDimensions().getY(); y++) { - for (int z = 0; z < clipboard.getDimensions().getZ(); z++) { - BlockVector3 pos = minimum.add(x, y, z); - BaseBlock block = clipboard.getFullBlock(pos); - if (block.equals(WOOL)) { - clipboard.setBlock(pos, wool); - } else if (block.equals(CLAY)) { - clipboard.setBlock(pos, clay); - } else if (block.equals(GLAZED)) { - clipboard.setBlock(pos, glazed); - } else if (block.equals(GLASS)) { - clipboard.setBlock(pos, glass); - } else if (block.equals(GLASS_PANE)) { - clipboard.setBlock(pos, glassPane); - } else if (block.equals(CARPET)) { - clipboard.setBlock(pos, carpet); - } else if (block.equals(CONCRETE)) { - clipboard.setBlock(pos, concrete); - } else if (block.equals(CONCRETE_POWDER)) { - clipboard.setBlock(pos, concretePowder); - } - } - } - } - } - - public void removeTNT(Clipboard clipboard) throws WorldEditException { - BlockVector3 minimum = clipboard.getRegion().getMinimumPoint(); - BaseBlock tnt = Objects.requireNonNull(BlockTypes.get("tnt")).getDefaultState().toBaseBlock(); - BaseBlock air = Objects.requireNonNull(BlockTypes.get("air")).getDefaultState().toBaseBlock(); - - for (int x = 0; x < clipboard.getDimensions().getX(); x++) { - for (int y = 0; y < clipboard.getDimensions().getY(); y++) { - for (int z = 0; z < clipboard.getDimensions().getZ(); z++) { - BlockVector3 pos = minimum.add(x, y, z); - BaseBlock block = clipboard.getFullBlock(pos); - - if (block.equals(tnt)) { - clipboard.setBlock(pos, air); - } - } - } - } - } - - public void removeWater(Clipboard clipboard) throws WorldEditException { - BlockVector3 minimum = clipboard.getRegion().getMinimumPoint(); - BaseBlock water = Objects.requireNonNull(BlockTypes.get("water")).getDefaultState().toBaseBlock(); - BaseBlock air = Objects.requireNonNull(BlockTypes.get("air")).getDefaultState().toBaseBlock(); - WaterloggedRemover waterloggedRemover = new WaterloggedRemover(clipboard); - - for (int x = 0; x < clipboard.getDimensions().getX(); x++) { - for (int y = 0; y < clipboard.getDimensions().getY(); y++) { - for (int z = 0; z < clipboard.getDimensions().getZ(); z++) { - BlockVector3 pos = minimum.add(x, y, z); - BaseBlock block = clipboard.getFullBlock(pos); - - if (block.equals(water)) { - clipboard.setBlock(pos, air); - } else { - String blockName = block.getBlockType().getName(); - if (blockName.equals("Water")) { - clipboard.setBlock(pos, air); - } else if (blockName.contains("waterlogged=true")) { - clipboard.setBlock(pos, waterloggedRemover.applyBlock(pos)); - } - } - } - } - } - } - @Override public boolean backup(Point minPoint, Point maxPoint, File file) { BukkitWorld bukkitWorld = new BukkitWorld(Bukkit.getWorlds().get(0)); @@ -402,19 +223,4 @@ public class FlatteningWrapper15 implements FlatteningWrapper { return ((Waterlogged) data).isWaterlogged(); } - - @Override - public Material getTraceShowMaterial() { - return Material.LIME_CONCRETE; - } - - @Override - public Material getTraceHideMaterial() { - return Material.RED_CONCRETE; - } - - @Override - public Material getTraceXZMaterial() { - return Material.QUARTZ_SLAB; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java b/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java deleted file mode 100644 index 5be73fe6..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/PasteOptions.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 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.region; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.ToString; - -@Getter -@Builder -@AllArgsConstructor -@ToString -public class PasteOptions { - - private final boolean rotate; - - private final boolean ignoreAir; - - private final Color color; - - private final boolean onlyColors; - - private final boolean reset; - - private final Point minPoint; - - private final Point maxPoint; - - private final int waterLevel; - - private final boolean testBlock; - - private final boolean removeTNT; - - private final boolean removeWater; -} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java index e80c4027..aef0b302 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/FlatteningWrapper.java @@ -20,11 +20,8 @@ package de.steamwar.bausystem.utils; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.region.Color; -import de.steamwar.bausystem.region.PasteOptions; import de.steamwar.bausystem.region.Point; import de.steamwar.core.VersionDependent; import org.bukkit.Material; @@ -49,13 +46,7 @@ public interface FlatteningWrapper { Clipboard loadSchematic(File file); EditSession paste(PasteBuilder pasteBuilder); - EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions); - EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions); boolean backup(Point minPoint, Point maxPoint, File file); boolean inWater(World world, Vector tntPosition); - - Material getTraceShowMaterial(); - Material getTraceHideMaterial(); - Material getTraceXZMaterial(); } -- 2.39.2 From ed862ba6b2e91dcbb5eaacb845fa397526b5a1f9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 19 Aug 2023 23:25:52 +0200 Subject: [PATCH 22/22] Fix paste problems Signed-off-by: yoyosource --- .../steamwar/bausystem/utils/FlatteningWrapper15.java | 11 +++++++++-- .../bausystem/features/region/ColorCommand.java | 3 ++- .../bausystem/features/region/RegionCommand.java | 8 ++++++-- .../bausystem/features/region/ResetCommand.java | 8 ++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index df3f0cc1..0a01fb42 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -61,6 +61,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Objects; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiPredicate; import java.util.logging.Level; @@ -138,18 +139,23 @@ public class FlatteningWrapper15 implements FlatteningWrapper { } } + AtomicReference pastePoint = new AtomicReference<>(); if (!pasteBuilder.getPredicates().isEmpty()) { e.setMask(new Mask() { @Override public boolean test(BlockVector3 blockVector3) { - BaseBlock block = clipboard.getFullBlock(blockVector3); - String blockName = block.toString().toLowerCase(); + BaseBlock block = clipboard.getFullBlock(blockVector3.subtract(pastePoint.get()).add(clipboard.getRegion().getMinimumPoint())); + String blockName = block.getBlockType().toString().toLowerCase(); for (BiPredicate predicate : pasteBuilder.getPredicates()) { if (!predicate.test(block, blockName)) return false; } return true; } + public Mask copy() { + return this; + } + @Nullable @Override public Mask2D toMask2D() { @@ -168,6 +174,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper { } else { v = v.subtract(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset); } + pastePoint.set(v); if (pasteBuilder.isReset()) { e.setBlocks(new CuboidRegion(toBlockVector3(pasteBuilder.getMinPoint()), toBlockVector3(pasteBuilder.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java index bf7aa7c0..543d8727 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java @@ -67,7 +67,8 @@ public class ColorCommand extends SWCommand { try { PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL))) .ignoreAir(true) - .onlyColors(true); + .onlyColors(true) + .color(color.getColor()); region.reset(pasteBuilder, RegionType.NORMAL, RegionExtensionType.NORMAL); RegionUtils.message(region, "REGION_REGION_COLORED"); RegionUtils.message(region, "REGION_REGION_COLORED_FAILED"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java index cf8522c6..5caf0af3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java @@ -25,6 +25,8 @@ import de.steamwar.bausystem.features.util.SelectCommand; import de.steamwar.bausystem.region.Prototype; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.utils.PasteBuilder; @@ -101,7 +103,8 @@ public class RegionCommand extends SWCommand { try { PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL))) - .ignoreAir(true); + .ignoreAir(true) + .color(region.getPlain(Flag.COLOR, ColorMode.class).getColor()); region.reset(pasteBuilder, RegionType.NORMAL, RegionExtensionType.NORMAL); RegionUtils.message(region, "REGION_REGION_RESTORED"); } catch (SecurityException e) { @@ -122,7 +125,8 @@ public class RegionCommand extends SWCommand { try { PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.SchematicProvider(node)) - .ignoreAir(true); + .ignoreAir(true) + .color(region.getPlain(Flag.COLOR, ColorMode.class).getColor()); region.reset(pasteBuilder, RegionType.NORMAL, RegionExtensionType.NORMAL); RegionUtils.message(region, "REGION_REGION_RESTORED"); } catch (SecurityException e) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java index bcb46110..03a22027 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java @@ -25,6 +25,8 @@ import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.utils.PasteBuilder; @@ -56,7 +58,8 @@ public class ResetCommand extends SWCommand { Region region = regionCheck(p); if (region == null) return; try { - PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL))); + PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getResetFile(RegionType.NORMAL))) + .color(region.getPlain(Flag.COLOR, ColorMode.class).getColor()); region.reset(pasteBuilder, RegionType.NORMAL, RegionExtensionType.NORMAL); RegionUtils.message(region, "REGION_RESET_RESETED"); } catch (SecurityException e) { @@ -84,7 +87,8 @@ public class ResetCommand extends SWCommand { return; } try { - PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.SchematicProvider(node)); + PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.SchematicProvider(node)) + .color(region.getPlain(Flag.COLOR, ColorMode.class).getColor()); region.reset(pasteBuilder, RegionType.NORMAL, RegionExtensionType.NORMAL); RegionUtils.message(region, "REGION_RESET_RESETED"); } catch (SecurityException e) { -- 2.39.2