From f4059943462d2526151a4895ef8de88b1f6f9c5e Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sun, 19 Sep 2021 20:47:40 +0100 Subject: [PATCH] Improve fullycopy pattern parsing - Don't attempt ClipboardFormats#loadAllFromInput if the user is typing #copy or #clipboard to avoid needless "File dialogs are not supported in your environment." message --- .../RandomFullClipboardPatternParser.java | 64 +++++++++++-------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/pattern/RandomFullClipboardPatternParser.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/pattern/RandomFullClipboardPatternParser.java index 02fae5e93..ff5d8471b 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/pattern/RandomFullClipboardPatternParser.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/factory/parser/pattern/RandomFullClipboardPatternParser.java @@ -18,6 +18,7 @@ import javax.annotation.Nonnull; import java.io.IOException; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.stream.Stream; public class RandomFullClipboardPatternParser extends RichParser { @@ -34,6 +35,16 @@ public class RandomFullClipboardPatternParser extends RichParser { @Override protected Stream getSuggestions(String argumentInput, int index) { switch (index) { + case 0: + if (argumentInput.equals("#") || argumentInput.equals("#c")) { + return Stream.of("#copy", "#clipboard"); + } else if ("#copy".startsWith(argumentInput.toUpperCase(Locale.ROOT))) { + return Stream.of("#copy"); + } else if ("#clipboard".startsWith(argumentInput.toUpperCase(Locale.ROOT))) { + return Stream.of("#clipboard"); + } else { + return Stream.empty(); + } case 1: case 2: return SuggestionHelper.suggestBoolean(argumentInput); @@ -54,35 +65,32 @@ public class RandomFullClipboardPatternParser extends RichParser { boolean rotate = arguments.length >= 2 && Boolean.getBoolean(arguments[1]); boolean flip = arguments.length == 3 && Boolean.getBoolean(arguments[2]); List clipboards; - switch (arguments[0].toLowerCase()) { - case "#copy": - case "#clipboard": - ClipboardHolder clipboard = context.requireSession().getExistingClipboard(); - if (clipboard == null) { - throw new InputParseException(Caption.of("fawe.error.parse.no-clipboard", getPrefix())); - } - clipboards = Collections.singletonList(clipboard); - break; - default: - Actor player = context.requireActor(); - MultiClipboardHolder multi = ClipboardFormats.loadAllFromInput(player, - arguments[0], ClipboardFormats.findByAlias("fast"), false + if ("#copy".startsWith(arguments[0].toUpperCase(Locale.ROOT)) || + "#clipboard".startsWith(arguments[0].toUpperCase(Locale.ROOT))) { + ClipboardHolder clipboard = context.requireSession().getExistingClipboard(); + if (clipboard == null) { + throw new InputParseException(Caption.of("fawe.error.parse.no-clipboard", getPrefix())); + } + clipboards = Collections.singletonList(clipboard); + } else { + Actor player = context.requireActor(); + MultiClipboardHolder multi = ClipboardFormats.loadAllFromInput(player, + arguments[0], ClipboardFormats.findByAlias("fast"), false + ); + if (multi == null) { + multi = ClipboardFormats.loadAllFromInput(player, + arguments[0], ClipboardFormats.findByAlias("mcedit"), false ); - if (multi == null) { - multi = ClipboardFormats.loadAllFromInput(player, - arguments[0], ClipboardFormats.findByAlias("mcedit"), false - ); - } - if (multi == null) { - multi = ClipboardFormats.loadAllFromInput(player, - arguments[0], ClipboardFormats.findByAlias("sponge"), false - ); - } - if (multi == null) { - throw new InputParseException(Caption.of("fawe.error.parse.no-clipboard-source", arguments[0])); - } - clipboards = multi.getHolders(); - break; + } + if (multi == null) { + multi = ClipboardFormats.loadAllFromInput(player, + arguments[0], ClipboardFormats.findByAlias("sponge"), false + ); + } + if (multi == null) { + throw new InputParseException(Caption.of("fawe.error.parse.no-clipboard-source", arguments[0])); + } + clipboards = multi.getHolders(); } return new RandomFullClipboardPattern(clipboards, rotate, flip); } catch (IOException e) {