MEDDL
Dieser Commit ist enthalten in:
Ursprung
b399ec3a3d
Commit
8f7ca37717
135
BauSystem_15/src/de/steamwar/bausystem/region/RegionUtils_15.java
Normale Datei
135
BauSystem_15/src/de/steamwar/bausystem/region/RegionUtils_15.java
Normale Datei
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 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 com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
|
||||
@UtilityClass
|
||||
public class RegionUtils_15 {
|
||||
|
||||
public BlockVector3 toBlockVector3(Point point) {
|
||||
return BlockVector3.at(point.getX(), point.getY(), point.getZ());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
102
BauSystem_15/src/de/steamwar/bausystem/region/Region_15.java
Normale Datei
102
BauSystem_15/src/de/steamwar/bausystem/region/Region_15.java
Normale Datei
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
|
||||
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;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
|
||||
@UtilityClass
|
||||
public class Region_15 {
|
||||
|
||||
EditSession paste(File file, int x, int y, int z, 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);
|
||||
}
|
||||
|
||||
return paste(clipboard, x, y, z, pasteOptions);
|
||||
}
|
||||
|
||||
EditSession paste(Clipboard clipboard, int x, int y, int z, PasteOptions pasteOptions) {
|
||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||
changeColor(clipboard, pasteOptions.getColor());
|
||||
|
||||
ClipboardHolder ch = new ClipboardHolder(clipboard);
|
||||
BlockVector3 dimensions = clipboard.getDimensions();
|
||||
BlockVector3 v = BlockVector3.at(x, y, z);
|
||||
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(1, 0, 1);
|
||||
} else {
|
||||
v = v.subtract(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset);
|
||||
}
|
||||
|
||||
if (pasteOptions.isReset()) {
|
||||
e.setBlocks(new CuboidRegion(RegionUtils_15.toBlockVector3(pasteOptions.getMinPoint()), RegionUtils_15.toBlockVector3(pasteOptions.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock());
|
||||
if (pasteOptions.getWaterLevel() != 0) {
|
||||
e.setBlocks(new CuboidRegion(RegionUtils_15.toBlockVector3(pasteOptions.getMinPoint()), RegionUtils_15.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);
|
||||
}
|
||||
}
|
||||
|
||||
void changeColor(Clipboard clipboard, Color color) throws WorldEditException {
|
||||
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 blockPointer = clipboard.getMinimumPoint().add(x, y, z);
|
||||
BaseBlock baseBlock = clipboard.getFullBlock(blockPointer);
|
||||
BlockType blockType = baseBlock.getBlockType();
|
||||
if (blockType != BlockTypes.YELLOW_CONCRETE && blockType != BlockTypes.YELLOW_STAINED_GLASS) {
|
||||
continue;
|
||||
}
|
||||
clipboard.setBlock(blockPointer, RegionUtils_15.mapColor(blockType, color).getDefaultState().toBaseBlock());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
67
BauSystem_API/src/de/steamwar/bausystem/region/PasteOptions.java
Normale Datei
67
BauSystem_API/src/de/steamwar/bausystem/region/PasteOptions.java
Normale Datei
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.NoArgsConstructor;
|
||||
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PasteOptions {
|
||||
|
||||
/**
|
||||
* Used in 1.12 and 1.15
|
||||
*/
|
||||
private final boolean rotate;
|
||||
|
||||
/**
|
||||
* Used in 1.12 and 1.15
|
||||
*/
|
||||
private final boolean ignoreAir;
|
||||
|
||||
/**
|
||||
* Used in 1.15
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
/**
|
||||
* Used in 1.15
|
||||
*/
|
||||
private final boolean reset;
|
||||
|
||||
/**
|
||||
* Used in 1.15
|
||||
*/
|
||||
private final Point minPoint;
|
||||
|
||||
/**
|
||||
* Used in 1.15
|
||||
*/
|
||||
private final Point maxPoint;
|
||||
|
||||
/**
|
||||
* Used in 1.15
|
||||
*/
|
||||
private final int waterLevel;
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren