/** * Creates a text component by applying configuration from {@code consumer}. * * @param consumer the builder configurator * @return the text component */ public static TextComponent make(final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(); consumer.accept(builder); return builder.build(); }
/** * Creates a text component by applying configuration from {@code consumer}. * * @param consumer the builder configurator * @return the text component */ public static TextComponent make(final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(); consumer.accept(builder); return builder.build(); }
/** * Creates a text component by applying configuration from {@code consumer}. * * @param consumer the builder configurator * @return the text component */ public static TextComponent make(final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(); consumer.accept(builder); return builder.build(); }
@Test void testFromColor() { final TextComponent component = TextComponent.builder("") .append(TextComponent.of("foo").color(TextColor.GREEN).decoration(TextDecoration.BOLD, TextDecoration.State.TRUE)) .append(TextComponent.of("bar").color(TextColor.BLUE)) .build(); assertEquals(component, LegacyComponentSerializer.INSTANCE.deserialize("&a&lfoo&9bar", '&')); }
/** * Creates a text component by applying configuration from {@code consumer}. * * @param content the plain text content * @param consumer the builder configurator * @return the text component */ public static TextComponent make(final @NonNull String content, final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(content); consumer.accept(builder); return builder.build(); }
/** * Creates a text component by applying configuration from {@code consumer}. * * @param content the plain text content * @param consumer the builder configurator * @return the text component */ public static TextComponent make(final @NonNull String content, final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(content); consumer.accept(builder); return builder.build(); }
/** * Creates a text component with content. * * @param content the plain text content * @return the text component */ public static TextComponent of(final @NonNull String content) { return builder(content).build(); }
/** * Creates a text component with content, and optional color and decorations. * * @param content the plain text content * @param color the color * @param decorations the decorations * @return the text component */ public static TextComponent of(final @NonNull String content, final @Nullable TextColor color, final @NonNull Set<TextDecoration> decorations) { return builder(content).color(color).decorations(decorations, true).build(); }
@Test void testCopy() { final TextComponent.Builder component = TextComponent.builder().content("").color(TextColor.GRAY); component.append(TextComponent.builder().content("This is a test").color(TextColor.DARK_PURPLE).build()); component.append(TextComponent.builder().content(" ").build()); component.append(TextComponent.builder().content("A what?").color(TextColor.DARK_AQUA).clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/what")).build()); assertEquals(component.build(), component.build().copy()); }
/** * Creates a text component with content. * * @param content the plain text content * @return the text component */ public static TextComponent of(final @NonNull String content) { return builder(content).build(); }
@Test void testRebuildWithNoChanges() { final TextComponent component = TextComponent.of("foo", TextColor.RED); assertEquals(component, component.toBuilder().build()); } }
/** * Creates a text component with content, and optional color and decorations. * * @param content the plain text content * @param color the color * @param decorations the decorations * @return the text component */ public static TextComponent of(final @NonNull String content, final @Nullable TextColor color, final @NonNull Set<TextDecoration> decorations) { return builder(content).color(color).decorations(decorations, true).build(); }
@Subscribe(order = PostOrder.FIRST) public void onEnable(ProxyInitializeEvent e) { this.proxy.getCommandManager().register((sender, args) -> { if (!sender.hasPermission("spark")) { TextComponent msg = TextComponent.builder("You do not have permission to use this command.").color(TextColor.RED).build(); sender.sendMessage(msg); return; } SparkVelocityPlugin.this.sparkPlatform.executeCommand(sender, args); }, "sparkv", "sparkvelocity"); } }
@Test void testCycleSelf() { assertThrows(IllegalStateException.class, () -> { final Component component = TextComponent.builder().content("cat").build(); component.append(component); fail("A component was added to itself"); }); }
@Test void testStyleReset() { Component component = TextComponent.builder() .content("kittens") .build(); assertFalse(component.hasStyling()); component = component.decoration(TextDecoration.BOLD, TextDecoration.State.TRUE); assertTrue(component.hasStyling()); component = component.resetStyle(); assertFalse(component.hasStyling()); }
@Test void testContains() { final Component child = TextComponent.of("kittens"); final Component component = TextComponent.builder() .content("cat") .append(child) .build(); assertTrue(component.contains(child)); }
@Test void testSerializeDeserialize() { final TextComponent expected = TextComponent.builder() .content("Hello!") .color(TextColor.DARK_PURPLE) .decoration(TextDecoration.BOLD, TextDecoration.State.TRUE) .clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://google.com/")) .hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.builder().content(":o").color(TextColor.DARK_AQUA).build())) .build(); final String json = GsonComponentSerializer.INSTANCE.serialize(expected); assertEquals(expected, GsonComponentSerializer.INSTANCE.deserialize(json)); }
/** * Creates a text component with content, and optional color and decorations. * * @param content the plain text content * @param color the color * @param decorations the decorations * @return the text component */ public static TextComponent of(final @NonNull String content, final @Nullable TextColor color, final @NonNull Set<TextDecoration> decorations) { return builder(content).color(color).decorations(decorations, true).build(); }
/** * Creates a text component by applying configuration from {@code consumer}. * * @param content the plain text content * @param consumer the builder configurator * @return the text component */ public static TextComponent make(final @NonNull String content, final @NonNull Consumer<Builder> consumer) { final Builder builder = builder(content); consumer.accept(builder); return builder.build(); }
/** * Creates a text component with content. * * @param content the plain text content * @return the text component */ public static TextComponent of(final @NonNull String content) { return builder(content).build(); }