use of com.viaversion.viaversion.libs.kyori.adventure.text.Component in project ViaBackwards by ViaVersion.
the class TranslatableRewriter1_16 method processText.
@Override
public void processText(JsonElement value) {
super.processText(value);
if (value == null || !value.isJsonObject())
return;
// c o l o r s
JsonObject object = value.getAsJsonObject();
JsonPrimitive color = object.getAsJsonPrimitive("color");
if (color != null) {
String colorName = color.getAsString();
if (!colorName.isEmpty() && colorName.charAt(0) == '#') {
int rgb = Integer.parseInt(colorName.substring(1), 16);
String closestChatColor = getClosestChatColor(rgb);
object.addProperty("color", closestChatColor);
}
}
JsonObject hoverEvent = object.getAsJsonObject("hoverEvent");
if (hoverEvent != null) {
// Let adventure handle all of that
try {
Component component = ChatRewriter.HOVER_GSON_SERIALIZER.deserializeFromTree(object);
JsonObject processedHoverEvent = ((JsonObject) ChatRewriter.HOVER_GSON_SERIALIZER.serializeToTree(component)).getAsJsonObject("hoverEvent");
// Remove new format
processedHoverEvent.remove("contents");
object.add("hoverEvent", processedHoverEvent);
} catch (Exception e) {
ViaBackwards.getPlatform().getLogger().severe("Error converting hover event component: " + object);
e.printStackTrace();
}
}
}
Aggregations