protected AbstractBuilder(final @NonNull C component) { this.children = new ArrayList<>(component.children()); this.color = component.color(); this.obfuscated = component.decoration(TextDecoration.OBFUSCATED); this.bold = component.decoration(TextDecoration.BOLD); this.strikethrough = component.decoration(TextDecoration.STRIKETHROUGH); this.underlined = component.decoration(TextDecoration.UNDERLINED); this.italic = component.decoration(TextDecoration.ITALIC); this.clickEvent = Optional.ofNullable(component.clickEvent()).map(ClickEvent::copy).orElse(null); this.hoverEvent = Optional.ofNullable(component.hoverEvent()).map(HoverEvent::copy).orElse(null); this.insertion = component.insertion(); }
protected AbstractBuilder(final @NonNull C component) { this.children = new ArrayList<>(component.children()); this.color = component.color(); this.obfuscated = component.decoration(TextDecoration.OBFUSCATED); this.bold = component.decoration(TextDecoration.BOLD); this.strikethrough = component.decoration(TextDecoration.STRIKETHROUGH); this.underlined = component.decoration(TextDecoration.UNDERLINED); this.italic = component.decoration(TextDecoration.ITALIC); this.clickEvent = Optional.ofNullable(component.clickEvent()).map(ClickEvent::copy).orElse(null); this.hoverEvent = Optional.ofNullable(component.hoverEvent()).map(HoverEvent::copy).orElse(null); this.insertion = component.insertion(); }
protected AbstractBuilder(final @NonNull C component) { this.children = new ArrayList<>(component.children()); this.color = component.color(); this.obfuscated = component.decoration(TextDecoration.OBFUSCATED); this.bold = component.decoration(TextDecoration.BOLD); this.strikethrough = component.decoration(TextDecoration.STRIKETHROUGH); this.underlined = component.decoration(TextDecoration.UNDERLINE); this.italic = component.decoration(TextDecoration.ITALIC); this.clickEvent = Optional.ofNullable(component.clickEvent()).map(ClickEvent::copy).orElse(null); this.hoverEvent = Optional.ofNullable(component.hoverEvent()).map(HoverEvent::copy).orElse(null); this.insertion = component.insertion(); }
@Test void testClickEvent() { final C c0 = this.builder().build(); assertNull(c0.clickEvent()); final C c1 = (C) c0.clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "foo")); assertNotNull(c1.clickEvent()); assertEquals(c0, c1.clickEvent(null)); }
@Test void testMergeEvents() { final C c0 = this.builder().build(); assertNull(c0.color()); assertDecorations(c0, ImmutableMap.of()); assertNull(c0.clickEvent()); final C c1 = (C) c0.mergeEvents(TextComponent.of("xyz", TextColor.RED, ImmutableSet.of(TextDecoration.BOLD)).clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/foo"))); assertNull(c1.color()); assertDecorations(c1, ImmutableMap.of()); assertNotNull(c1.clickEvent()); }
@Test void testMergeColor() { final C c0 = this.builder().build(); assertNull(c0.color()); assertDecorations(c0, ImmutableMap.of()); assertNull(c0.clickEvent()); final C c1 = (C) c0.mergeColor(TextComponent.of("xyz", TextColor.RED, ImmutableSet.of(TextDecoration.BOLD)).clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/foo"))); assertEquals(TextColor.RED, c1.color()); assertDecorations(c1, ImmutableMap.of()); assertNull(c1.clickEvent()); assertEquals(c0, c1.color(null)); }
@Test void testMergeDecorations() { final C c0 = this.builder().build(); assertNull(c0.color()); assertDecorations(c0, ImmutableMap.of()); assertNull(c0.clickEvent()); final C c1 = (C) c0.mergeDecorations(TextComponent.of("xyz", TextColor.RED, ImmutableSet.of(TextDecoration.BOLD)).clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/foo"))); assertNull(c1.color()); assertDecorations(c1, ImmutableMap.of(TextDecoration.BOLD, TextDecoration.State.TRUE)); assertNull(c1.clickEvent()); assertEquals(c0, c1.decoration(TextDecoration.BOLD, TextDecoration.State.NOT_SET)); }
@Test void testMergeStyle() { final C c0 = this.builder().build(); assertNull(c0.color()); assertDecorations(c0, ImmutableMap.of()); assertNull(c0.clickEvent()); final C c1 = (C) c0.mergeStyle(TextComponent.of("xyz", TextColor.RED, ImmutableSet.of(TextDecoration.BOLD)).clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/foo"))); assertEquals(TextColor.RED, c1.color()); assertDecorations(c1, ImmutableMap.of(TextDecoration.BOLD, TextDecoration.State.TRUE)); assertNotNull(c1.clickEvent()); assertEquals(c0, c1.color(null).decoration(TextDecoration.BOLD, TextDecoration.State.NOT_SET).clickEvent(null)); }
@Test void testResetStyle() { final C c0 = this.builder() .color(TextColor.RED) .decoration(TextDecoration.BOLD, true) .clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/foo")) .build(); final C c1 = (C) c0.resetStyle(); assertNull(c1.color()); assertDecorations(c1, ImmutableMap.of()); assertNull(c1.clickEvent()); assertEquals(c1, c0.color(null).decoration(TextDecoration.BOLD, TextDecoration.State.NOT_SET).clickEvent(null)); }