From 4175decc24cc201a3686db3505f3f18aa0957b2a Mon Sep 17 00:00:00 2001 From: LeonTG Date: Sun, 21 Jan 2024 23:01:33 +0100 Subject: [PATCH] Fix missing handling of text components in 1.11.1>1.12 chat item rewriter --- .../protocol1_12to1_11_1/ChatItemRewriter.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/ChatItemRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/ChatItemRewriter.java index bb1c7426a..aa34790fc 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/ChatItemRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/ChatItemRewriter.java @@ -42,6 +42,15 @@ public static void toClient(JsonElement element, UserConnection user) { if (value.isJsonPrimitive() && value.getAsJsonPrimitive().isString()) { String newValue = indexRemoval.matcher(value.getAsString()).replaceAll(""); hoverEvent.addProperty("value", newValue); + } else if (value.isJsonObject() && value.getAsJsonObject().has("text")) { + JsonObject newObject = (JsonObject) value; + JsonElement textElement = newObject.get("text"); + + if (textElement.isJsonPrimitive() && textElement.getAsJsonPrimitive().isString()) { + String newValue = indexRemoval.matcher(textElement.getAsString()).replaceAll(""); + newObject.addProperty("text", newValue); + hoverEvent.add("value", newObject); + } } else if (value.isJsonArray()) { JsonArray newArray = new JsonArray(); @@ -49,6 +58,15 @@ public static void toClient(JsonElement element, UserConnection user) { if (valueElement.isJsonPrimitive() && valueElement.getAsJsonPrimitive().isString()) { String newValue = indexRemoval.matcher(valueElement.getAsString()).replaceAll(""); newArray.add(new JsonPrimitive(newValue)); + } else if (valueElement.isJsonObject() && valueElement.getAsJsonObject().has("text")) { + JsonObject newObject = (JsonObject) valueElement; + JsonElement textElement = newObject.get("text"); + + if (textElement.isJsonPrimitive() && textElement.getAsJsonPrimitive().isString()) { + String newValue = indexRemoval.matcher(textElement.getAsString()).replaceAll(""); + newObject.addProperty("text", newValue); + newArray.add(newObject); + } } }