From 99ffcf6d1dd12ba978187596fd8ecd481c39e9d6 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 10 Dec 2017 11:43:47 +1300 Subject: [PATCH] Use custom string splitter --- .../disguise/utilities/DisguiseParser.java | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java index c5c2e4f6..930d68db 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java @@ -17,6 +17,7 @@ import org.bukkit.potion.PotionEffectType; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Map.Entry; @@ -439,7 +440,41 @@ public class DisguiseParser { * Splits a string while respecting quotes */ public static String[] split(String string) { - return ChatColor.translateAlternateColorCodes('&', string).split(" (?=\")|(?<=\")\\s"); + String[] strings = ChatColor.translateAlternateColorCodes('&', string).split(" "); + + ArrayList list = new ArrayList<>(); + StringBuilder builder = new StringBuilder(); + + for (String s : strings) { + String a = s.replaceAll("\\\\", ""); + + if (builder.length() != 0 || s.startsWith("\"")) { + if (builder.length() != 0) + builder.append(' '); + + String append; + + if (s.startsWith("\"")) + builder.append(s.substring(1)); + else if (a.endsWith("\"") && !a.endsWith("\\\"")) + builder.append(s.substring(0, s.length() - 1)); + else + builder.append(s); + + if (a.endsWith("\"") && !a.endsWith("\\\"")) { + list.add(builder.toString()); + builder = new StringBuilder(); + } + } else { + list.add(s); + } + } + + if (builder.length() != 0) { + list.addAll(Arrays.asList(builder.toString().split(" "))); + } + + return list.toArray(new String[list.size()]); } /**