@Override ScoreComponent.Builder builder() { return ScoreComponent.builder("test", "test"); }
/** * Creates a score component with a name and objective. * * @param name the score name * @param objective the score objective * @return the score component */ public static ScoreComponent of(final @NonNull String name, final @NonNull String objective) { return of(name, objective, null); }
@Override public @NonNull ScoreComponent append(final @NonNull Component component) { this.detectCycle(component); // detect cycle before modifying final List<Component> children = new ArrayList<>(this.children.size() + 1); children.addAll(this.children); children.add(component); return new ScoreComponent(children, this.color, this.obfuscated, this.bold, this.strikethrough, this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); }
@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; } }
@Test void testOf() { final ScoreComponent component = ScoreComponent.of("abc", "def"); assertEquals("abc", component.name()); assertEquals("def", component.objective()); assertNull(component.color()); for(final TextDecoration decoration : TextDecoration.values()) { assertEquals(TextDecoration.State.NOT_SET, component.decoration(decoration)); } }
@Override public @NonNull ScoreComponent decoration(final @NonNull TextDecoration decoration, final TextDecoration.@NonNull State state) { switch(decoration) { case BOLD: return new ScoreComponent(this.children, this.color, this.obfuscated, requireNonNull(state, "flag"), this.strikethrough, this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); case ITALIC: return new ScoreComponent(this.children, this.color, this.obfuscated, this.bold, this.strikethrough, this.underlined, requireNonNull(state, "flag"), this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); case UNDERLINED: return new ScoreComponent(this.children, this.color, this.obfuscated, this.bold, this.strikethrough, requireNonNull(state, "flag"), this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); case STRIKETHROUGH: return new ScoreComponent(this.children, this.color, this.obfuscated, this.bold, requireNonNull(state, "flag"), this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); case OBFUSCATED: return new ScoreComponent(this.children, this.color, requireNonNull(state, "flag"), this.bold, this.strikethrough, this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); default: throw new IllegalArgumentException(String.format("unknown decoration '%s'", decoration)); } }
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); } } }
@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 ScoreComponent decoration(final @NonNull TextDecoration decoration, final TextDecoration.@NonNull State state) { switch(decoration) { case BOLD: return new ScoreComponent(this.children, this.color, this.obfuscated, checkNotNull(state, "flag"), this.strikethrough, this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); case ITALIC: return new ScoreComponent(this.children, this.color, this.obfuscated, this.bold, this.strikethrough, this.underlined, checkNotNull(state, "flag"), this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); case UNDERLINE: return new ScoreComponent(this.children, this.color, this.obfuscated, this.bold, this.strikethrough, checkNotNull(state, "flag"), this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); case STRIKETHROUGH: return new ScoreComponent(this.children, this.color, this.obfuscated, this.bold, checkNotNull(state, "flag"), this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); case OBFUSCATED: return new ScoreComponent(this.children, this.color, checkNotNull(state, "flag"), this.bold, this.strikethrough, this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); default: throw new IllegalArgumentException(String.format("unknown decoration '%s'", decoration)); } }
@Override public @NonNull ScoreComponent append(final @NonNull Component component) { this.detectCycle(component); // detect cycle before modifying final List<Component> children = new ArrayList<>(this.children.size() + 1); children.addAll(this.children); children.add(component); return new ScoreComponent(children, this.color, this.obfuscated, this.bold, this.strikethrough, this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); }
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); } } }
@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 ScoreComponent decoration(final @NonNull TextDecoration decoration, final TextDecoration.@NonNull State state) { switch(decoration) { case BOLD: return new ScoreComponent(this.children, this.color, this.obfuscated, requireNonNull(state, "flag"), this.strikethrough, this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); case ITALIC: return new ScoreComponent(this.children, this.color, this.obfuscated, this.bold, this.strikethrough, this.underlined, requireNonNull(state, "flag"), this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); case UNDERLINED: return new ScoreComponent(this.children, this.color, this.obfuscated, this.bold, this.strikethrough, requireNonNull(state, "flag"), this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); case STRIKETHROUGH: return new ScoreComponent(this.children, this.color, this.obfuscated, this.bold, requireNonNull(state, "flag"), this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); case OBFUSCATED: return new ScoreComponent(this.children, this.color, requireNonNull(state, "flag"), this.bold, this.strikethrough, this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); default: throw new IllegalArgumentException(String.format("unknown decoration '%s'", decoration)); } }
@Override public @NonNull ScoreComponent append(final @NonNull Component component) { this.detectCycle(component); // detect cycle before modifying final List<Component> children = new ArrayList<>(this.children.size() + 1); children.addAll(this.children); children.add(component); return new ScoreComponent(children, this.color, this.obfuscated, this.bold, this.strikethrough, this.underlined, this.italic, this.clickEvent, this.hoverEvent, this.insertion, this.name, this.objective, this.value); }