From d2704053d05cd47b16fa38a6635e182797c40e70 Mon Sep 17 00:00:00 2001 From: Madelyyn Date: Sun, 25 Jan 2026 20:48:52 -0600 Subject: [PATCH 1/3] Quote schematics --- .../worldedit/command/SchematicCommands.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 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 67e1e33d98..0ffeabfb37 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 @@ -145,6 +145,23 @@ private static List getFiles(File root, String filter, ClipboardFormat for return fileList; } + public static String quoteCmd(String value) { + if (value.isEmpty()) { + return "\"\""; + } + + boolean quote = value.indexOf(' ') >= 0 || value.indexOf('\t') >= 0; + if (!quote) { + return value; + } + + String escaped = value + .replace("\\", "\\\\") + .replace("\"", "\\\""); + + return "\"" + escaped + "\""; + } + @Command( name = "loadall", desc = "Load multiple clipboards (paste will randomly choose one)" @@ -770,19 +787,20 @@ public void list( List components = UtilityCommands.entryToComponent(dir, entries, isLoaded, (name, path, type, loaded) -> { TextComponentProducer msg = new TextComponentProducer(); + String pathArg = quoteCmd(path); msg.append(Caption.of("worldedit.schematic.dash.symbol")); if (loaded) { msg.append(Caption.of("worldedit.schematic.minus.symbol") - .clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, unload + " " + path)) + .clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, unload + " " + pathArg)) .hoverEvent(HoverEvent.of( HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.unload") ))); } else { msg.append(Caption.of("worldedit.schematic.plus.symbol") - .clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadMulti + " " + path)) + .clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadMulti + " " + pathArg)) .hoverEvent(HoverEvent.of( HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.clipboard") @@ -790,12 +808,12 @@ public void list( } if (type != UtilityCommands.URIType.DIRECTORY) { msg.append(Caption.of("worldedit.schematic.x.symbol") - .clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, delete + " " + path)) + .clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, delete + " " + pathArg)) .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.delete"))) ); } else if (hasShow) { msg.append(Caption.of("worldedit.schematic.0.symbol") - .clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, showCmd + " " + path)) + .clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, showCmd + " " + pathArg)) .hoverEvent(HoverEvent.of( HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.visualize") @@ -804,13 +822,13 @@ public void list( } TextComponent msgElem = TextComponent.of(name); if (type != UtilityCommands.URIType.DIRECTORY) { - msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadSingle + " " + path)); + msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadSingle + " " + pathArg)); msgElem = msgElem.hoverEvent(HoverEvent.of( HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.load") )); } else { - msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, list + " " + path)); + msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, list + " " + pathArg)); msgElem = msgElem.hoverEvent(HoverEvent.of( HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.list") From 8d6bfe8d4cf70476bcc7b3f500442fcd9d003619 Mon Sep 17 00:00:00 2001 From: Madelyyn Date: Sun, 1 Feb 2026 12:10:50 -0600 Subject: [PATCH 2/3] Move escpaing function to StringMan & rename --- .../core/util/StringMan.java | 17 ++++++++++++++++ .../worldedit/command/SchematicCommands.java | 20 ++----------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/StringMan.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/StringMan.java index 595bbdcffc..bec00fe39c 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/StringMan.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/StringMan.java @@ -542,4 +542,21 @@ public static boolean containsUuid(String str) { return UUID_PATTERN.matcher(str).find(); } + public static String escape(String value) { + if (value.isEmpty()) { + return "\"\""; + } + + boolean quote = value.indexOf(' ') >= 0 || value.indexOf('\t') >= 0; + if (!quote) { + return value; + } + + String escaped = value + .replace("\\", "\\\\") + .replace("\"", "\\\""); + + return "\"" + escaped + "\""; + } + } 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 0ffeabfb37..b4bf7f06a1 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 @@ -26,6 +26,7 @@ import com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder; import com.fastasyncworldedit.core.math.transform.MutatingOperationTransformHolder; import com.fastasyncworldedit.core.util.MainUtil; +import com.fastasyncworldedit.core.util.StringMan; import com.google.common.collect.Multimap; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; @@ -145,23 +146,6 @@ private static List getFiles(File root, String filter, ClipboardFormat for return fileList; } - public static String quoteCmd(String value) { - if (value.isEmpty()) { - return "\"\""; - } - - boolean quote = value.indexOf(' ') >= 0 || value.indexOf('\t') >= 0; - if (!quote) { - return value; - } - - String escaped = value - .replace("\\", "\\\\") - .replace("\"", "\\\""); - - return "\"" + escaped + "\""; - } - @Command( name = "loadall", desc = "Load multiple clipboards (paste will randomly choose one)" @@ -787,7 +771,7 @@ public void list( List components = UtilityCommands.entryToComponent(dir, entries, isLoaded, (name, path, type, loaded) -> { TextComponentProducer msg = new TextComponentProducer(); - String pathArg = quoteCmd(path); + String pathArg = StringMan.escape(path); msg.append(Caption.of("worldedit.schematic.dash.symbol")); From 8a4f954d40a55172873498bdf26730ba0bd223c4 Mon Sep 17 00:00:00 2001 From: Madelyyn Date: Sat, 7 Feb 2026 09:56:44 -0600 Subject: [PATCH 3/3] Remove new lines --- .../main/java/com/fastasyncworldedit/core/util/StringMan.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/StringMan.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/StringMan.java index bec00fe39c..d724f41d4c 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/StringMan.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/StringMan.java @@ -552,9 +552,7 @@ public static String escape(String value) { return value; } - String escaped = value - .replace("\\", "\\\\") - .replace("\"", "\\\""); + String escaped = value.replace("\\", "\\\\").replace("\"", "\\\""); return "\"" + escaped + "\""; }