From f93ad596c6723074c49ffc44ccdb210b0c811345 Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 31 Jul 2024 21:08:06 +0200 Subject: [PATCH] fix: correctly resolve file if extension is given (#2857) * fix: correctly resolve file if extension is given * Adjust error if ClipboardFormats#findByFile null --- .../java/com/fastasyncworldedit/core/util/MainUtil.java | 6 ++++++ .../java/com/sk89q/worldedit/command/SchematicCommands.java | 6 +++++- .../worldedit/extent/clipboard/io/ClipboardFormats.java | 1 - 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/MainUtil.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/MainUtil.java index 83f951c13..0c323e47b 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/MainUtil.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/MainUtil.java @@ -712,6 +712,12 @@ public class MainUtil { return file; } } + if (filename.matches(".*\\.[\\w].*")) { + File file = MainUtil.resolveRelative(new File(dir, filename)); + if (file.exists()) { + return file; + } + } for (ClipboardFormat f : ClipboardFormats.getAll()) { File file = MainUtil.resolveRelative(new File(dir, filename + "." + f.getPrimaryFileExtension())); if (file.exists()) { 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 2d75b65b8..615702a19 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 @@ -401,7 +401,11 @@ public class SchematicCommands { if (format == null) { format = ClipboardFormats.findByFile(file); if (format == null) { - actor.print(Caption.of("worldedit.schematic.unknown-format", TextComponent.of(formatName))); + if (noExplicitFormat) { + actor.print(Caption.of("fawe.worldedit.schematic.schematic.load-failure", TextComponent.of(file.getName()))); + } else { + actor.print(Caption.of("worldedit.schematic.unknown-format", TextComponent.of(formatName))); + } return; } } 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 786af54fa..801baa187 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 @@ -208,7 +208,6 @@ public class ClipboardFormats { } } return null; - } public static MultiClipboardHolder loadAllFromInput(