2021-04-18 18:47:43 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of the SteamWar software.
|
|
|
|
*
|
2022-01-29 15:28:28 +01:00
|
|
|
* Copyright (C) 2022 SteamWar.de-Serverteam
|
2021-04-18 18:47:43 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2022-01-29 15:28:28 +01:00
|
|
|
package de.steamwar.bausystem.utils;
|
2021-04-18 18:47:43 +02:00
|
|
|
|
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
|
|
|
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
2022-01-29 15:28:28 +01:00
|
|
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
2021-07-05 19:32:10 +02:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
2021-04-18 18:47:43 +02:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
2021-07-05 19:32:10 +02:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
|
2021-04-18 18:47:43 +02:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
|
2021-07-05 19:32:10 +02:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
|
2022-05-18 17:33:25 +02:00
|
|
|
import com.sk89q.worldedit.function.mask.Mask;
|
2021-08-01 22:01:25 +02:00
|
|
|
import com.sk89q.worldedit.function.mask.Mask2D;
|
2021-07-05 19:32:10 +02:00
|
|
|
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
2021-04-18 18:47:43 +02:00
|
|
|
import com.sk89q.worldedit.function.operation.Operations;
|
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
|
|
|
import com.sk89q.worldedit.math.transform.AffineTransform;
|
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
2022-05-18 17:33:25 +02:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
2022-01-29 15:28:28 +01:00
|
|
|
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
|
2021-04-18 18:47:43 +02:00
|
|
|
import com.sk89q.worldedit.session.ClipboardHolder;
|
2022-01-29 15:28:28 +01:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2021-04-18 18:47:43 +02:00
|
|
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
|
|
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
2022-01-29 15:28:28 +01:00
|
|
|
import de.steamwar.bausystem.region.Color;
|
|
|
|
import de.steamwar.bausystem.region.PasteOptions;
|
|
|
|
import de.steamwar.bausystem.region.Point;
|
2021-07-30 23:00:32 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2022-01-29 15:28:28 +01:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.data.BlockData;
|
|
|
|
import org.bukkit.block.data.Waterlogged;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.util.Vector;
|
2021-07-30 23:00:32 +02:00
|
|
|
|
2021-08-01 22:01:25 +02:00
|
|
|
import javax.annotation.Nullable;
|
2021-04-18 18:47:43 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
2021-07-05 19:32:10 +02:00
|
|
|
import java.io.FileOutputStream;
|
2021-04-18 18:47:43 +02:00
|
|
|
import java.io.IOException;
|
2021-08-03 13:53:50 +02:00
|
|
|
import java.util.*;
|
2021-07-05 19:32:10 +02:00
|
|
|
import java.util.logging.Level;
|
2021-04-18 18:47:43 +02:00
|
|
|
|
2022-01-29 15:28:28 +01:00
|
|
|
public class FlatteningWrapper15 implements FlatteningWrapper.IFlatteningWrapper {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isNoBook(ItemStack item) {
|
|
|
|
return item.getType() != Material.WRITABLE_BOOK && item.getType() != Material.WRITTEN_BOOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Set<Material> unpushable = new HashSet<>(Arrays.asList(Material.BARRIER, Material.BEACON, Material.COMMAND_BLOCK, Material.CHAIN_COMMAND_BLOCK, Material.REPEATING_COMMAND_BLOCK, Material.ENCHANTING_TABLE, Material.END_GATEWAY, Material.END_PORTAL, Material.ENDER_CHEST, Material.GRINDSTONE, Material.JIGSAW, Material.JUKEBOX, Material.NETHER_PORTAL, Material.OBSIDIAN, Material.STRUCTURE_VOID, Material.BARREL, Material.BEEHIVE, Material.BEE_NEST, Material.BLAST_FURNACE, Material.BREWING_STAND, Material.CHEST, Material.DAYLIGHT_DETECTOR, Material.DISPENSER, Material.DROPPER, Material.FURNACE, Material.HOPPER, Material.LECTERN, Material.SMOKER, Material.TRAPPED_CHEST));
|
|
|
|
|
|
|
|
// TODO: FLOWER
|
|
|
|
private static final Set<Material> breaking = new HashSet<>(Arrays.asList(Material.BAMBOO, Material.CACTUS, Material.CAKE, Material.CARVED_PUMPKIN, Material.CHORUS_FLOWER, Material.CHORUS_PLANT, Material.COBWEB, Material.COCOA, Material.DRAGON_EGG, Material.FIRE, Material.FLOWER_POT, Material.JACK_O_LANTERN, Material.LADDER, Material.LAVA, Material.LAVA, Material.LEVER, Material.LILY_PAD, Material.MELON, Material.NETHER_WART, Material.PUMPKIN, Material.COMPARATOR, Material.REDSTONE_WIRE, Material.REPEATER, Material.TORCH, Material.STRUCTURE_VOID, Material.SCAFFOLDING, Material.SEA_PICKLE, Material.SNOW, Material.SUGAR_CANE, Material.TORCH, Material.TRIPWIRE, Material.TRIPWIRE_HOOK, Material.TURTLE_EGG, Material.VINE, Material.WATER, Material.WHEAT));
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isUnpusheable(Material material) {
|
|
|
|
if (unpushable.contains(material)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
String name = material.name();
|
|
|
|
return name.contains("BANNER") || name.contains("SIGN");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isBreakingOnPush(Material material) {
|
|
|
|
if (breaking.contains(material)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
String name = material.name();
|
|
|
|
return name.contains("BED") || name.contains("BUTTON") || name.contains("CARPET") || (name.contains("DOOR") && !name.contains("TRAPDOOR")) || name.contains("HEAD") || name.contains("LEAVES") || name.contains("MUSHROOM") || name.contains("PRESSURE_PLATE") || name.contains("SHULKER_BOX");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isWorldEditCommand(String command) {
|
|
|
|
if (command.startsWith("/")) {
|
|
|
|
command = command.replaceFirst("/", "");
|
|
|
|
}
|
|
|
|
command = command.toLowerCase();
|
|
|
|
return WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().containsCommand(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final WorldEditPlugin WORLDEDIT_PLUGIN = Objects.requireNonNull((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
|
|
|
|
private static final World BUKKITWORLD = new BukkitWorld(Bukkit.getWorlds().get(0));
|
|
|
|
@Override
|
|
|
|
public void setSelection(Player p, Point minPoint, Point maxPoint) {
|
|
|
|
WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, toBlockVector3(minPoint), toBlockVector3(maxPoint)));
|
|
|
|
}
|
2021-07-31 12:08:53 +02:00
|
|
|
|
2021-07-31 12:57:01 +02:00
|
|
|
private static final BaseBlock WOOL = Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock();
|
2021-12-22 17:31:22 +01:00
|
|
|
private static final BaseBlock WOOL2 = Objects.requireNonNull(BlockTypes.YELLOW_WOOL).getDefaultState().toBaseBlock();
|
2021-07-31 12:57:01 +02:00
|
|
|
private static final BaseBlock CLAY = Objects.requireNonNull(BlockTypes.PINK_TERRACOTTA).getDefaultState().toBaseBlock();
|
2021-12-22 17:31:22 +01:00
|
|
|
private static final BaseBlock CLAY2 = Objects.requireNonNull(BlockTypes.YELLOW_TERRACOTTA).getDefaultState().toBaseBlock();
|
2021-12-22 13:25:57 +01:00
|
|
|
private static final BaseBlock GLAZED = Objects.requireNonNull(BlockTypes.PINK_GLAZED_TERRACOTTA).getDefaultState().toBaseBlock();
|
2021-07-31 12:57:01 +02:00
|
|
|
private static final BaseBlock GLASS = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS).getDefaultState().toBaseBlock();
|
2021-07-31 13:02:19 +02:00
|
|
|
private static final BaseBlock GLASS2 = Objects.requireNonNull(BlockTypes.YELLOW_STAINED_GLASS).getDefaultState().toBaseBlock();
|
2021-07-31 12:57:01 +02:00
|
|
|
private static final BaseBlock GLASS_PANE = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS_PANE).getDefaultState().toBaseBlock();
|
2021-12-24 22:01:55 +01:00
|
|
|
private static final BaseBlock GLASS_PANE2 = Objects.requireNonNull(BlockTypes.YELLOW_STAINED_GLASS_PANE).getDefaultState().toBaseBlock();
|
2021-07-31 12:57:01 +02:00
|
|
|
private static final BaseBlock CONCRETE = Objects.requireNonNull(BlockTypes.PINK_CONCRETE).getDefaultState().toBaseBlock();
|
2021-07-31 13:02:19 +02:00
|
|
|
private static final BaseBlock CONCRETE2 = Objects.requireNonNull(BlockTypes.YELLOW_CONCRETE).getDefaultState().toBaseBlock();
|
2021-07-31 12:57:01 +02:00
|
|
|
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();
|
|
|
|
|
2022-01-29 15:28:28 +01:00
|
|
|
private final Map<String, Long> timing = new HashMap<>();
|
2021-07-31 12:57:01 +02:00
|
|
|
|
2022-02-01 08:51:51 +01:00
|
|
|
private void start(String name) {
|
2021-07-31 12:57:01 +02:00
|
|
|
timing.put(name, System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
|
2022-02-01 08:51:51 +01:00
|
|
|
private long stop(String name) {
|
2021-07-31 12:57:01 +02:00
|
|
|
return System.currentTimeMillis() - timing.getOrDefault(name, System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
|
2022-01-29 15:28:28 +01:00
|
|
|
@Override
|
|
|
|
public EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) {
|
2021-07-31 12:57:01 +02:00
|
|
|
start("clipboardLoad");
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
System.out.println("Clipboard Load: " + stop("clipboardLoad"));
|
|
|
|
|
|
|
|
start("paste");
|
|
|
|
EditSession editSession = paste(clipboard, pastePoint, pasteOptions);
|
|
|
|
System.out.println("Paste: " + stop("paste"));
|
|
|
|
return editSession;
|
|
|
|
}
|
|
|
|
|
2022-01-29 15:28:28 +01:00
|
|
|
@Override
|
|
|
|
public EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) {
|
2021-07-31 12:57:01 +02:00
|
|
|
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
|
|
|
start("changeColor");
|
2021-07-31 13:05:39 +02:00
|
|
|
if (pasteOptions.getColor() != Color.YELLOW) {
|
|
|
|
changeColor(clipboard, pasteOptions.getColor());
|
|
|
|
}
|
2021-08-01 22:01:25 +02:00
|
|
|
if (pasteOptions.isOnlyColors()) {
|
2021-08-03 13:53:50 +02:00
|
|
|
Set<String> blocks = new HashSet<>();
|
|
|
|
blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_wool");
|
|
|
|
blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_terracotta");
|
2021-12-22 13:25:57 +01:00
|
|
|
blocks.add("minecraft:" + pasteOptions.getColor().name().toLowerCase() + "_glazed_terracotta");
|
2021-08-03 13:53:50 +02:00
|
|
|
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");
|
|
|
|
|
2022-05-18 17:33:25 +02:00
|
|
|
e.setMask(new Mask() {
|
2021-08-01 22:01:25 +02:00
|
|
|
@Override
|
|
|
|
public boolean test(BlockVector3 blockVector3) {
|
2022-05-18 17:33:25 +02:00
|
|
|
BaseBlock block = clipboard.getFullBlock(blockVector3);
|
2021-08-03 13:53:50 +02:00
|
|
|
String blockName = block.toString().toLowerCase();
|
|
|
|
return blocks.contains(blockName);
|
2021-08-01 22:01:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public Mask2D toMask2D() {
|
|
|
|
return null;
|
|
|
|
}
|
2022-05-18 17:33:25 +02:00
|
|
|
|
|
|
|
public Mask copy() {
|
|
|
|
return this;
|
|
|
|
}
|
2021-08-01 22:01:25 +02:00
|
|
|
});
|
|
|
|
}
|
2021-07-31 12:57:01 +02:00
|
|
|
System.out.println("ChangeColor: " + stop("changeColor"));
|
|
|
|
|
|
|
|
start("transform");
|
|
|
|
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));
|
2021-12-03 16:32:03 +01:00
|
|
|
v = v.add(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset.multiply(-1, 1, -1)).subtract(0, 0, 1);
|
2021-07-31 12:57:01 +02:00
|
|
|
} else {
|
|
|
|
v = v.subtract(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset);
|
|
|
|
}
|
|
|
|
System.out.println("Transform: " + stop("transform"));
|
|
|
|
|
|
|
|
start("reset");
|
|
|
|
if (pasteOptions.isReset()) {
|
2022-05-18 17:33:25 +02:00
|
|
|
e.setBlocks((Region) new CuboidRegion(toBlockVector3(pasteOptions.getMinPoint()), toBlockVector3(pasteOptions.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock());
|
2021-07-31 12:57:01 +02:00
|
|
|
if (pasteOptions.getWaterLevel() != 0) {
|
2022-05-18 17:33:25 +02:00
|
|
|
e.setBlocks((Region) new CuboidRegion(toBlockVector3(pasteOptions.getMinPoint()), toBlockVector3(pasteOptions.getMaxPoint()).withY(pasteOptions.getWaterLevel())), Objects.requireNonNull(BlockTypes.WATER).getDefaultState().toBaseBlock());
|
2021-07-31 12:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
System.out.println("Reset: " + stop("reset"));
|
|
|
|
start("operation");
|
|
|
|
Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(pasteOptions.isIgnoreAir()).build());
|
|
|
|
System.out.println("Operation: " + stop("operation"));
|
|
|
|
return e;
|
|
|
|
} catch (WorldEditException e) {
|
|
|
|
throw new SecurityException(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-29 15:28:28 +01:00
|
|
|
@Override
|
|
|
|
public void changeColor(Clipboard clipboard, Color color) throws WorldEditException {
|
2021-07-31 12:57:01 +02:00
|
|
|
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();
|
2021-12-22 13:25:57 +01:00
|
|
|
BaseBlock glazed = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_glazed_terracotta")).getDefaultState().toBaseBlock();
|
2021-07-31 12:57:01 +02:00
|
|
|
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);
|
2021-12-22 17:31:22 +01:00
|
|
|
} else if (block.equals(WOOL2)) {
|
|
|
|
clipboard.setBlock(pos, wool);
|
2021-07-31 12:57:01 +02:00
|
|
|
} else if (block.equals(CLAY)) {
|
|
|
|
clipboard.setBlock(pos, clay);
|
2021-12-22 17:31:22 +01:00
|
|
|
} else if (block.equals(CLAY2)) {
|
|
|
|
clipboard.setBlock(pos, clay);
|
2021-12-22 13:25:57 +01:00
|
|
|
} else if (block.equals(GLAZED)) {
|
|
|
|
clipboard.setBlock(pos, glazed);
|
2021-07-31 12:57:01 +02:00
|
|
|
} else if (block.equals(GLASS)) {
|
|
|
|
clipboard.setBlock(pos, glass);
|
2021-07-31 13:02:19 +02:00
|
|
|
} else if (block.equals(GLASS2)) {
|
|
|
|
clipboard.setBlock(pos, glass);
|
2021-07-31 12:57:01 +02:00
|
|
|
} else if (block.equals(GLASS_PANE)) {
|
|
|
|
clipboard.setBlock(pos, glassPane);
|
2021-12-24 22:01:55 +01:00
|
|
|
} else if (block.equals(GLASS_PANE2)) {
|
|
|
|
clipboard.setBlock(pos, glassPane);
|
2021-07-31 12:57:01 +02:00
|
|
|
} else if (block.equals(CARPET)) {
|
|
|
|
clipboard.setBlock(pos, carpet);
|
|
|
|
} else if (block.equals(CONCRETE)) {
|
|
|
|
clipboard.setBlock(pos, concrete);
|
2021-07-31 13:02:19 +02:00
|
|
|
} else if (block.equals(CONCRETE2)) {
|
|
|
|
clipboard.setBlock(pos, concrete);
|
2021-07-31 12:57:01 +02:00
|
|
|
} else if (block.equals(CONCRETE_POWDER)) {
|
|
|
|
clipboard.setBlock(pos, concretePowder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-29 15:28:28 +01:00
|
|
|
@Override
|
|
|
|
public boolean backup(Point minPoint, Point maxPoint, File file) {
|
2021-07-31 12:57:01 +02:00
|
|
|
BukkitWorld bukkitWorld = new BukkitWorld(Bukkit.getWorlds().get(0));
|
2022-01-29 15:28:28 +01:00
|
|
|
CuboidRegion region = new CuboidRegion(bukkitWorld, toBlockVector3(minPoint), toBlockVector3(maxPoint));
|
2021-07-31 12:57:01 +02:00
|
|
|
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
|
|
|
|
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(bukkitWorld, -1)) {
|
|
|
|
ForwardExtentCopy copy = new ForwardExtentCopy(
|
|
|
|
e, region, clipboard, region.getMinimumPoint()
|
|
|
|
);
|
|
|
|
|
|
|
|
copy.setCopyingEntities(false);
|
|
|
|
copy.setCopyingBiomes(false);
|
|
|
|
|
|
|
|
Operations.complete(copy);
|
|
|
|
|
|
|
|
try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) {
|
|
|
|
writer.write(clipboard);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} catch (WorldEditException | IOException e) {
|
|
|
|
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2022-01-29 15:28:28 +01:00
|
|
|
|
|
|
|
private BlockVector3 toBlockVector3(Point point) {
|
|
|
|
return BlockVector3.at(point.getX(), point.getY(), point.getZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean inWater(org.bukkit.World world, Vector tntPosition) {
|
|
|
|
Block block = world.getBlockAt(tntPosition.getBlockX(), tntPosition.getBlockY(), tntPosition.getBlockZ());
|
|
|
|
if (block.getType() == Material.WATER)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
BlockData data = block.getBlockData();
|
|
|
|
if (!(data instanceof Waterlogged))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|