Builder(final @NonNull TextComponent component) { super(component); this.content = component.content(); }
Builder(final @NonNull TextComponent component) { super(component); this.content = component.content(); }
Builder(final @NonNull TextComponent component) { super(component); this.content = component.content(); }
public void serialize(final @NonNull StringBuilder sb, final @NonNull Component component) { if(component instanceof KeybindComponent) { sb.append(this.keybind.apply((KeybindComponent) component)); } else if(component instanceof ScoreComponent) { sb.append(((ScoreComponent) component).value()); } else if(component instanceof SelectorComponent) { sb.append(((SelectorComponent) component).pattern()); } else if(component instanceof TextComponent) { sb.append(((TextComponent) component).content()); } else if(component instanceof TranslatableComponent) { sb.append(this.translatable.apply((TranslatableComponent) component)); } else { throw new IllegalArgumentException("Don't know how to turn " + component + " into a string"); } for(final Component child : component.children()) { this.serialize(sb, child); } } }
public void serialize(final @NonNull StringBuilder sb, final @NonNull Component component) { if(component instanceof KeybindComponent) { sb.append(this.keybind.apply((KeybindComponent) component)); } else if(component instanceof ScoreComponent) { sb.append(((ScoreComponent) component).value()); } else if(component instanceof SelectorComponent) { sb.append(((SelectorComponent) component).pattern()); } else if(component instanceof TextComponent) { sb.append(((TextComponent) component).content()); } else if(component instanceof TranslatableComponent) { sb.append(this.translatable.apply((TranslatableComponent) component)); } else { throw new IllegalArgumentException("Don't know how to turn " + component + " into a string"); } for(final Component child : component.children()) { this.serialize(sb, child); } } }
private void append(final @NonNull Component component, final @NonNull Style style) { style.apply(component); if(component instanceof TextComponent) { final String content = ((TextComponent) component).content(); if(!content.isEmpty()) { style.applyFormat(); this.sb.append(content); } } final List<Component> children = component.children(); if(!children.isEmpty()) { final Style childrenStyle = new Style(style); for(final Component child : component.children()) { this.append(child, childrenStyle); childrenStyle.set(style); } } }
private void append(final @NonNull Component component, final @NonNull Style style) { style.apply(component); if(component instanceof TextComponent) { final String content = ((TextComponent) component).content(); if(!content.isEmpty()) { style.applyFormat(); this.sb.append(content); } } final List<Component> children = component.children(); if(!children.isEmpty()) { final Style childrenStyle = new Style(style); for(final Component child : component.children()) { this.append(child, childrenStyle); childrenStyle.set(style); } } }
final JsonObject object = new JsonObject(); if(component instanceof TextComponent) { object.addProperty("text", ((TextComponent) component).content()); } else if(component instanceof TranslatableComponent) { final TranslatableComponent tc = (TranslatableComponent) component;
final JsonObject object = new JsonObject(); if(component instanceof TextComponent) { object.addProperty("text", ((TextComponent) component).content()); } else if(component instanceof TranslatableComponent) { final TranslatableComponent tc = (TranslatableComponent) component;
@Test void testMake_content() { final TextComponent component = TextComponent.make("foo", builder -> builder.color(TextColor.DARK_PURPLE)); assertEquals("foo", component.content()); assertEquals(TextColor.DARK_PURPLE, component.color()); }
@Test void testMake() { final TextComponent component = TextComponent.make(builder -> { builder.content("foo"); builder.color(TextColor.DARK_PURPLE); }); assertEquals("foo", component.content()); assertEquals(TextColor.DARK_PURPLE, component.color()); }
@Test void testOf_color() { final TextComponent component = TextComponent.of("foo", TextColor.GREEN); assertEquals("foo", component.content()); assertEquals(TextColor.GREEN, component.color()); for(final TextDecoration decoration : TextDecoration.values()) { assertEquals(TextDecoration.State.NOT_SET, component.decoration(decoration)); } }
@Test void testOf() { final TextComponent component = TextComponent.of("foo"); assertEquals("foo", component.content()); assertNull(component.color()); for(final TextDecoration decoration : TextDecoration.values()) { assertEquals(TextDecoration.State.NOT_SET, component.decoration(decoration)); } }
@Test void testOf_color_decorations() { final TextComponent component = TextComponent.of("foo", TextColor.GREEN, ImmutableSet.of(TextDecoration.BOLD)); assertEquals("foo", component.content()); assertEquals(TextColor.GREEN, component.color()); assertEquals(TextDecoration.State.NOT_SET, component.decoration(TextDecoration.OBFUSCATED)); assertEquals(TextDecoration.State.TRUE, component.decoration(TextDecoration.BOLD)); assertEquals(TextDecoration.State.NOT_SET, component.decoration(TextDecoration.STRIKETHROUGH)); assertEquals(TextDecoration.State.NOT_SET, component.decoration(TextDecoration.UNDERLINED)); assertEquals(TextDecoration.State.NOT_SET, component.decoration(TextDecoration.ITALIC)); }
@Override public @NonNull Component render(final @NonNull Component component, final @NonNull C context) { if(component instanceof TranslatableComponent) { return this.render((TranslatableComponent) component, context); } else if(component instanceof TextComponent) { final TextComponent.Builder builder = TextComponent.builder(((TextComponent) component).content()); return this.deepRender(component, builder, context).build(); } else if(component instanceof KeybindComponent) { final KeybindComponent.Builder builder = KeybindComponent.builder(((KeybindComponent) component).keybind()); return this.deepRender(component, builder, context).build(); } else if(component instanceof ScoreComponent) { final ScoreComponent sc = (ScoreComponent) component; final ScoreComponent.Builder builder = ScoreComponent.builder() .name(sc.name()) .objective(sc.objective()) .value(sc.value()); return this.deepRender(component, builder, context).build(); } else if(component instanceof SelectorComponent) { final SelectorComponent.Builder builder = SelectorComponent.builder(((SelectorComponent) component).pattern()); return this.deepRender(component, builder, context).build(); } else { return component; } }
@Override public @NonNull Component render(final @NonNull Component component, final @NonNull C context) { if(component instanceof TranslatableComponent) { return this.render((TranslatableComponent) component, context); } else if(component instanceof TextComponent) { final TextComponent.Builder builder = TextComponent.builder(((TextComponent) component).content()); return this.deepRender(component, builder, context).build(); } else if(component instanceof KeybindComponent) { final KeybindComponent.Builder builder = KeybindComponent.builder(((KeybindComponent) component).keybind()); return this.deepRender(component, builder, context).build(); } else if(component instanceof ScoreComponent) { final ScoreComponent sc = (ScoreComponent) component; final ScoreComponent.Builder builder = ScoreComponent.builder() .name(sc.name()) .objective(sc.objective()) .value(sc.value()); return this.deepRender(component, builder, context).build(); } else if(component instanceof SelectorComponent) { final SelectorComponent.Builder builder = SelectorComponent.builder(((SelectorComponent) component).pattern()); return this.deepRender(component, builder, context).build(); } else { return component; } }
@Override public @NonNull Component render(final @NonNull Component component, final @NonNull C context) { if(component instanceof TranslatableComponent) { return this.render((TranslatableComponent) component, context); } else if(component instanceof TextComponent) { final TextComponent.Builder builder = TextComponent.builder(((TextComponent) component).content()); return this.deepRender(component, builder, context).build(); } else if(component instanceof KeybindComponent) { final KeybindComponent.Builder builder = KeybindComponent.builder(((KeybindComponent) component).keybind()); return this.deepRender(component, builder, context).build(); } else if(component instanceof ScoreComponent) { final ScoreComponent sc = (ScoreComponent) component; final ScoreComponent.Builder builder = ScoreComponent.builder() .name(sc.name()) .objective(sc.objective()) .value(sc.value()); return this.deepRender(component, builder, context).build(); } else if(component instanceof SelectorComponent) { final SelectorComponent.Builder builder = SelectorComponent.builder(((SelectorComponent) component).pattern()); return this.deepRender(component, builder, context).build(); } else { return component; } }