From 2c42dfafe90bc23214df18c25fc1fb685f049f0f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 1 Aug 2021 22:01:25 +0200 Subject: [PATCH] Optimize Region_15 Signed-off-by: yoyosource --- .../bausystem/region/RegionUtils_15.java | 100 ------------------ .../steamwar/bausystem/region/Region_15.java | 21 ++++ .../bausystem/region/PasteOptions.java | 5 + .../features/region/RegionCommand.java | 2 +- .../de/steamwar/bausystem/region/Region.java | 8 +- 5 files changed, 33 insertions(+), 103 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/region/RegionUtils_15.java b/BauSystem_15/src/de/steamwar/bausystem/region/RegionUtils_15.java index 45c770bd..037727d7 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/region/RegionUtils_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/region/RegionUtils_15.java @@ -20,8 +20,6 @@ package de.steamwar.bausystem.region; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BlockType; -import com.sk89q.worldedit.world.block.BlockTypes; import lombok.experimental.UtilityClass; @UtilityClass @@ -30,102 +28,4 @@ public class RegionUtils_15 { public BlockVector3 toBlockVector3(Point point) { return BlockVector3.at(point.getX(), point.getY(), point.getZ()); } - - public BlockType mapColor(BlockType original, Color color) { - switch (color) { - case WHITE: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.WHITE_CONCRETE; - } else { - return BlockTypes.WHITE_STAINED_GLASS; - } - case ORANGE: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.ORANGE_CONCRETE; - } else { - return BlockTypes.ORANGE_STAINED_GLASS; - } - case MAGENTA: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.MAGENTA_CONCRETE; - } else { - return BlockTypes.MAGENTA_STAINED_GLASS; - } - case LIGHT_BLUE: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.LIGHT_BLUE_CONCRETE; - } else { - return BlockTypes.LIGHT_BLUE_STAINED_GLASS; - } - case LIME: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.LIME_CONCRETE; - } else { - return BlockTypes.LIME_STAINED_GLASS; - } - case PINK: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.PINK_CONCRETE; - } else { - return BlockTypes.PINK_STAINED_GLASS; - } - case GRAY: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.GRAY_CONCRETE; - } else { - return BlockTypes.GRAY_STAINED_GLASS; - } - case LIGHT_GRAY: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.LIGHT_GRAY_CONCRETE; - } else { - return BlockTypes.LIGHT_GRAY_STAINED_GLASS; - } - case CYAN: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.CYAN_CONCRETE; - } else { - return BlockTypes.CYAN_STAINED_GLASS; - } - case PURPLE: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.PURPLE_CONCRETE; - } else { - return BlockTypes.PURPLE_STAINED_GLASS; - } - case BLUE: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.BLUE_CONCRETE; - } else { - return BlockTypes.BLUE_STAINED_GLASS; - } - case BROWN: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.BROWN_CONCRETE; - } else { - return BlockTypes.BROWN_STAINED_GLASS; - } - case GREEN: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.GREEN_CONCRETE; - } else { - return BlockTypes.GREEN_STAINED_GLASS; - } - case RED: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.RED_CONCRETE; - } else { - return BlockTypes.RED_STAINED_GLASS; - } - case BLACK: - if (original == BlockTypes.YELLOW_CONCRETE) { - return BlockTypes.BLACK_CONCRETE; - } else { - return BlockTypes.BLACK_STAINED_GLASS; - } - case YELLOW: - default: - return original; - } - } } \ No newline at end of file diff --git a/BauSystem_15/src/de/steamwar/bausystem/region/Region_15.java b/BauSystem_15/src/de/steamwar/bausystem/region/Region_15.java index 968bc53d..805aa5e9 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/region/Region_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/region/Region_15.java @@ -29,6 +29,10 @@ import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; +import com.sk89q.worldedit.function.mask.AbstractExtentMask; +import com.sk89q.worldedit.function.mask.BlockMask; +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.math.BlockVector3; @@ -36,10 +40,12 @@ import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; +import javax.annotation.Nullable; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -94,6 +100,21 @@ public class Region_15 { if (pasteOptions.getColor() != Color.YELLOW) { changeColor(clipboard, pasteOptions.getColor()); } + if (pasteOptions.isOnlyColors()) { + e.setMask(new AbstractExtentMask(clipboard) { + @Override + public boolean test(BlockVector3 blockVector3) { + BaseBlock block = getExtent().getFullBlock(blockVector3); + return !(block.equals(WOOL) || block.equals(CLAY) || block.equals(GLASS) || block.equals(GLASS2) || block.equals(GLASS_PANE) || block.equals(CARPET) || block.equals(CONCRETE) || block.equals(CONCRETE2) || block.equals(CONCRETE_POWDER)); + } + + @Nullable + @Override + public Mask2D toMask2D() { + return null; + } + }); + } System.out.println("ChangeColor: " + stop("changeColor")); start("transform"); diff --git a/BauSystem_API/src/de/steamwar/bausystem/region/PasteOptions.java b/BauSystem_API/src/de/steamwar/bausystem/region/PasteOptions.java index 479b9fec..e28a02d8 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/region/PasteOptions.java +++ b/BauSystem_API/src/de/steamwar/bausystem/region/PasteOptions.java @@ -43,6 +43,11 @@ public class PasteOptions { */ private final Color color; + /** + * Used in 1.15 + */ + private final boolean onlyColors; + /** * Used in 1.15 */ 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 7a9ffb26..caa76bda 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java @@ -131,7 +131,7 @@ public class RegionCommand extends SWCommand { if(checkGlobalRegion(region, p)) return; try { - region.reset(null, RegionType.NORMAL, RegionExtensionType.NORMAL, true); + region.reset(null, RegionType.NORMAL, RegionExtensionType.NORMAL, true, true); 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/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index e8086e41..cce07ac3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -371,12 +371,16 @@ 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, 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)); initSessions(); undoSessions.push(editSession); } public void reset(Schematic schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir) throws IOException { + reset(schematic, regionType, regionExtensionType, ignoreAir, false); + } + + public void reset(Schematic schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir, boolean onlyColors) throws IOException { if (!hasReset(regionType)) { return; } @@ -384,7 +388,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(), 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); Point pastePoint; File tempFile = null;