use of org.lanternpowered.server.text.LanternTextHelper.RawAction in project LanternServer by LanternPowered.
the class JsonTextBaseSerializer method serialize.
public static void serialize(JsonObject json, Text text, JsonSerializationContext context, List<Text> children) {
final TextColor color = text.getColor();
if (color != TextColors.NONE) {
json.addProperty(COLOR, color.getId());
}
final TextStyle style = text.getStyle();
style.isBold().ifPresent(v -> json.addProperty(BOLD, v));
style.isItalic().ifPresent(v -> json.addProperty(ITALIC, v));
style.hasUnderline().ifPresent(v -> json.addProperty(UNDERLINE, v));
style.hasStrikethrough().ifPresent(v -> json.addProperty(STRIKETHROUGH, v));
style.isObfuscated().ifPresent(v -> json.addProperty(OBFUSCATED, v));
if (!children.isEmpty()) {
json.add(CHILDREN, context.serialize(children.toArray(new Text[children.size()]), Text[].class));
}
text.getClickAction().ifPresent(clickAction -> {
final RawAction raw = LanternTextHelper.raw(clickAction);
final JsonObject jsonEvent = new JsonObject();
jsonEvent.addProperty(EVENT_ACTION, raw.getAction());
jsonEvent.addProperty(EVENT_VALUE, raw.getValueAsString());
json.add(CLICK_EVENT, jsonEvent);
});
text.getHoverAction().ifPresent(clickAction -> {
final RawAction raw = LanternTextHelper.raw(clickAction);
final JsonObject jsonEvent = new JsonObject();
jsonEvent.addProperty(EVENT_ACTION, raw.getAction());
jsonEvent.addProperty(EVENT_VALUE, raw.getValueAsString());
json.add(HOVER_EVENT, jsonEvent);
});
text.getShiftClickAction().ifPresent(shiftClickAction -> {
if (shiftClickAction instanceof ShiftClickAction.InsertText) {
json.addProperty(INSERTION, ((ShiftClickAction.InsertText) shiftClickAction).getResult());
}
});
}
Aggregations