From 74a2f02003a4293ca0eb508ea64abfaf8bb4e1c0 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Mon, 11 Jan 2021 16:02:50 +0000 Subject: [PATCH] put MCEdit before sponge and query by file extension. Massively reduces loading time a few addon plugins that are literally only trying to get the format of a schematic --- .../clipboard/io/BuiltInClipboardFormat.java | 70 ++++++++----------- 1 file changed, 28 insertions(+), 42 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 7d563d4ee..0cfc6f99c 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 @@ -86,6 +86,34 @@ public enum BuiltInClipboardFormat implements ClipboardFormat { }, + /** + * The Schematic format used by MCEdit. + */ + MCEDIT_SCHEMATIC("mcedit", "mce", "schematic") { + + @Override + public String getPrimaryFileExtension() { + return "schematic"; + } + + @Override + public ClipboardReader getReader(InputStream inputStream) throws IOException { + NBTInputStream nbtStream = new NBTInputStream(new GZIPInputStream(inputStream)); + return new MCEditSchematicReader(nbtStream); + } + + @Override + public ClipboardWriter getWriter(OutputStream outputStream) throws IOException { + throw new IOException("This format does not support saving"); + } + + @Override + public boolean isFormat(File file) { + String name = file.getName().toLowerCase(Locale.ROOT); + return name.endsWith(".schematic") || name.endsWith(".mcedit") || name.endsWith(".mce"); + } + }, + SPONGE_SCHEMATIC("sponge", "schem") { @Override @@ -126,48 +154,6 @@ public enum BuiltInClipboardFormat implements ClipboardFormat { } }, - /** - * The Schematic format used by MCEdit. - */ - MCEDIT_SCHEMATIC("mcedit", "mce", "schematic") { - - @Override - public String getPrimaryFileExtension() { - return "schematic"; - } - - @Override - public ClipboardReader getReader(InputStream inputStream) throws IOException { - NBTInputStream nbtStream = new NBTInputStream(new GZIPInputStream(inputStream)); - return new MCEditSchematicReader(nbtStream); - } - - @Override - public ClipboardWriter getWriter(OutputStream outputStream) throws IOException { - throw new IOException("This format does not support saving"); - } - - @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; - } - }, - BROKENENTITY("brokenentity", "legacyentity", "le", "be", "brokenentities", "legacyentities") { @Override