private static boolean applyFormat(final TextComponent.@NonNull Builder builder, final @NonNull TextFormat format) { if(format instanceof TextColor) { builder.colorIfAbsent((TextColor) format); return true; } else if(format instanceof TextDecoration) { builder.decoration((TextDecoration) format, TextDecoration.State.TRUE); return false; } else if(format instanceof Reset) { builder.colorIfAbsent(null); for(final TextDecoration decoration : DECORATIONS) { builder.decoration(decoration, TextDecoration.State.NOT_SET); } return true; } throw new IllegalArgumentException(String.format("unknown format '%s'", format.getClass())); }
private static boolean applyFormat(final TextComponent.@NonNull Builder builder, final @NonNull TextFormat format) { if(format instanceof TextColor) { builder.colorIfAbsent((TextColor) format); return true; } else if(format instanceof TextDecoration) { builder.decoration((TextDecoration) format, TextDecoration.State.TRUE); return false; } else if(format instanceof Reset) { builder.colorIfAbsent(null); for(final TextDecoration decoration : DECORATIONS) { builder.decoration(decoration, TextDecoration.State.NOT_SET); } return true; } throw new IllegalArgumentException(String.format("unknown format '%s'", format.getClass())); }
.decoration(TextDecoration.BOLD, true) .color(TextColor.DARK_AQUA) .append(TextComponent.of(version.getVersion()).decoration(TextDecoration.BOLD, false))
@Test void testToLegacy() { final TextComponent c1 = TextComponent.builder("hi") .decoration(TextDecoration.BOLD, TextDecoration.State.TRUE) .append( TextComponent.of("foo") .decoration(TextDecoration.BOLD, true) .append( TextComponent.builder()
@Test void testToLegacy() { final TextComponent c1 = TextComponent.builder("hi") .decoration(TextDecoration.BOLD, TextDecoration.State.TRUE) .append( TextComponent.of("foo") .decoration(TextDecoration.BOLD, TextDecoration.State.TRUE) .append( TextComponent.of("you")
@Test void testSerializeDeserialize() { final TextComponent expected = TextComponent.builder() .content("Hello!") .color(TextColor.DARK_PURPLE) .decoration(TextDecoration.BOLD, TextDecoration.State.TRUE) .clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://google.com/")) .hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.builder().content(":o").color(TextColor.DARK_AQUA).build())) .build(); final String json = GsonComponentSerializer.INSTANCE.serialize(expected); assertEquals(expected, GsonComponentSerializer.INSTANCE.deserialize(json)); }