From 1a7f555add2d101e6abe0d76193b72a7474a2a89 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Sat, 18 Nov 2023 15:11:17 +0100 Subject: [PATCH] Use FastSchematicReader by default (#2478) --- .../sk89q/worldedit/command/SchematicCommands.java | 11 ++++++++--- .../extent/clipboard/io/ClipboardFormats.java | 6 ++++-- 2 files changed, 12 insertions(+), 5 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 c677734ef..1158a7847 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 @@ -313,9 +313,9 @@ public class SchematicCommands { Actor actor, LocalSession session, @Arg(desc = "File name.") String filename, - @Arg(desc = "Format name.", def = "fast") - String formatName, //FAWE start - random rotation + @Arg(desc = "Format name.", def = "") + String formatName, @Switch(name = 'r', desc = "Apply random rotation to the clipboard") boolean randomRotate //FAWE end @@ -325,6 +325,11 @@ public class SchematicCommands { //FAWE start ClipboardFormat format; InputStream in = null; + // if format is set explicitly, do not look up by extension! + boolean noExplicitFormat = formatName == null; + if (noExplicitFormat) { + formatName = "fast"; + } try { URI uri; if (formatName.startsWith("url:")) { @@ -369,7 +374,7 @@ public class SchematicCommands { actor.print(Caption.of("fawe.error.no-perm", "worldedit.schematic.load.other")); return; } - if (filename.matches(".*\\.[\\w].*")) { + if (noExplicitFormat && filename.matches(".*\\.[\\w].*")) { format = ClipboardFormats .findByExtension(filename.substring(filename.lastIndexOf('.') + 1)); } else { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java index b00c9ea5b..03cce5d80 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java @@ -26,7 +26,6 @@ import com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder; import com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder; import com.fastasyncworldedit.core.internal.io.FastByteArrayOutputStream; import com.fastasyncworldedit.core.util.MainUtil; -import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import com.google.common.io.ByteSource; @@ -51,6 +50,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Map; @@ -64,7 +64,9 @@ import static com.google.common.base.Preconditions.checkNotNull; public class ClipboardFormats { private static final Map aliasMap = new HashMap<>(); - private static final Multimap fileExtensionMap = HashMultimap.create(); + // FAWE start - keep order of ClipboardFormat entries -> prefer FAST over SPONGE_SCHEMATIC + private static final Multimap fileExtensionMap = Multimaps.newMultimap(new HashMap<>(), LinkedHashSet::new); + // FAWE end private static final List registeredFormats = new ArrayList<>(); public static void registerClipboardFormat(ClipboardFormat format) {