Search in sources :

Example 1 with RandomFullClipboardPattern

use of com.fastasyncworldedit.core.function.pattern.RandomFullClipboardPattern in project FastAsyncWorldEdit by IntellectualSites.

the class RandomFullClipboardPatternParser method parseFromInput.

@Override
protected Pattern parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
    if (arguments.length == 0 || arguments.length > 3) {
        throw new InputParseException(Caption.of("fawe.error.command.syntax", TextComponent.of(getPrefix() + "[pattern] (e.g. " + getPrefix() + "[#copy][true][false])")));
    }
    try {
        boolean rotate = arguments.length >= 2 && Boolean.getBoolean(arguments[1]);
        boolean flip = arguments.length == 3 && Boolean.getBoolean(arguments[2]);
        List<ClipboardHolder> clipboards;
        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("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) {
        throw new InputParseException(TextComponent.of(e.getMessage()), e);
    }
}
Also used : RandomFullClipboardPattern(com.fastasyncworldedit.core.function.pattern.RandomFullClipboardPattern) InputParseException(com.sk89q.worldedit.extension.input.InputParseException) MultiClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) MultiClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder) Actor(com.sk89q.worldedit.extension.platform.Actor) IOException(java.io.IOException)

Aggregations

MultiClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder)1 RandomFullClipboardPattern (com.fastasyncworldedit.core.function.pattern.RandomFullClipboardPattern)1 InputParseException (com.sk89q.worldedit.extension.input.InputParseException)1 Actor (com.sk89q.worldedit.extension.platform.Actor)1 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)1 IOException (java.io.IOException)1