SteamWar/BauSystem2.0
Archiviert
12
0

Fix Backup loading

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-07-31 12:57:01 +02:00
Ursprung 3df67955a7
Commit 731f7baaec

Datei anzeigen

@ -36,7 +36,6 @@ import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -53,105 +52,146 @@ import java.util.logging.Level;
@UtilityClass @UtilityClass
public class Region_15 { public class Region_15 {
private Map<String, Long> timing = new HashMap<>(); private static final BaseBlock WOOL = Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock();
public void start(String name) { private static final BaseBlock CLAY = Objects.requireNonNull(BlockTypes.PINK_TERRACOTTA).getDefaultState().toBaseBlock();
timing.put(name, System.currentTimeMillis()); 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();
public long stop(String name) { private static final BaseBlock CONCRETE = Objects.requireNonNull(BlockTypes.PINK_CONCRETE).getDefaultState().toBaseBlock();
return System.currentTimeMillis() - timing.getOrDefault(name, System.currentTimeMillis()); 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();
EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) { private Map<String, Long> timing = new HashMap<>();
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"); public void start(String name) {
EditSession editSession = paste(clipboard, pastePoint, pasteOptions); timing.put(name, System.currentTimeMillis());
System.out.println("Paste: " + stop("paste")); }
return editSession;
}
EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) { public long stop(String name) {
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { return System.currentTimeMillis() - timing.getOrDefault(name, System.currentTimeMillis());
start("changeColor"); }
if (pasteOptions.getColor() != Color.YELLOW) {
changeColor(clipboard, pasteOptions.getColor());
}
System.out.println("ChangeColor: " + stop("changeColor"));
start("transform"); EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) {
ClipboardHolder ch = new ClipboardHolder(clipboard); start("clipboardLoad");
BlockVector3 dimensions = clipboard.getDimensions(); Clipboard clipboard;
BlockVector3 v = BlockVector3.at(pastePoint.getX(), pastePoint.getY(), pastePoint.getZ()); try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) {
BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); clipboard = reader.read();
if (pasteOptions.isRotate()) { } catch (NullPointerException | IOException e) {
ch.setTransform(new AffineTransform().rotateY(180)); throw new SecurityException("Bausystem schematic not found", e);
v = v.add(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); }
} else { System.out.println("Clipboard Load: " + stop("clipboardLoad"));
v = v.subtract(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset);
}
System.out.println("Transform: " + stop("transform"));
start("reset"); start("paste");
if (pasteOptions.isReset()) { EditSession editSession = paste(clipboard, pastePoint, pasteOptions);
e.setBlocks(new CuboidRegion(RegionUtils_15.toBlockVector3(pasteOptions.getMinPoint()), RegionUtils_15.toBlockVector3(pasteOptions.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock()); System.out.println("Paste: " + stop("paste"));
if (pasteOptions.getWaterLevel() != 0) { return editSession;
e.setBlocks(new CuboidRegion(RegionUtils_15.toBlockVector3(pasteOptions.getMinPoint()), RegionUtils_15.toBlockVector3(pasteOptions.getMaxPoint()).withY(pasteOptions.getWaterLevel())), Objects.requireNonNull(BlockTypes.WATER).getDefaultState().toBaseBlock()); }
}
}
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);
}
}
void changeColor(Clipboard clipboard, Color color) throws WorldEditException { EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) {
for (int x = 0; x < clipboard.getDimensions().getX(); x++) { try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
for (int y = 0; y < clipboard.getDimensions().getY(); y++) { start("changeColor");
for (int z = 0; z < clipboard.getDimensions().getZ(); z++) { changeColor(clipboard, pasteOptions.getColor());
BlockVector3 blockPointer = clipboard.getMinimumPoint().add(x, y, z); System.out.println("ChangeColor: " + stop("changeColor"));
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());
}
}
}
}
boolean backup(Point minPoint, Point maxPoint, File file) { start("transform");
BukkitWorld bukkitWorld = new BukkitWorld(Bukkit.getWorlds().get(0)); ClipboardHolder ch = new ClipboardHolder(clipboard);
CuboidRegion region = new CuboidRegion(bukkitWorld, RegionUtils_15.toBlockVector3(minPoint), RegionUtils_15.toBlockVector3(maxPoint)); BlockVector3 dimensions = clipboard.getDimensions();
BlockArrayClipboard clipboard = new BlockArrayClipboard(region); BlockVector3 v = BlockVector3.at(pastePoint.getX(), pastePoint.getY(), pastePoint.getZ());
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(bukkitWorld, -1)) { BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
ForwardExtentCopy copy = new ForwardExtentCopy( if (pasteOptions.isRotate()) {
e, region, clipboard, region.getMinimumPoint() 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);
}
System.out.println("Transform: " + stop("transform"));
copy.setCopyingEntities(false); start("reset");
copy.setCopyingBiomes(false); 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());
}
}
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);
}
}
Operations.complete(copy); 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 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();
try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) { for (int x = 0; x < clipboard.getDimensions().getX(); x++) {
writer.write(clipboard); for (int y = 0; y < clipboard.getDimensions().getY(); y++) {
} for (int z = 0; z < clipboard.getDimensions().getZ(); z++) {
return true; BlockVector3 pos = minimum.add(x, y, z);
} catch (WorldEditException | IOException e) { BaseBlock block = clipboard.getFullBlock(pos);
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e); if (block.equals(WOOL)) {
return false; clipboard.setBlock(pos, wool);
} } else if (block.equals(CLAY)) {
} clipboard.setBlock(pos, clay);
} 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);
}
}
}
}
/*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());
}
}
}*/
}
boolean backup(Point minPoint, Point maxPoint, File file) {
BukkitWorld bukkitWorld = new BukkitWorld(Bukkit.getWorlds().get(0));
CuboidRegion region = new CuboidRegion(bukkitWorld, RegionUtils_15.toBlockVector3(minPoint), RegionUtils_15.toBlockVector3(maxPoint));
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;
}
}
} }