From 96e2b6c5af6861f0d57c2dc0bee799bb7a981c17 Mon Sep 17 00:00:00 2001 From: wizjany Date: Thu, 4 Jul 2019 01:48:55 -0400 Subject: [PATCH] First attempt at fixing quoted string oddities. --- .../extension/factory/MaskFactory.java | 11 +++++++++ .../internal/command/CommandArgParser.java | 24 ++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java index 73df7a52d..b4845f35e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java @@ -42,6 +42,7 @@ import com.sk89q.worldedit.internal.registry.InputParser; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * A registry of known {@link Mask}s. Provides methods to instantiate @@ -74,6 +75,16 @@ public final class MaskFactory extends AbstractFactory { register(new BiomeMaskParser(worldEdit)); } + @Override + public List getSuggestions(String input) { + final String[] split = input.split(" "); + if (split.length > 1) { + String prev = input.substring(0, input.lastIndexOf(" ")) + " "; + return super.getSuggestions(split[split.length -1]).stream().map(s -> prev + s).collect(Collectors.toList()); + } + return super.getSuggestions(input); + } + @Override public Mask parseFromInput(String input, ParserContext context) throws InputParseException { List masks = new ArrayList<>(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandArgParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandArgParser.java index c7ce23311..156563bbb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandArgParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandArgParser.java @@ -67,16 +67,28 @@ public class CommandArgParser { handleQuote(nextPart); } } + if (currentArg.size() > 0) { + finishArg(); // force finish "hanging" args + } return args.build(); } private void handleNormal(Substring part) { - if (part.getSubstring().startsWith("\"")) { - state = State.QUOTE; - currentArg.add(Substring.wrap( - part.getSubstring().substring(1), - part.getStart(), part.getEnd() - )); + final String strPart = part.getSubstring(); + if (strPart.startsWith("\"")) { + if (strPart.endsWith("\"") && strPart.length() > 1) { + currentArg.add(Substring.wrap( + strPart.substring(1, strPart.length() - 1), + part.getStart(), part.getEnd() + )); + finishArg(); + } else { + state = State.QUOTE; + currentArg.add(Substring.wrap( + strPart.substring(1), + part.getStart(), part.getEnd() + )); + } } else { currentArg.add(part); finishArg();