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.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) {
|
|
||||||
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");
|
private Map<String, Long> timing = new HashMap<>();
|
||||||
EditSession editSession = paste(clipboard, pastePoint, pasteOptions);
|
|
||||||
System.out.println("Paste: " + stop("paste"));
|
|
||||||
return editSession;
|
|
||||||
}
|
|
||||||
|
|
||||||
EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) {
|
public void start(String name) {
|
||||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
timing.put(name, System.currentTimeMillis());
|
||||||
start("changeColor");
|
}
|
||||||
if (pasteOptions.getColor() != Color.YELLOW) {
|
|
||||||
changeColor(clipboard, pasteOptions.getColor());
|
|
||||||
}
|
|
||||||
System.out.println("ChangeColor: " + stop("changeColor"));
|
|
||||||
|
|
||||||
start("transform");
|
public long stop(String name) {
|
||||||
ClipboardHolder ch = new ClipboardHolder(clipboard);
|
return System.currentTimeMillis() - timing.getOrDefault(name, System.currentTimeMillis());
|
||||||
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"));
|
|
||||||
|
|
||||||
start("reset");
|
EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) {
|
||||||
if (pasteOptions.isReset()) {
|
start("clipboardLoad");
|
||||||
e.setBlocks(new CuboidRegion(RegionUtils_15.toBlockVector3(pasteOptions.getMinPoint()), RegionUtils_15.toBlockVector3(pasteOptions.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock());
|
Clipboard clipboard;
|
||||||
if (pasteOptions.getWaterLevel() != 0) {
|
try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) {
|
||||||
e.setBlocks(new CuboidRegion(RegionUtils_15.toBlockVector3(pasteOptions.getMinPoint()), RegionUtils_15.toBlockVector3(pasteOptions.getMaxPoint()).withY(pasteOptions.getWaterLevel())), Objects.requireNonNull(BlockTypes.WATER).getDefaultState().toBaseBlock());
|
clipboard = reader.read();
|
||||||
}
|
} catch (NullPointerException | IOException e) {
|
||||||
}
|
throw new SecurityException("Bausystem schematic not found", e);
|
||||||
System.out.println("Reset: " + stop("reset"));
|
}
|
||||||
start("operation");
|
System.out.println("Clipboard Load: " + stop("clipboardLoad"));
|
||||||
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 {
|
start("paste");
|
||||||
for (int x = 0; x < clipboard.getDimensions().getX(); x++) {
|
EditSession editSession = paste(clipboard, pastePoint, pasteOptions);
|
||||||
for (int y = 0; y < clipboard.getDimensions().getY(); y++) {
|
System.out.println("Paste: " + stop("paste"));
|
||||||
for (int z = 0; z < clipboard.getDimensions().getZ(); z++) {
|
return editSession;
|
||||||
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) {
|
EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) {
|
||||||
BukkitWorld bukkitWorld = new BukkitWorld(Bukkit.getWorlds().get(0));
|
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||||
CuboidRegion region = new CuboidRegion(bukkitWorld, RegionUtils_15.toBlockVector3(minPoint), RegionUtils_15.toBlockVector3(maxPoint));
|
start("changeColor");
|
||||||
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
|
changeColor(clipboard, pasteOptions.getColor());
|
||||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(bukkitWorld, -1)) {
|
System.out.println("ChangeColor: " + stop("changeColor"));
|
||||||
ForwardExtentCopy copy = new ForwardExtentCopy(
|
|
||||||
e, region, clipboard, region.getMinimumPoint()
|
|
||||||
);
|
|
||||||
|
|
||||||
copy.setCopyingEntities(false);
|
start("transform");
|
||||||
copy.setCopyingBiomes(false);
|
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))) {
|
void changeColor(Clipboard clipboard, Color color) throws WorldEditException {
|
||||||
writer.write(clipboard);
|
BlockVector3 minimum = clipboard.getRegion().getMinimumPoint();
|
||||||
}
|
BaseBlock wool = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_wool")).getDefaultState().toBaseBlock();
|
||||||
return true;
|
BaseBlock clay = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_terracotta")).getDefaultState().toBaseBlock();
|
||||||
} catch (WorldEditException | IOException e) {
|
BaseBlock glass = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_stained_glass")).getDefaultState().toBaseBlock();
|
||||||
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
|
BaseBlock glassPane = Objects.requireNonNull(BlockTypes.get(color.name().toLowerCase() + "_stained_glass_pane")).getDefaultState().toBaseBlock();
|
||||||
return false;
|
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