Fix Backup loading
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
3df67955a7
Commit
731f7baaec
@ -36,7 +36,6 @@ 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 lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -53,105 +52,146 @@ import java.util.logging.Level;
|
||||
@UtilityClass
|
||||
public class Region_15 {
|
||||
|
||||
private Map<String, Long> timing = new HashMap<>();
|
||||
public void start(String name) {
|
||||
timing.put(name, System.currentTimeMillis());
|
||||
}
|
||||
public long stop(String name) {
|
||||
return System.currentTimeMillis() - timing.getOrDefault(name, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) {
|
||||
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"));
|
||||
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 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();
|
||||
|
||||
start("paste");
|
||||
EditSession editSession = paste(clipboard, pastePoint, pasteOptions);
|
||||
System.out.println("Paste: " + stop("paste"));
|
||||
return editSession;
|
||||
}
|
||||
private Map<String, Long> timing = new HashMap<>();
|
||||
|
||||
EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) {
|
||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||
start("changeColor");
|
||||
if (pasteOptions.getColor() != Color.YELLOW) {
|
||||
changeColor(clipboard, pasteOptions.getColor());
|
||||
}
|
||||
System.out.println("ChangeColor: " + stop("changeColor"));
|
||||
public void start(String name) {
|
||||
timing.put(name, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
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));
|
||||
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"));
|
||||
public long stop(String name) {
|
||||
return System.currentTimeMillis() - timing.getOrDefault(name, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
start("reset");
|
||||
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);
|
||||
}
|
||||
}
|
||||
EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) {
|
||||
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"));
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
start("paste");
|
||||
EditSession editSession = paste(clipboard, pastePoint, pasteOptions);
|
||||
System.out.println("Paste: " + stop("paste"));
|
||||
return editSession;
|
||||
}
|
||||
|
||||
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()
|
||||
);
|
||||
EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) {
|
||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||
start("changeColor");
|
||||
changeColor(clipboard, pasteOptions.getColor());
|
||||
System.out.println("ChangeColor: " + stop("changeColor"));
|
||||
|
||||
copy.setCopyingEntities(false);
|
||||
copy.setCopyingBiomes(false);
|
||||
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));
|
||||
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"));
|
||||
|
||||
Operations.complete(copy);
|
||||
start("reset");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
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();
|
||||
|
||||
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(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;
|
||||
}
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren