From 287be0209c0f1ca4c3cd13dff46c58f674283fe7 Mon Sep 17 00:00:00 2001 From: wizjany Date: Tue, 12 Feb 2019 08:46:31 -0500 Subject: [PATCH] Slight readability and usability improvements. Also no longer allows trailing strings (e.g. //set #clipboardasdf). --- .../pattern/ClipboardPatternParser.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/ClipboardPatternParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/ClipboardPatternParser.java index 1d88aefa6..1df80b8d1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/ClipboardPatternParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/ClipboardPatternParser.java @@ -47,26 +47,22 @@ public class ClipboardPatternParser extends InputParser { @Override public Pattern parseFromInput(String input, ParserContext context) throws InputParseException { - if (!input.startsWith("#clipboard") && !input.startsWith("#copy")) { + String[] offsetParts = input.split("@", 2); + if (!offsetParts[0].equalsIgnoreCase("#clipboard") && !offsetParts[0].equalsIgnoreCase("#copy")) { return null; } LocalSession session = context.requireSession(); - int offsetPart; BlockVector3 offset = BlockVector3.ZERO; - if ((offsetPart = input.indexOf('@')) >= 0) { - if (input.length() <= offsetPart + 1) { - throw new InputParseException("Clipboard offset coordinates not specified!"); - } - String offsetString = input.substring(offsetPart + 1); - String[] offsetCoords = offsetString.split(","); - if (offsetCoords.length != 3) { + if (offsetParts.length == 2) { + String[] offsetSplit = offsetParts[1].split(","); + if (offsetSplit.length != 3) { throw new InputParseException("Clipboard offset needs x,y,z coordinates."); } offset = BlockVector3.at( - Integer.valueOf(offsetCoords[0]), - Integer.valueOf(offsetCoords[1]), - Integer.valueOf(offsetCoords[2]) + Integer.valueOf(offsetSplit[0]), + Integer.valueOf(offsetSplit[1]), + Integer.valueOf(offsetSplit[2]) ); }