From aacdd77f3e9de41f48b22dc1e9e7d4d6cde11523 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Tue, 13 Sep 2011 12:02:53 +0800 Subject: [PATCH] Add support for spaces in world names via double-quotes on commands --- src/main/java/org/dynmap/DynmapPlugin.java | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index 12e7eaf6..135d55b7 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -647,6 +647,44 @@ public class DynmapPlugin extends JavaPlugin { } } + /* Parse argument strings : handle quoted strings */ + public static String[] parseArgs(String[] args, CommandSender snd) { + ArrayList rslt = new ArrayList(); + /* Build command line, so we can parse our way - make sure there is trailing space */ + String cmdline = ""; + for(int i = 0; i < args.length; i++) { + cmdline += args[i] + " "; + } + boolean inquote = false; + StringBuilder sb = new StringBuilder(); + for(int i = 0; i < cmdline.length(); i++) { + char c = cmdline.charAt(i); + if(inquote) { /* If in quote, accumulate until end or another quote */ + if(c == '\"') { /* End quote */ + inquote = false; + } + else { + sb.append(c); + } + } + else if(c == '\"') { /* Start of quote? */ + inquote = true; + } + else if(c == ' ') { /* Ending space? */ + rslt.add(sb.toString()); + sb.setLength(0); + } + else { + sb.append(c); + } + } + if(inquote) { /* If still in quote, syntax error */ + snd.sendMessage("Error: unclosed doublequote"); + return null; + } + return rslt.toArray(new String[rslt.size()]); + } + private static final Set commands = new HashSet(Arrays.asList(new String[] { "render", "hide", @@ -668,6 +706,12 @@ public class DynmapPlugin extends JavaPlugin { Player player = null; if (sender instanceof Player) player = (Player) sender; + /* Re-parse args - handle doublequotes */ + args = parseArgs(args, sender); + + if(args == null) + return false; + if (args.length > 0) { String c = args[0]; if (!commands.contains(c)) {