From fc7e502a16d32acbcede2809da3368d68c6464a9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 4 Apr 2021 21:20:51 +0200 Subject: [PATCH 1/2] Add '/rg restore' to restore broken blocks not self set ones --- .../steamwar/bausystem/world/Region_12.java | 8 ++-- .../steamwar/bausystem/world/Region_15.java | 8 ++-- .../bausystem/commands/CommandRegion.java | 47 +++++++++++++++++++ .../de/steamwar/bausystem/world/Region.java | 33 +++++++------ 4 files changed, 71 insertions(+), 25 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java index d95b106..f9ca671 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/world/Region_12.java @@ -40,7 +40,7 @@ class Region_12 { private Region_12() { } - static EditSession paste(File file, int x, int y, int z, boolean rotate) { + static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir) { World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Clipboard clipboard; try { @@ -49,10 +49,10 @@ class Region_12 { throw new SecurityException("Bausystem schematic not found", e); } - return paste(clipboard, x, y, z, rotate); + return paste(clipboard, x, y, z, rotate, ignoreAir); } - static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate) { + static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir) { World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Vector dimensions = clipboard.getDimensions(); @@ -69,7 +69,7 @@ class Region_12 { EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); ClipboardHolder ch = new ClipboardHolder(clipboard, w.getWorldData()); ch.setTransform(aT); - Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).build()); + Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).ignoreAirBlocks(ignoreAir).build()); return e; } } diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java index 76da59d..5fcadac 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java @@ -42,7 +42,7 @@ class Region_15 { private Region_15() { } - static EditSession paste(File file, int x, int y, int z, boolean rotate) { + static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir) { Clipboard clipboard; try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) { clipboard = reader.read(); @@ -50,10 +50,10 @@ class Region_15 { throw new SecurityException("Bausystem schematic not found", e); } - return paste(clipboard, x, y, z, rotate); + return paste(clipboard, x, y, z, rotate, ignoreAir); } - static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate) { + static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir) { try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { ClipboardHolder ch = new ClipboardHolder(clipboard); BlockVector3 dimensions = clipboard.getDimensions(); @@ -66,7 +66,7 @@ class Region_15 { v = v.subtract(dimensions.getX() / 2 - dimensions.getX() % 2, 0, dimensions.getZ() / 2 - dimensions.getZ() % 2).subtract(offset); } - Operations.completeBlindly(ch.createPaste(e).to(v).build()); + Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(ignoreAir).build()); return e; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java index 7ed72ff..eb984b0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java @@ -5,8 +5,13 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Region; import de.steamwar.bausystem.world.Welt; import de.steamwar.command.SWCommand; +import de.steamwar.sql.Schematic; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import java.io.IOException; +import java.util.logging.Level; + public class CommandRegion extends SWCommand { public CommandRegion() { @@ -50,6 +55,39 @@ public class CommandRegion extends SWCommand { } } + @Register("restore") + public void genericRestoreCommand(Player p) { + if (!permissionCheck(p)) return; + Region region = regionCheck(p); + if (region == null) return; + try { + region.reset(null, true); + p.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); + } catch (IOException e) { + p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region"); + Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e); + } + } + + @Register("restore") + public void schematicRestoreCommand(Player p, String s) { + if (!permissionCheck(p)) return; + Region region = regionCheck(p); + if (region == null) return; + Schematic schem = Schematic.getSchemFromDB(s, p.getUniqueId()); + if (schem == null) { + p.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); + return; + } + try { + region.reset(schem, true); + p.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); + } catch (IOException e) { + p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region"); + Bukkit.getLogger().log(Level.WARNING, "Failed reset", e); + } + } + static boolean checkGlobalRegion(Region region, Player p) { if(Region.GlobalRegion.isGlobalRegion(region)) { p.sendMessage(BauSystem.PREFIX + "§cDu bist in keiner Region"); @@ -66,6 +104,15 @@ public class CommandRegion extends SWCommand { return true; } + private Region regionCheck(Player player) { + Region region = Region.getRegion(player.getLocation()); + if (region == Region.GlobalRegion.getInstance()) { + player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); + return null; + } + return region; + } + enum Action { UNDO, REDO diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 13b99d1..e06c85e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -174,14 +174,13 @@ public class Region { return prototype.buildArea.inRegionExtension(this, l); } - public void reset() throws IOException { - initSessions(); - undosessions.push(prototype.reset(this, null)); + public void reset(Schematic schem) throws IOException, NoClipboardException { + reset(schem, false); } - public void reset(Schematic schem) throws IOException, NoClipboardException { + public void reset(Schematic schem, boolean ignoreAir) throws IOException, NoClipboardException { initSessions(); - undosessions.push(prototype.reset(this, schem)); + undosessions.push(prototype.reset(this, schem, ignoreAir)); } public boolean hasTestblock() { @@ -368,14 +367,14 @@ public class Region { inRange(l.getZ(), region.minZ + offsetZ - extensionNegativeZ, sizeZ + extensionNegativeZ + extensionPositiveZ); } - public EditSession reset(Region region, Schematic schem) throws IOException, NoClipboardException { + public EditSession reset(Region region, Schematic schem, boolean ignoreAir) throws IOException, NoClipboardException { int x = region.minX + offsetX + sizeX / 2; int y = region.minY + offsetY; int z = region.minZ + offsetZ + sizeZ / 2; if (schem == null) - return paste(new File(schematic), x, y, z, rotate); + return paste(new File(schematic), x, y, z, rotate, ignoreAir); else - return paste(schem.load(), x, y, z, rotate); + return paste(schem.load(), x, y, z, rotate, ignoreAir); } public boolean hasProtection() { @@ -387,9 +386,9 @@ public class Region { int y = region.minY + testblock.offsetY - 1; int z = region.minZ + offsetZ + sizeZ / 2; if (schem == null) - return paste(new File(protectSchematic), x, y, z, rotate); + return paste(new File(protectSchematic), x, y, z, rotate, false); else - return paste(schem.load(), x, y, z, rotate); + return paste(schem.load(), x, y, z, rotate, false); } public boolean hasTestblock() { @@ -397,21 +396,21 @@ public class Region { } public EditSession resetTestblock(Region region, Schematic schem) throws IOException, NoClipboardException { - return testblock.reset(region, schem); + return testblock.reset(region, schem, false); } private static boolean inRange(double l, int min, int size) { return min <= l && l < min + size; } - private static EditSession paste(File file, int x, int y, int z, boolean rotate) { //Type of protect - return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(file, x, y, z, rotate), 8), - new VersionedCallable(() -> Region_15.paste(file, x, y, z, rotate), 15)); + private static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir) { //Type of protect + return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(file, x, y, z, rotate, ignoreAir), 8), + new VersionedCallable(() -> Region_15.paste(file, x, y, z, rotate, ignoreAir), 15)); } - private static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate) { - return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(clipboard, x, y, z, rotate), 8), - new VersionedCallable(() -> Region_15.paste(clipboard, x, y, z, rotate), 15)); + private static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir) { + return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(clipboard, x, y, z, rotate, ignoreAir), 8), + new VersionedCallable(() -> Region_15.paste(clipboard, x, y, z, rotate, ignoreAir), 15)); } } } -- 2.39.5 From 738954f669c2ea4cf37367c8e25265e6d4b3e0c0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 4 Apr 2021 21:31:33 +0200 Subject: [PATCH 2/2] Add '/rg restore' to restore broken blocks not self set ones --- .../bausystem/commands/CommandRegion.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java index eb984b0..dcd8d5b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRegion.java @@ -58,7 +58,9 @@ public class CommandRegion extends SWCommand { @Register("restore") public void genericRestoreCommand(Player p) { if (!permissionCheck(p)) return; - Region region = regionCheck(p); + Region region = Region.getRegion(p.getLocation()); + if(checkGlobalRegion(region, p)) return; + if (region == null) return; try { region.reset(null, true); @@ -72,7 +74,9 @@ public class CommandRegion extends SWCommand { @Register("restore") public void schematicRestoreCommand(Player p, String s) { if (!permissionCheck(p)) return; - Region region = regionCheck(p); + Region region = Region.getRegion(p.getLocation()); + if(checkGlobalRegion(region, p)) return; + if (region == null) return; Schematic schem = Schematic.getSchemFromDB(s, p.getUniqueId()); if (schem == null) { @@ -104,15 +108,6 @@ public class CommandRegion extends SWCommand { return true; } - private Region regionCheck(Player player) { - Region region = Region.getRegion(player.getLocation()); - if (region == Region.GlobalRegion.getInstance()) { - player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); - return null; - } - return region; - } - enum Action { UNDO, REDO -- 2.39.5