component = SelectorComponent.builder().pattern(object.get("selector").getAsString()); } else if(object.has("keybind")) { component = KeybindComponent.builder().keybind(object.get("keybind").getAsString()); } else { throw new JsonParseException("Don't know how to turn " + element + " into a Component");
/** * Creates a keybind component by applying configuration from {@code consumer}. * * @param keybind the keybind * @param consumer the builder configurator * @return the keybind component */ public static KeybindComponent make(final @NonNull String keybind, final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(keybind); consumer.accept(builder); return builder.build(); }
component = SelectorComponent.builder().pattern(object.get("selector").getAsString()); } else if(object.has("keybind")) { component = KeybindComponent.builder().keybind(object.get("keybind").getAsString()); } else { throw new JsonParseException("Don't know how to turn " + element + " into a 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; } }
@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 Builder toBuilder() { return new Builder(this); }
/** * Creates a keybind component with a keybind. * * @param keybind the keybind * @return the keybind component */ public static KeybindComponent of(final @NonNull String keybind) { return builder(keybind).build(); }
/** * Creates a keybind component builder. * * @return a builder */ public static Builder builder() { return new Builder(); }
@Override public @NonNull Builder toBuilder() { return new Builder(this); }
@Override public @NonNull Builder toBuilder() { return new Builder(this); }
/** * Creates a keybind component with a keybind. * * @param keybind the keybind * @return the keybind component */ public static KeybindComponent of(final @NonNull String keybind) { return builder(keybind).build(); }
/** * Creates a keybind component by applying configuration from {@code consumer}. * * @param keybind the keybind * @param consumer the builder configurator * @return the keybind component */ public static KeybindComponent make(final @NonNull String keybind, final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(keybind); consumer.accept(builder); return builder.build(); }
@Test void testRebuildWithNoChanges() { final KeybindComponent component = KeybindComponent.of("keybind.jump"); assertEquals(component, component.toBuilder().build()); } }
@Test void testMake_content() { final KeybindComponent component = KeybindComponent.make("key.jump", builder -> builder.color(TextColor.DARK_PURPLE)); assertEquals("key.jump", component.keybind()); assertEquals(TextColor.DARK_PURPLE, component.color()); }
/** * Creates a keybind component by applying configuration from {@code consumer}. * * @param keybind the keybind * @param consumer the builder configurator * @return the keybind component */ public static KeybindComponent make(final @NonNull String keybind, final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(keybind); consumer.accept(builder); return builder.build(); }
/** * Creates a keybind component by applying configuration from {@code consumer}. * * @param consumer the builder configurator * @return the keybind component */ public static KeybindComponent make(final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(); consumer.accept(builder); return builder.build(); }