From 7a9adacc32a5db70d0860a6dabae1809fdc0a623 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 29 Jun 2019 01:42:22 +1000 Subject: [PATCH] Don't read the entire file to check the format --- .../clipboard/io/BuiltInClipboardFormat.java | 41 +++---------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java index 336243914..3d646866d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java @@ -71,27 +71,13 @@ public enum BuiltInClipboardFormat implements ClipboardFormat { @Override public ClipboardWriter getWriter(OutputStream outputStream) throws IOException { - throw new IOException("This format does not support saving, use `schem` as format"); + throw new IOException("This format does not support saving, use `.schem` as format"); } @Override public boolean isFormat(File file) { - try (NBTInputStream str = new NBTInputStream(new GZIPInputStream(new FileInputStream(file)))) { - NamedTag rootTag = str.readNamedTag(); - if (!rootTag.getName().equals("Schematic")) { - return false; - } - CompoundTag schematicTag = (CompoundTag) rootTag.getTag(); - - // Check - Map schematic = schematicTag.getValue(); - if (!schematic.containsKey("Materials")) { - return false; - } - } catch (Exception e) { - return false; - } - return true; + String name = file.getName().toLowerCase(); + return name.endsWith(".schematic") || name.endsWith(".mcedit") || name.endsWith(".mce"); } }, SPONGE_SCHEMATIC("sponge", "schem") { @@ -126,23 +112,8 @@ public enum BuiltInClipboardFormat implements ClipboardFormat { @Override public boolean isFormat(File file) { - try (NBTInputStream str = new NBTInputStream(new GZIPInputStream(new FileInputStream(file)))) { - NamedTag rootTag = str.readNamedTag(); - if (!rootTag.getName().equals("Schematic")) { - return false; - } - CompoundTag schematicTag = (CompoundTag) rootTag.getTag(); - - // Check - Map schematic = schematicTag.getValue(); - if (!schematic.containsKey("Version")) { - return false; - } - } catch (Exception e) { - return false; - } - - return true; + String name = file.getName().toLowerCase(); + return name.endsWith(".schem") || name.endsWith(".sponge"); } }, @@ -174,7 +145,7 @@ public enum BuiltInClipboardFormat implements ClipboardFormat { @Override public boolean isFormat(File file) { - return file.getName().endsWith(".nbt"); + return file.getName().toLowerCase().endsWith(".nbt"); } @Override