From 1c9c0d0207fb93a972a58b7e70674dce3774d559 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 1 Apr 2019 21:39:01 +1100 Subject: [PATCH 1/2] Schematic fixes The 1.13 schematic format uses the `.schem` extension, use that instead Support loading both legacy `.schematic` and `.schem` files for road schematics Fix reading road schematics with an offset --- .../plotsquared/plot/commands/Owner.java | 2 +- .../plotsquared/plot/commands/Save.java | 2 +- .../plot/generator/HybridPlotManager.java | 12 ++++---- .../plot/generator/HybridPlotWorld.java | 30 +++++++++++-------- .../plot/generator/HybridUtils.java | 5 ++-- .../plotsquared/plot/object/Plot.java | 2 +- .../plot/util/SchematicHandler.java | 15 ++++++---- 7 files changed, 38 insertions(+), 30 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java index 0e692748f..89416512f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java @@ -27,7 +27,7 @@ import java.util.UUID; } } else { uuid = UUIDHandler.getUUID(value, null); - name = UUIDHandler.getName(uuid); + name = uuid == null ? value : UUIDHandler.getName(uuid); name = name == null ? value : name; } if (uuid == null || value.equalsIgnoreCase("-")) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Save.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Save.java index d408ce2fa..481acba53 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Save.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Save.java @@ -64,7 +64,7 @@ import java.util.UUID; MainUtil.sendMessage(player, Captions.SAVE_SUCCESS); List schematics = player.getMeta("plot_schematics"); if (schematics != null) { - schematics.add(file + ".schematic"); + schematics.add(file + ".schem"); } } }); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java index b95913102..52dc99f82 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotManager.java @@ -31,22 +31,22 @@ public class HybridPlotManager extends ClassicPlotManager { + File.separator; try { File sideroad = - MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "sideroad.schematic"); + MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "sideroad.schem"); if (sideroad.exists()) { - files.add(new FileBytes(newDir + "sideroad.schematic", + files.add(new FileBytes(newDir + "sideroad.schem", Files.readAllBytes(sideroad.toPath()))); } File intersection = - MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "intersection.schematic"); + MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "intersection.schem"); if (intersection.exists()) { - files.add(new FileBytes(newDir + "intersection.schematic", + files.add(new FileBytes(newDir + "intersection.schem", Files.readAllBytes(intersection.toPath()))); } File plot = - MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "plot.schematic"); + MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "plot.schem"); if (plot.exists()) { files.add( - new FileBytes(newDir + "plot.schematic", Files.readAllBytes(plot.toPath()))); + new FileBytes(newDir + "plot.schem", Files.readAllBytes(plot.toPath()))); } } catch (IOException e) { e.printStackTrace(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotWorld.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotWorld.java index 63b4e0c16..7c619f052 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotWorld.java @@ -131,15 +131,16 @@ public class HybridPlotWorld extends ClassicPlotWorld { public void setupSchematics() throws SchematicHandler.UnsupportedFormatException { this.G_SCH = new HashMap<>(); - File schematic1File = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), - "schematics/GEN_ROAD_SCHEMATIC/" + this.worldname + "/sideroad.schematic"); - File schematic2File = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), - "schematics/GEN_ROAD_SCHEMATIC/" + this.worldname + "/intersection.schematic"); - File schem3File = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), - "schematics/GEN_ROAD_SCHEMATIC/" + this.worldname + "/plot.schematic"); + File root = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "schematics/GEN_ROAD_SCHEMATIC/" + this.worldname); + File schematic1File = new File(root, "sideroad.schem"); + if (!schematic1File.exists()) schematic1File = new File(root, "sideroad.schematic"); + File schematic2File = new File(root, "intersection.schem"); + if (!schematic2File.exists()) schematic2File = new File(root, "intersection.schematic"); + File schematic3File = new File(root, "plot.schem"); + if (!schematic3File.exists()) schematic3File = new File(root, "plot.schematic"); Schematic schematic1 = SchematicHandler.manager.getSchematic(schematic1File); Schematic schematic2 = SchematicHandler.manager.getSchematic(schematic2File); - Schematic schematic3 = SchematicHandler.manager.getSchematic(schem3File); + Schematic schematic3 = SchematicHandler.manager.getSchematic(schematic3File); int shift = this.ROAD_WIDTH / 2; int oddshift = (this.ROAD_WIDTH & 1) == 0 ? 0 : 1; int minY = Math.min(PLOT_HEIGHT, ROAD_HEIGHT); @@ -169,10 +170,11 @@ public class HybridPlotWorld extends ClassicPlotWorld { int startY = minY - PLOT_HEIGHT; + BlockVector3 min = blockArrayClipboard3.getMinimumPoint(); for (short x = 0; x < w3; x++) { for (short z = 0; z < l3; z++) { for (short y = 0; y < h3; y++) { - BaseBlock id = blockArrayClipboard3.getFullBlock(BlockVector3.at(x, y, z)); + BaseBlock id = blockArrayClipboard3.getFullBlock(BlockVector3.at(x + min.getBlockX(), y + min.getBlockY(), z + min.getBlockZ())); if (!id.getBlockType().getMaterial().isAir()) { addOverlayBlock((short) (x + shift + oddshift + centerShiftX), (short) (y + startY), (short) (z + shift + oddshift + centerShiftZ), @@ -233,10 +235,11 @@ public class HybridPlotWorld extends ClassicPlotWorld { short l2 = (short) d2.getZ(); short h2 = (short) d2.getY(); int startY = minY - ROAD_HEIGHT; - for (short x = 0; x < w1; x++) { - for (short z = 0; z < l1; z++) { - for (short y = 0; y < h1; y++) { - BaseBlock id = blockArrayClipboard1.getFullBlock(BlockVector3.at(x, y, z)); + BlockVector3 min = blockArrayClipboard2.getMinimumPoint(); + for (short x = 0; x < w2; x++) { + for (short z = 0; z < l2; z++) { + for (short y = 0; y < h2; y++) { + BaseBlock id = blockArrayClipboard2.getFullBlock(BlockVector3.at(x + min.getBlockX(), y + min.getBlockY(), z + min.getBlockZ())); if (!id.getBlockType().getMaterial().isAir()) { addOverlayBlock((short) (x - shift), (short) (y + startY), (short) (z + shift + oddshift), id, false, h1); @@ -246,10 +249,11 @@ public class HybridPlotWorld extends ClassicPlotWorld { } } } + min = blockArrayClipboard2.getMinimumPoint(); for (short x = 0; x < w2; x++) { for (short z = 0; z < l2; z++) { for (short y = 0; y < h2; y++) { - BaseBlock id = blockArrayClipboard2.getFullBlock(BlockVector3.at(x, y, z)); + BaseBlock id = blockArrayClipboard2.getFullBlock(BlockVector3.at(x + min.getBlockX(), y + min.getBlockY(), z + min.getBlockZ())); if (!id.getBlockType().getMaterial().isAir()) { addOverlayBlock((short) (x - shift), (short) (y + startY), (short) (z - shift), id, false, h2); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java index 9b1018dbb..7214f409c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridUtils.java @@ -238,13 +238,14 @@ public abstract class HybridUtils { final String dir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.getArea() .toString() + File.separator; + SchematicHandler.manager.getCompoundTag(world, sideRoad, new RunnableVal() { @Override public void run(CompoundTag value) { - SchematicHandler.manager.save(value, dir + "sideroad.schematic"); + SchematicHandler.manager.save(value, dir + "sideroad.schem"); SchematicHandler.manager .getCompoundTag(world, intersection, new RunnableVal() { @Override public void run(CompoundTag value) { - SchematicHandler.manager.save(value, dir + "intersection.schematic"); + SchematicHandler.manager.save(value, dir + "intersection.schem"); plotworld.ROAD_SCHEMATIC_ENABLED = true; try { plotworld.setupSchematics(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index 674528395..5f8a3df0e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -1882,7 +1882,7 @@ public class Plot { String name = Plot.this.id + "," + Plot.this.area + ',' + MainUtil .getName(Plot.this.owner); boolean result = SchematicHandler.manager.save(value, - Settings.Paths.SCHEMATICS + File.separator + name + ".schematic"); + Settings.Paths.SCHEMATICS + File.separator + name + ".schem"); if (whenDone != null) { whenDone.value = result; TaskManager.runTask(whenDone); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java index 38869c2ee..522e45fa5 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/SchematicHandler.java @@ -80,7 +80,7 @@ public abstract class SchematicHandler { TaskManager.runTaskAsync(() -> { MainUtil.sendMessage(null, "&6ID: " + plot.getId()); boolean result = SchematicHandler.manager - .save(value, directory + File.separator + name + ".schematic"); + .save(value, directory + File.separator + name + ".schem"); if (!result) { MainUtil .sendMessage(null, "&7 - Failed to save &c" + plot.getId()); @@ -250,10 +250,13 @@ public abstract class SchematicHandler { throw new RuntimeException("Could not create schematic parent directory"); } } - File file = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), - Settings.Paths.SCHEMATICS + File.separator + name + (name.endsWith(".schem") ? - "" : - ".schematic")); + if (!name.endsWith(".schem") && !name.endsWith(".schematic")) { + name = name + ".schem"; + } + File file = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), Settings.Paths.SCHEMATICS + File.separator + name); + if (!file.exists()) { + file = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), Settings.Paths.SCHEMATICS + File.separator + name + "atic"); + } return getSchematic(file); } @@ -267,7 +270,7 @@ public abstract class SchematicHandler { MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), Settings.Paths.SCHEMATICS); final List names = new ArrayList<>(); if (parent.exists()) { - final String[] rawNames = parent.list((dir, name) -> name.endsWith(".schematic")); + final String[] rawNames = parent.list((dir, name) -> name.endsWith(".schematic") || name.endsWith(".schem")); if (rawNames != null) { final List transformed = Arrays.stream(rawNames) .map(rawName -> rawName.substring(0, rawName.length() - 10)) From b1835f099869b60058df85a8e363e303e014c67f Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 1 Apr 2019 21:45:55 +1100 Subject: [PATCH 2/2] whoops, wrong schematic --- .../plotsquared/plot/generator/HybridPlotWorld.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotWorld.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotWorld.java index 7c619f052..8ee998111 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridPlotWorld.java @@ -249,11 +249,11 @@ public class HybridPlotWorld extends ClassicPlotWorld { } } } - min = blockArrayClipboard2.getMinimumPoint(); + min = blockArrayClipboard1.getMinimumPoint(); for (short x = 0; x < w2; x++) { for (short z = 0; z < l2; z++) { for (short y = 0; y < h2; y++) { - BaseBlock id = blockArrayClipboard2.getFullBlock(BlockVector3.at(x + min.getBlockX(), y + min.getBlockY(), z + min.getBlockZ())); + BaseBlock id = blockArrayClipboard1.getFullBlock(BlockVector3.at(x + min.getBlockX(), y + min.getBlockY(), z + min.getBlockZ())); if (!id.getBlockType().getMaterial().isAir()) { addOverlayBlock((short) (x - shift), (short) (y + startY), (short) (z - shift), id, false, h2);