From 3df67955a7f2e0255cd28ddc5a317b9e73f82ed1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 31 Jul 2021 12:08:53 +0200 Subject: [PATCH] Fix Backup loading Signed-off-by: yoyosource --- .../steamwar/bausystem/region/Region_15.java | 29 +++++++++++++++++-- .../bausystem/features/bau/BauCommand.java | 2 +- .../de/steamwar/bausystem/region/Region.java | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/region/Region_15.java b/BauSystem_15/src/de/steamwar/bausystem/region/Region_15.java index 47f92ba9..e0ed9db7 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/region/Region_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/region/Region_15.java @@ -45,27 +45,47 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; import java.util.logging.Level; @UtilityClass public class Region_15 { + + private Map 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")); - 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) { 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); BlockVector3 dimensions = clipboard.getDimensions(); BlockVector3 v = BlockVector3.at(pastePoint.getX(), pastePoint.getY(), pastePoint.getZ()); @@ -76,14 +96,19 @@ public class Region_15 { } else { v = v.subtract(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset); } + System.out.println("Transform: " + stop("transform")); + 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); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauCommand.java index f7e8a00c..94ce4021 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauCommand.java @@ -79,7 +79,7 @@ public class BauCommand extends SWCommand { } - @Register("addmemeber") + @Register("addmember") public void addMemberCommand(Player p, String s) { } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 2a898128..e8086e41 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -371,7 +371,7 @@ public class Region { } 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(); undoSessions.push(editSession); }