args.add(this.deserialize(argElement, argElement.getClass(), context)); component = TranslatableComponent.builder(key).args(args);
/** * Creates a translatable component by applying configuration from {@code consumer}. * * @param key the translation key * @param consumer the builder configurator * @return the translatable component */ public static TranslatableComponent make(final @NonNull String key, final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(key); consumer.accept(builder); return builder.build(); }
args.add(this.deserialize(argElement, argElement.getClass(), context)); component = TranslatableComponent.builder(key).args(args);
@Test void testComplex() { final FriendlyComponentRenderer<ComponentRenderer.Context> renderer = FriendlyComponentRenderer.from((locale, key) -> new MessageFormat(TRANSLATIONS.get(locale, key), locale)); assertEquals( TextComponent.builder("") .color(TextColor.YELLOW) .append(TextComponent.of("kashike")) .append(TextComponent.of(" and ")) .append(TextComponent.of("lucko")) .append(TextComponent.of(" are cats.")) .build(), renderer.render( TranslatableComponent .builder() .key("cats") .args( TextComponent.of("kashike"), TextComponent.of("lucko") ) .color(TextColor.YELLOW) .build(), new ComponentRenderer.Context() { @Override public @NonNull Locale locale() { return Locale.US; } } ) ); }
@Test void testSimple() { final FriendlyComponentRenderer<ComponentRenderer.Context> renderer = FriendlyComponentRenderer.from((locale, key) -> new MessageFormat(TRANSLATIONS.get(locale, key), locale)); assertEquals( TextComponent.builder("This is a test.") .color(TextColor.YELLOW) .build(), renderer.render( TranslatableComponent .builder() .key("test") .color(TextColor.YELLOW) .build(), new ComponentRenderer.Context() { @Override public @NonNull Locale locale() { return Locale.US; } } ) ); }
/** * Creates a translatable component with a translation key and arguments. * * @param key the translation key * @param color the color * @param decorations the decorations * @param args the translation arguments * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color, final @NonNull Set<TextDecoration> decorations, final @NonNull List<Component> args) { return builder() .color(color) .decorations(decorations, true) .key(key) .args(args) .build(); }
/** * Creates a translatable component with a translation key and arguments. * * @param key the translation key * @param color the color * @param decorations the decorations * @param args the translation arguments * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color, final @NonNull Set<TextDecoration> decorations, final @NonNull List<Component> args) { return builder() .color(color) .decorations(decorations, true) .key(key) .args(args) .build(); }
/** * Creates a translatable component with a translation key and arguments. * * @param key the translation key * @param color the color * @param decorations the decorations * @param args the translation arguments * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color, final @NonNull Set<TextDecoration> decorations, final @NonNull List<Component> args) { return builder() .color(color) .decorations(decorations, true) .key(key) .args(args) .build(); }
@Override public @NonNull Builder toBuilder() { return new Builder(this); }
/** * Creates a translatable component by applying configuration from {@code consumer}. * * @param consumer the builder configurator * @return the translatable component */ public static TranslatableComponent make(final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(); consumer.accept(builder); return builder.build(); }
@Test void testMake_content() { final TranslatableComponent component = TranslatableComponent.make("multiplayer.player.left", builder -> builder.color(TextColor.DARK_PURPLE)); assertEquals("multiplayer.player.left", component.key()); assertEquals(TextColor.DARK_PURPLE, component.color()); }
/** * Creates a translatable component with a translation key. * * @param key the translation key * @param color the color * @param decorations the decorations * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color, final @NonNull Set<TextDecoration> decorations) { return builder(key) .color(color) .decorations(decorations, true) .build(); }
/** * Creates a translatable component with a translation key. * * @param key the translation key * @param color the color * @param decorations the decorations * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color, final @NonNull Set<TextDecoration> decorations) { return builder(key) .color(color) .decorations(decorations, true) .build(); }
/** * Creates a translatable component with a translation key. * * @param key the translation key * @param color the color * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key, final @Nullable TextColor color) { return builder(key) .color(color) .build(); }
@Override public @NonNull Builder toBuilder() { return new Builder(this); }
/** * Creates a translatable component by applying configuration from {@code consumer}. * * @param key the translation key * @param consumer the builder configurator * @return the translatable component */ public static TranslatableComponent make(final @NonNull String key, final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(key); consumer.accept(builder); return builder.build(); }
/** * Creates a translatable component by applying configuration from {@code consumer}. * * @param key the translation key * @param consumer the builder configurator * @return the translatable component */ public static TranslatableComponent make(final @NonNull String key, final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(key); consumer.accept(builder); return builder.build(); }
/** * Creates a translatable component with a translation key. * * @param key the translation key * @return the translatable component */ public static TranslatableComponent of(final @NonNull String key) { return builder(key).build(); }
/** * Sets the translation args. * * @param args the translation args * @return this builder */ public @NonNull Builder args(final @NonNull Component... args) { return this.args(Arrays.asList(args)); }