/** * Creates a text component with the content of {@link String#valueOf(long)}. * * @param value the long value * @return the component */ static @NonNull Component of(final long value) { return TextComponent.of(String.valueOf(value)); }
/** * Creates a text component with the content of {@link String#valueOf(double)}. * * @param value the double value * @return the component */ static @NonNull Component of(final double value) { return TextComponent.of(String.valueOf(value)); }
/** * Creates a text component with the content of {@link String#valueOf(int)}. * * @param value the int value * @return the component */ static @NonNull Component of(final int value) { return TextComponent.of(String.valueOf(value)); }
/** * Creates a text component with the content of {@link String#valueOf(boolean)}. * * @param value the boolean value * @return the component */ static @NonNull Component of(final boolean value) { return TextComponent.of(String.valueOf(value)); }
/** * Creates a text component with the content of {@link String#valueOf(long)}. * * @param value the long value * @return the component */ static @NonNull Component of(final long value) { return TextComponent.of(String.valueOf(value)); } }
/** * Creates a text component with the content of {@link String#valueOf(boolean)}. * * @param value the boolean value * @return the component */ static @NonNull Component of(final boolean value) { return TextComponent.of(String.valueOf(value)); }
@Override public void exception(Throwable throwable) { player.disconnect(TextComponent.of("Your connection has encountered an error. Try again later.", TextColor.RED)); }
/** * Creates a text component with the content of {@link String#valueOf(double)}. * * @param value the double value * @return the component */ static @NonNull Component of(final double value) { return TextComponent.of(String.valueOf(value)); }
/** * Creates a text component with the content of {@link String#valueOf(double)}. * * @param value the double value * @return the component */ static @NonNull Component of(final double value) { return TextComponent.of(String.valueOf(value)); }
/** * Creates a text component with the content of {@link String#valueOf(float)}. * * @param value the float value * @return the component */ static @NonNull Component of(final float value) { return TextComponent.of(String.valueOf(value)); }
/** * Creates a text component with the content of {@link String#valueOf(int)}. * * @param value the int value * @return the component */ static @NonNull Component of(final int value) { return TextComponent.of(String.valueOf(value)); }
/** * Creates a text component with the content of {@link String#valueOf(float)}. * * @param value the float value * @return the component */ static @NonNull Component of(final float value) { return TextComponent.of(String.valueOf(value)); }
/** * Creates a text component with content, and optional color. * * @param content the plain text content * @param color the color * @return the text component */ public static TextComponent of(final @NonNull String content, final @Nullable TextColor color) { return of(content, color, Collections.emptySet()); }
@Override public boolean handle(LegacyHandshake packet) { connection.closeWith(LegacyDisconnect .from(TextComponent.of("Your client is old, please upgrade!", TextColor.RED))); return true; }
/** * Creates a text component with the content of {@link String#valueOf(char)}. * * @param value the char value * @return the component */ static @NonNull Component of(final char value) { if(value == '\n') return newline(); if(value == ' ') return space(); return TextComponent.of(String.valueOf(value)); }
@Override protected void runCommand(String command) { try { if (!this.server.getCommandManager().execute(this, command)) { sendMessage(TextComponent.of("Command not found.", TextColor.RED)); } } catch (Exception e) { logger.error("An error occurred while running this command.", e); } }
@Test void testCopy() { final HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Kittens!")); final HoverEvent copy = event.copy(); assertNotSame(event, copy); assertEquals(event, copy); } }
@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 testMergeEvents() { final C c0 = this.builder().build(); assertNull(c0.color()); assertDecorations(c0, ImmutableMap.of()); assertNull(c0.clickEvent()); final C c1 = (C) c0.mergeEvents(TextComponent.of("xyz", TextColor.RED, ImmutableSet.of(TextDecoration.BOLD)).clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/foo"))); assertNull(c1.color()); assertDecorations(c1, ImmutableMap.of()); assertNotNull(c1.clickEvent()); }
@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)); } }