TestBlockPaste-Without-Water #146
@ -34,18 +34,14 @@ import com.sk89q.worldedit.function.mask.Mask;
|
|||||||
import com.sk89q.worldedit.function.mask.Mask2D;
|
import com.sk89q.worldedit.function.mask.Mask2D;
|
||||||
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
||||||
import com.sk89q.worldedit.function.operation.Operations;
|
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.BlockVector3;
|
||||||
import com.sk89q.worldedit.math.transform.AffineTransform;
|
import com.sk89q.worldedit.math.transform.AffineTransform;
|
||||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
|
||||||
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
||||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
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 de.steamwar.bausystem.region.Point;
|
||||||
zOnlyKroks markierte diese Unterhaltung als gelöst
Veraltet
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
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
|
@Override
|
||||||
public boolean backup(Point minPoint, Point maxPoint, File file) {
|
public boolean backup(Point minPoint, Point maxPoint, File file) {
|
||||||
BukkitWorld bukkitWorld = new BukkitWorld(Bukkit.getWorlds().get(0));
|
BukkitWorld bukkitWorld = new BukkitWorld(Bukkit.getWorlds().get(0));
|
||||||
@ -402,19 +223,4 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
|
|||||||
|
|
||||||
return ((Waterlogged) data).isWaterlogged();
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
@ -20,11 +20,8 @@
|
|||||||
package de.steamwar.bausystem.utils;
|
package de.steamwar.bausystem.utils;
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
|
||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
import de.steamwar.bausystem.BauSystem;
|
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.bausystem.region.Point;
|
||||||
import de.steamwar.core.VersionDependent;
|
import de.steamwar.core.VersionDependent;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -49,13 +46,7 @@ public interface FlatteningWrapper {
|
|||||||
Clipboard loadSchematic(File file);
|
Clipboard loadSchematic(File file);
|
||||||
EditSession paste(PasteBuilder pasteBuilder);
|
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 backup(Point minPoint, Point maxPoint, File file);
|
||||||
|
|
||||||
boolean inWater(World world, Vector tntPosition);
|
boolean inWater(World world, Vector tntPosition);
|
||||||
|
|
||||||
Material getTraceShowMaterial();
|
|
||||||
Material getTraceHideMaterial();
|
|
||||||
Material getTraceXZMaterial();
|
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Scheint mir nicht genutzt zu sein.