From 3abf964620fc968a2f23dad5310b84f2dd29ce43 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Tue, 5 May 2020 16:16:27 +0100 Subject: [PATCH] Better logic for selecting schematic format. - You had to specifically use //schem load .schematic mcedit to load legacy schematics, now if you're loading .schematic it assumes you're wanting mcedit format - If you end up attempting to load an mcedit schematic with the sponge reader it now throws an exception. --- .../sk89q/worldedit/command/SchematicCommands.java | 11 +++++++---- .../extent/clipboard/io/FastSchematicReader.java | 7 +++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index 0d3e8502c..d5e4f4b49 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -201,7 +201,7 @@ public class SchematicCommands { String formatName) throws FilenameException { LocalConfiguration config = worldEdit.getConfiguration(); - ClipboardFormat format = ClipboardFormats.findByAlias(formatName); + ClipboardFormat format = null; InputStream in = null; try { URI uri; @@ -221,6 +221,7 @@ public class SchematicCommands { File dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(saveDir, actor.getUniqueId().toString()) : saveDir; File file; if (filename.startsWith("#")) { + format = ClipboardFormats.findByAlias(formatName); String[] extensions; if (format != null) { extensions = format.getFileExtensions().toArray(new String[0]); @@ -237,9 +238,11 @@ public class SchematicCommands { actor.print(Caption.of("fawe.error.no-perm", "worldedit.schematic.load.other")); return; } - if (format == null && filename.matches(".*\\.[\\w].*")) { - String extension = filename.substring(filename.lastIndexOf('.') + 1); - format = ClipboardFormats.findByExtension(extension); + if (filename.matches(".*\\.[\\w].*")) { + format = ClipboardFormats + .findByExtension(filename.substring(filename.lastIndexOf('.') + 1)); + } else { + format = ClipboardFormats.findByAlias(formatName); } file = MainUtil.resolve(dir, filename, format, false); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/FastSchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/FastSchematicReader.java index d5da9201b..3b2332fb8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/FastSchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/FastSchematicReader.java @@ -69,6 +69,7 @@ public class FastSchematicReader extends NBTSchematicReader { private final NBTInputStream inputStream; private DataFixer fixer = null; private int dataVersion = -1; + private int version = -1; private FastByteArrayOutputStream blocksOut; private FaweOutputStream blocks; @@ -119,6 +120,7 @@ public class FastSchematicReader extends NBTSchematicReader { StreamDelegate root = new StreamDelegate(); StreamDelegate schematic = root.add("Schematic"); schematic.add("DataVersion").withInt((i, v) -> dataVersion = v); + schematic.add("Version").withInt((i, v) -> version = v); schematic.add("Width").withInt((i, v) -> width = v); schematic.add("Height").withInt((i, v) -> height = v); schematic.add("Length").withInt((i, v) -> length = v); @@ -196,6 +198,11 @@ public class FastSchematicReader extends NBTSchematicReader { public Clipboard read(UUID uuid, Function createOutput) throws IOException { StreamDelegate root = createDelegate(); inputStream.readNamedTagLazy(root); + + if (version != 1 && version != 2) { + throw new IOException("This schematic version is currently not supported"); + } + if (blocks != null) blocks.close(); if (biomes != null) biomes.close(); blocks = null;