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:08:53 +02:00
Ursprung 6d5f7a48f2
Commit 3df67955a7
3 geänderte Dateien mit 29 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -45,27 +45,47 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.logging.Level; import java.util.logging.Level;
@UtilityClass @UtilityClass
public class Region_15 { 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) { EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) {
start("clipboardLoad");
Clipboard clipboard; Clipboard clipboard;
try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) { try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) {
clipboard = reader.read(); clipboard = reader.read();
} catch (NullPointerException | IOException e) { } catch (NullPointerException | IOException e) {
throw new SecurityException("Bausystem schematic not found", e); throw new SecurityException("Bausystem schematic not found", e);
} }
System.out.println("Clipboard Load: " + stop("clipboardLoad"));
return paste(clipboard, pastePoint, pasteOptions); start("paste");
EditSession editSession = paste(clipboard, pastePoint, pasteOptions);
System.out.println("Paste: " + stop("paste"));
return editSession;
} }
EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) { EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) {
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
changeColor(clipboard, pasteOptions.getColor()); start("changeColor");
if (pasteOptions.getColor() != Color.YELLOW) {
changeColor(clipboard, pasteOptions.getColor());
}
System.out.println("ChangeColor: " + stop("changeColor"));
start("transform");
ClipboardHolder ch = new ClipboardHolder(clipboard); ClipboardHolder ch = new ClipboardHolder(clipboard);
BlockVector3 dimensions = clipboard.getDimensions(); BlockVector3 dimensions = clipboard.getDimensions();
BlockVector3 v = BlockVector3.at(pastePoint.getX(), pastePoint.getY(), pastePoint.getZ()); BlockVector3 v = BlockVector3.at(pastePoint.getX(), pastePoint.getY(), pastePoint.getZ());
@ -76,14 +96,19 @@ public class Region_15 {
} else { } else {
v = v.subtract(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset); v = v.subtract(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset);
} }
System.out.println("Transform: " + stop("transform"));
start("reset");
if (pasteOptions.isReset()) { if (pasteOptions.isReset()) {
e.setBlocks(new CuboidRegion(RegionUtils_15.toBlockVector3(pasteOptions.getMinPoint()), RegionUtils_15.toBlockVector3(pasteOptions.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock()); e.setBlocks(new CuboidRegion(RegionUtils_15.toBlockVector3(pasteOptions.getMinPoint()), RegionUtils_15.toBlockVector3(pasteOptions.getMaxPoint())), Objects.requireNonNull(BlockTypes.AIR).getDefaultState().toBaseBlock());
if (pasteOptions.getWaterLevel() != 0) { 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()); 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()); Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(pasteOptions.isIgnoreAir()).build());
System.out.println("Operation: " + stop("operation"));
return e; return e;
} catch (WorldEditException e) { } catch (WorldEditException e) {
throw new SecurityException(e.getMessage(), e); throw new SecurityException(e.getMessage(), e);

Datei anzeigen

@ -79,7 +79,7 @@ public class BauCommand extends SWCommand {
} }
@Register("addmemeber") @Register("addmember")
public void addMemberCommand(Player p, String s) { public void addMemberCommand(Player p, String s) {
} }

Datei anzeigen

@ -371,7 +371,7 @@ public class Region {
} }
public void reset(File file) { public void reset(File file) {
EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, true, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel)); EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, false, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel));
initSessions(); initSessions();
undoSessions.push(editSession); undoSessions.push(editSession);
} }