SteamWar/BauSystem2.0
Archiviert
12
0

Update PasteBuilder and usages
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-07-30 21:02:33 +02:00
Ursprung c398ad239d
Commit 3e27a0b366
9 geänderte Dateien mit 277 neuen und 102 gelöschten Zeilen

Datei anzeigen

@ -130,6 +130,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
Clipboard clipboard = pasteBuilder.getClipboard();
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++) {
@ -139,11 +140,12 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
}
}
}
}
if (!pasteBuilder.getPredicates().isEmpty()) {
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<BaseBlock, String> predicate : pasteBuilder.getPredicates()) {
@ -158,6 +160,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
return null;
}
});
}
ClipboardHolder ch = new ClipboardHolder(clipboard);
BlockVector3 dimensions = clipboard.getDimensions();

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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());

Datei anzeigen

@ -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<BiPredicate<BaseBlock, String>> predicates = new ArrayList<>();
private List<BiConsumer<Clipboard, BlockVector3>> 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 <T extends ClipboardProvider> boolean is(Class<T> clazz) {
return clazz.isInstance(this);
}
default <T extends ClipboardProvider> T as(Class<T> 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;
}
}
}