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