Search in sources :

Example 1 with ClipboardPattern

use of com.sk89q.worldedit.function.pattern.ClipboardPattern in project FastAsyncWorldEdit by IntellectualSites.

the class ClipboardPatternParser method parseFromInput.

@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
    String[] offsetParts = input.split("@", 2);
    if (!offsetParts[0].equalsIgnoreCase("#clipboard") && !offsetParts[0].equalsIgnoreCase("#copy")) {
        return null;
    }
    LocalSession session = context.requireSession();
    BlockVector3 offset = BlockVector3.ZERO;
    if (offsetParts.length == 2) {
        String coords = offsetParts[1];
        if (// min length of `[x,y,z]`
        coords.length() < 7 || coords.charAt(0) != '[' || coords.charAt(coords.length() - 1) != ']') {
            throw new InputParseException(Caption.of("worldedit.error.parser.clipboard.missing-offset"));
        }
        String[] offsetSplit = coords.substring(1, coords.length() - 1).split(",");
        if (offsetSplit.length != 3) {
            throw new InputParseException(Caption.of("worldedit.error.parser.clipboard.missing-coordinates"));
        }
        offset = BlockVector3.at(Integer.parseInt(offsetSplit[0]), Integer.parseInt(offsetSplit[1]), Integer.parseInt(offsetSplit[2]));
    }
    if (session != null) {
        try {
            ClipboardHolder holder = session.getClipboard();
            Clipboard clipboard = holder.getClipboard();
            return new ClipboardPattern(clipboard, offset);
        } catch (EmptyClipboardException e) {
            throw new InputParseException(Caption.of("worldedit.error.empty-clipboard"));
        }
    } else {
        throw new InputParseException(Caption.of("worldedit.error.missing-session"));
    }
}
Also used : InputParseException(com.sk89q.worldedit.extension.input.InputParseException) EmptyClipboardException(com.sk89q.worldedit.EmptyClipboardException) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) LocalSession(com.sk89q.worldedit.LocalSession) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockVector3(com.sk89q.worldedit.math.BlockVector3) ClipboardPattern(com.sk89q.worldedit.function.pattern.ClipboardPattern)

Aggregations

EmptyClipboardException (com.sk89q.worldedit.EmptyClipboardException)1 LocalSession (com.sk89q.worldedit.LocalSession)1 InputParseException (com.sk89q.worldedit.extension.input.InputParseException)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 ClipboardPattern (com.sk89q.worldedit.function.pattern.ClipboardPattern)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)1