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"));
}
}
Aggregations