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
Dieser Commit ist enthalten in:
dordsor21 2021-09-19 20:47:40 +01:00
Ursprung abaa98d2a9
Commit f405994346
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B

Datei anzeigen

@ -18,6 +18,7 @@ import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.stream.Stream; import java.util.stream.Stream;
public class RandomFullClipboardPatternParser extends RichParser<Pattern> { public class RandomFullClipboardPatternParser extends RichParser<Pattern> {
@ -34,6 +35,16 @@ public class RandomFullClipboardPatternParser extends RichParser<Pattern> {
@Override @Override
protected Stream<String> getSuggestions(String argumentInput, int index) { protected Stream<String> getSuggestions(String argumentInput, int index) {
switch (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 1:
case 2: case 2:
return SuggestionHelper.suggestBoolean(argumentInput); return SuggestionHelper.suggestBoolean(argumentInput);
@ -54,35 +65,32 @@ public class RandomFullClipboardPatternParser extends RichParser<Pattern> {
boolean rotate = arguments.length >= 2 && Boolean.getBoolean(arguments[1]); boolean rotate = arguments.length >= 2 && Boolean.getBoolean(arguments[1]);
boolean flip = arguments.length == 3 && Boolean.getBoolean(arguments[2]); boolean flip = arguments.length == 3 && Boolean.getBoolean(arguments[2]);
List<ClipboardHolder> clipboards; List<ClipboardHolder> clipboards;
switch (arguments[0].toLowerCase()) { if ("#copy".startsWith(arguments[0].toUpperCase(Locale.ROOT)) ||
case "#copy": "#clipboard".startsWith(arguments[0].toUpperCase(Locale.ROOT))) {
case "#clipboard": ClipboardHolder clipboard = context.requireSession().getExistingClipboard();
ClipboardHolder clipboard = context.requireSession().getExistingClipboard(); if (clipboard == null) {
if (clipboard == null) { throw new InputParseException(Caption.of("fawe.error.parse.no-clipboard", getPrefix()));
throw new InputParseException(Caption.of("fawe.error.parse.no-clipboard", getPrefix())); }
} clipboards = Collections.singletonList(clipboard);
clipboards = Collections.singletonList(clipboard); } else {
break; Actor player = context.requireActor();
default: MultiClipboardHolder multi = ClipboardFormats.loadAllFromInput(player,
Actor player = context.requireActor(); arguments[0], ClipboardFormats.findByAlias("fast"), false
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, if (multi == null) {
arguments[0], ClipboardFormats.findByAlias("mcedit"), false multi = ClipboardFormats.loadAllFromInput(player,
); arguments[0], ClipboardFormats.findByAlias("sponge"), false
} );
if (multi == null) { }
multi = ClipboardFormats.loadAllFromInput(player, if (multi == null) {
arguments[0], ClipboardFormats.findByAlias("sponge"), false throw new InputParseException(Caption.of("fawe.error.parse.no-clipboard-source", arguments[0]));
); }
} clipboards = multi.getHolders();
if (multi == null) {
throw new InputParseException(Caption.of("fawe.error.parse.no-clipboard-source", arguments[0]));
}
clipboards = multi.getHolders();
break;
} }
return new RandomFullClipboardPattern(clipboards, rotate, flip); return new RandomFullClipboardPattern(clipboards, rotate, flip);
} catch (IOException e) { } catch (IOException e) {