From adba89794e67ae3fecdb39a4fb73812529860e8c Mon Sep 17 00:00:00 2001 From: ORelio Date: Sat, 11 Jan 2014 16:17:48 +0100 Subject: [PATCH] Fix for text coloration - Recursive text coloration (like in MC 1.7) - Fix for color bug introduced in 7e8b750 --- MinecraftClient/ChatParser.cs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/MinecraftClient/ChatParser.cs b/MinecraftClient/ChatParser.cs index 36e9437c..9bbdb80e 100644 --- a/MinecraftClient/ChatParser.cs +++ b/MinecraftClient/ChatParser.cs @@ -21,7 +21,7 @@ namespace MinecraftClient { int cursorpos = 0; JSONData jsonData = String2Data(json, ref cursorpos); - return JSONData2String(jsonData); + return JSONData2String(jsonData, ""); } /// @@ -281,28 +281,28 @@ namespace MinecraftClient /// Use a JSON Object to build the corresponding string /// /// JSON object to convert + /// Allow parent color code to affect child elements (set to "" for function init) /// returns the Minecraft-formatted string - private static string JSONData2String(JSONData data) + private static string JSONData2String(JSONData data, string colorcode) { string extra_result = ""; - string colorcode = ""; switch (data.Type) { case JSONData.DataType.Object: + if (data.Properties.ContainsKey("color")) + { + colorcode = color2tag(JSONData2String(data.Properties["color"], "")); + } if (data.Properties.ContainsKey("extra")) { JSONData[] extras = data.Properties["extra"].DataArray.ToArray(); foreach (JSONData item in extras) - extra_result = extra_result + JSONData2String(item); - } - if (data.Properties.ContainsKey("color")) - { - colorcode = color2tag(JSONData2String(data.Properties["color"])); + extra_result = extra_result + JSONData2String(item, colorcode) + "§r"; } if (data.Properties.ContainsKey("text")) { - return colorcode + JSONData2String(data.Properties["text"]) + extra_result; + return colorcode + JSONData2String(data.Properties["text"], colorcode) + extra_result; } else if (data.Properties.ContainsKey("translate")) { @@ -314,10 +314,10 @@ namespace MinecraftClient JSONData[] array = data.Properties["with"].DataArray.ToArray(); for (int i = 0; i < array.Length; i++) { - using_data.Add(JSONData2String(array[i])); + using_data.Add(JSONData2String(array[i], colorcode)); } } - return colorcode + TranslateString(JSONData2String(data.Properties["translate"]), using_data) + extra_result; + return colorcode + TranslateString(JSONData2String(data.Properties["translate"], ""), using_data) + extra_result; } else return extra_result; @@ -325,12 +325,12 @@ namespace MinecraftClient string result = ""; foreach (JSONData item in data.DataArray) { - result += JSONData2String(item); + result += JSONData2String(item, colorcode); } return result; case JSONData.DataType.String: - return data.StringValue; + return colorcode + data.StringValue; } return "";