From 5c31db3867e13ef7750287187cd193e0944009d1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 14 Mar 2021 18:33:54 +0100 Subject: [PATCH 1/5] Fix Region --- .../src/de/steamwar/bausystem/world/Region.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 01183bf..168d97c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -315,9 +315,9 @@ public class Region { } public boolean inRegionExtension(Region region, Location l) { - return inRange(l.getX(), region.minX + offsetX - extensionAxisX + 1, sizeX + extensionAxisX * 2 - 1) && - inRange(l.getY(), region.minY + offsetY, sizeY + extensionPositiveY - 1) && - inRange(l.getZ(), region.minZ + offsetZ - extensionNegativeZ + 1, sizeZ + extensionNegativeZ - 1 + extensionPositiveZ); + return inRange(l.getX(), region.minX + offsetX - extensionAxisX, sizeX + extensionAxisX * 2) && + inRange(l.getY(), region.minY + offsetY, sizeY + extensionPositiveY) && + inRange(l.getZ(), region.minZ + offsetZ - extensionNegativeZ, sizeZ + extensionNegativeZ + extensionPositiveZ); } public void fastreset(Region region){ @@ -362,7 +362,7 @@ public class Region { } private static boolean inRange(double l, int min, int size){ - return min <= l && l <= min + size; + return min <= l && l < min + size; } private static void paste(File file, int x, int y, int z, boolean rotate){ //Type of protect -- 2.39.5 From 06d3393c44e045ef6e33b9edf4dc3916cd21c2fe Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 20 Mar 2021 12:47:36 +0100 Subject: [PATCH 2/5] Fix Region --- .../de/steamwar/bausystem/world/Region.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 168d97c..8c6d43b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -42,7 +42,7 @@ public class Region { private static boolean buildArea = false; private static boolean extensionArea = false; - static{ + static { YamlConfiguration config = new YamlConfiguration(); try { config.load(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections.yml")); @@ -52,13 +52,13 @@ public class Region { ConfigurationSection prototypes = config.getConfigurationSection("prototypes"); assert prototypes != null; - for(String prototype : prototypes.getKeys(false)){ + for (String prototype : prototypes.getKeys(false)) { new Prototype(Objects.requireNonNull(prototypes.getConfigurationSection(prototype))); } ConfigurationSection regions = config.getConfigurationSection("regions"); assert regions != null; - for(String region : regions.getKeys(false)){ + for (String region : regions.getKeys(false)) { new Region(Objects.requireNonNull(regions.getConfigurationSection(region))); } } @@ -90,7 +90,7 @@ public class Region { private boolean freeze = false; private boolean fire = false; - private Region(ConfigurationSection config){ + private Region(ConfigurationSection config) { name = config.getName(); minX = config.getInt("minX"); minY = config.getInt("minY"); @@ -155,7 +155,7 @@ public class Region { setLinkedRegion(region -> region.fire = fire); } - public boolean inRegion(Location l){ + public boolean inRegion(Location l) { return prototype.inRegion(this, l); } @@ -171,7 +171,7 @@ public class Region { return prototype.buildArea.inRegionExtension(this, l); } - public void fastreset(){ + public void fastreset() { prototype.fastreset(this); } @@ -183,11 +183,11 @@ public class Region { return prototype.hasTestblock(); } - public void resetTestblock(Schematic schem) throws IOException, NoClipboardException{ + public void resetTestblock(Schematic schem) throws IOException, NoClipboardException { prototype.resetTestblock(this, schem); } - public boolean hasProtection(){ + public boolean hasProtection() { return prototype.hasProtection(); } @@ -250,7 +250,7 @@ public class Region { } } - public static class Prototype{ + public static class Prototype { private static final Map prototypes = new HashMap<>(); private final int sizeX; @@ -275,7 +275,7 @@ public class Region { private final String protectSchematic; //nullable - private Prototype(ConfigurationSection config){ + private Prototype(ConfigurationSection config) { sizeX = config.getInt("sizeX"); sizeY = config.getInt("sizeY"); sizeZ = config.getInt("sizeZ"); @@ -304,27 +304,27 @@ public class Region { protectSchematic = config.getString("protection", null); - if(!config.getName().equals("testblock") && !config.getName().equals("buildArea")) + if (!config.getName().equals("testblock") && !config.getName().equals("buildArea")) prototypes.put(config.getName(), this); } - public boolean inRegion(Region region, Location l){ - return inRange(l.getX(), region.minX + offsetX, sizeX) && + public boolean inRegion(Region region, Location l) { + return inRange(l.getX(), region.minX + offsetX, sizeX) && inRange(l.getY(), region.minY + offsetY, sizeY) && inRange(l.getZ(), region.minZ + offsetZ, sizeZ); } public boolean inRegionExtension(Region region, Location l) { - return inRange(l.getX(), region.minX + offsetX - extensionAxisX, sizeX + extensionAxisX * 2) && + return inRange(l.getX(), region.minX + offsetX - extensionAxisX, sizeX + extensionAxisX * 2) && inRange(l.getY(), region.minY + offsetY, sizeY + extensionPositiveY) && inRange(l.getZ(), region.minZ + offsetZ - extensionNegativeZ, sizeZ + extensionNegativeZ + extensionPositiveZ); } - public void fastreset(Region region){ + public void fastreset(Region region) { File file = new File(schematic); - int x = region.minX + offsetX + sizeX/2; + int x = region.minX + offsetX + sizeX / 2; int y = region.minY + offsetY; - int z = region.minZ + offsetZ + sizeZ/2; + int z = region.minZ + offsetZ + sizeZ / 2; VersionedRunnable.call(new VersionedRunnable(() -> Region_12.paste(file, x, y, z, rotate), 8), new VersionedRunnable(() -> Region_15.fastpaste(file, x, y, z, rotate), 15)); } @@ -333,7 +333,7 @@ public class Region { int x = region.minX + offsetX + sizeX / 2; int y = region.minY + offsetY; int z = region.minZ + offsetZ + sizeZ / 2; - if(schem == null) + if (schem == null) paste(new File(schematic), x, y, z, rotate); else paste(schem.load(), x, y, z, rotate); @@ -347,7 +347,7 @@ public class Region { int x = region.minX + offsetX + sizeX / 2; int y = region.minY + testblock.offsetY - 1; int z = region.minZ + offsetZ + sizeZ / 2; - if(schem == null) + if (schem == null) paste(new File(protectSchematic), x, y, z, rotate); else paste(schem.load(), x, y, z, rotate); @@ -361,16 +361,16 @@ public class Region { testblock.reset(region, schem); } - private static boolean inRange(double l, int min, int size){ + private static boolean inRange(double l, int min, int size) { return min <= l && l < min + size; } - private static void paste(File file, int x, int y, int z, boolean rotate){ //Type of protect + private static void paste(File file, int x, int y, int z, boolean rotate) { //Type of protect VersionedRunnable.call(new VersionedRunnable(() -> Region_12.paste(file, x, y, z, rotate), 8), new VersionedRunnable(() -> Region_15.paste(file, x, y, z, rotate), 15)); } - private static void paste(Clipboard clipboard, int x, int y, int z, boolean rotate){ + private static void paste(Clipboard clipboard, int x, int y, int z, boolean rotate) { VersionedRunnable.call(new VersionedRunnable(() -> Region_12.paste(clipboard, x, y, z, rotate), 8), new VersionedRunnable(() -> Region_15.paste(clipboard, x, y, z, rotate), 15)); } -- 2.39.5 From c4c785f9dac749686159f844c6aa37fb382e9972 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Fri, 2 Apr 2021 21:03:47 +0200 Subject: [PATCH 3/5] debug output --- .../steamwar/bausystem/world/Region_15.java | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) 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 2eb5a52..e4d354e 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java @@ -28,14 +28,15 @@ import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.session.ClipboardHolder; -import org.bukkit.Bukkit; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Objects; +import org.bukkit.Bukkit; + class Region_15 { + private Region_15() { } @@ -51,20 +52,37 @@ class Region_15 { } static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate) { - BlockVector3 dimensions = clipboard.getDimensions(); - BlockVector3 v = BlockVector3.at(x, y, z); - BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); - AffineTransform aT = new AffineTransform(); - if (rotate) { - aT = aT.rotateY(180); - v = v.add(dimensions.getX() / 2 + dimensions.getX() % 2, 0, dimensions.getZ() / 2 + dimensions.getZ() % 2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); - } else { - v = v.subtract(dimensions.getX() / 2 - dimensions.getX() % 2, 0, dimensions.getZ() / 2 - dimensions.getZ() % 2).subtract(offset); - } - try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { ClipboardHolder ch = new ClipboardHolder(clipboard); - ch.setTransform(aT); + BlockVector3 dimensions = clipboard.getDimensions(); + BlockVector3 v = BlockVector3.at(x, y, z); + BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); + System.out.println(clipboard.getRegion().getMinimumPoint()); + if (rotate) { + ch.setTransform(new AffineTransform().rotateY(180)); + v = v.add(dimensions.getX() / 2 + dimensions.getX() % 2, 0, dimensions.getZ() / 2 + dimensions.getZ() % 2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); + } else { + 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()); + return e; + } + } + + static EditSession pasteNew(Clipboard clipboard, int x, int y, int z, boolean rotate) { + try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { + ClipboardHolder ch = new ClipboardHolder(clipboard); + BlockVector3 dimensions = clipboard.getDimensions(); + BlockVector3 v = BlockVector3.at(x, y, z); + BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); + if (rotate) { + ch.setTransform(new AffineTransform().rotateY(180)); + v = v.add(dimensions.getX() / 2 + dimensions.getX() % 2, 0, dimensions.getZ() / 2 + dimensions.getZ() % 2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); + } else { + 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()); return e; } -- 2.39.5 From 8d6806b538097423535b1aa517a6e3c122dfe6f9 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Fri, 2 Apr 2021 21:23:23 +0200 Subject: [PATCH 4/5] debug output --- .../src/de/steamwar/bausystem/world/Region_15.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 e4d354e..7547b24 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java @@ -23,7 +23,9 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.transform.AffineTransform; @@ -42,8 +44,8 @@ class Region_15 { static EditSession paste(File file, int x, int y, int z, boolean rotate) { Clipboard clipboard; - try { - clipboard = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file)).read(); + 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); } @@ -57,7 +59,9 @@ class Region_15 { BlockVector3 dimensions = clipboard.getDimensions(); BlockVector3 v = BlockVector3.at(x, y, z); BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); - System.out.println(clipboard.getRegion().getMinimumPoint()); + System.out.println("min point cb: " + clipboard.getMinimumPoint()); + System.out.println("min point rg: " + clipboard.getRegion().getMinimumPoint()); + System.out.println("origin: " + clipboard.getOrigin()); if (rotate) { ch.setTransform(new AffineTransform().rotateY(180)); v = v.add(dimensions.getX() / 2 + dimensions.getX() % 2, 0, dimensions.getZ() / 2 + dimensions.getZ() % 2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); -- 2.39.5 From 2131cc9423e82b4121661316ecf7801f5763fcd4 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Fri, 2 Apr 2021 21:45:04 +0200 Subject: [PATCH 5/5] fixed? ws-region-reset --- .../steamwar/bausystem/world/Region_15.java | 21 ------------------- 1 file changed, 21 deletions(-) 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 7547b24..76da59d 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java @@ -54,27 +54,6 @@ class Region_15 { } static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate) { - try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { - ClipboardHolder ch = new ClipboardHolder(clipboard); - BlockVector3 dimensions = clipboard.getDimensions(); - BlockVector3 v = BlockVector3.at(x, y, z); - BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); - System.out.println("min point cb: " + clipboard.getMinimumPoint()); - System.out.println("min point rg: " + clipboard.getRegion().getMinimumPoint()); - System.out.println("origin: " + clipboard.getOrigin()); - if (rotate) { - ch.setTransform(new AffineTransform().rotateY(180)); - v = v.add(dimensions.getX() / 2 + dimensions.getX() % 2, 0, dimensions.getZ() / 2 + dimensions.getZ() % 2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1); - } else { - 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()); - return e; - } - } - - static EditSession pasteNew(Clipboard clipboard, int x, int y, int z, boolean rotate) { try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { ClipboardHolder ch = new ClipboardHolder(clipboard); BlockVector3 dimensions = clipboard.getDimensions(); -- 2.39.5