if(object.has("bold")) component.decoration(TextDecoration.BOLD, object.get("bold").getAsBoolean()); if(object.has("italic")) component.decoration(TextDecoration.ITALIC, object.get("italic").getAsBoolean()); if(object.has("underlined")) component.decoration(TextDecoration.UNDERLINE, object.get("underlined").getAsBoolean()); if(object.has("strikethrough")) component.decoration(TextDecoration.STRIKETHROUGH, object.get("strikethrough").getAsBoolean()); if(object.has("obfuscated")) component.decoration(TextDecoration.OBFUSCATED, object.get("obfuscated").getAsBoolean()); if(object.has("color")) component.color(context.deserialize(object.get("color"), TextColor.class)); if(object.has("insertion")) component.insertion(object.get("insertion").getAsString());
if(object.has("bold")) component.decoration(TextDecoration.BOLD, object.get("bold").getAsBoolean()); if(object.has("italic")) component.decoration(TextDecoration.ITALIC, object.get("italic").getAsBoolean()); if(object.has("underlined")) component.decoration(TextDecoration.UNDERLINED, object.get("underlined").getAsBoolean()); if(object.has("strikethrough")) component.decoration(TextDecoration.STRIKETHROUGH, object.get("strikethrough").getAsBoolean()); if(object.has("obfuscated")) component.decoration(TextDecoration.OBFUSCATED, object.get("obfuscated").getAsBoolean()); if(object.has("color")) component.color(context.deserialize(object.get("color"), TextColor.class)); if(object.has("insertion")) component.insertion(object.get("insertion").getAsString());
/** * Sets the state of a set of decorations to {@code flag} on this component. * * @param decorations the decorations * @param flag {@code true} if this component should have the decorations, {@code false} if * this component should not have the decorations * @return this builder */ default @NonNull B decorations(final @NonNull Set<TextDecoration> decorations, final boolean flag) { final TextDecoration.State state = TextDecoration.State.byBoolean(flag); decorations.forEach(decoration -> this.decoration(decoration, state)); return (B) this; }
/** * Sets the state of a set of decorations to {@code flag} on this component. * * @param decorations the decorations * @param flag {@code true} if this component should have the decorations, {@code false} if * this component should not have the decorations * @return this builder */ @SuppressWarnings("unchecked") default @NonNull B decorations(final @NonNull Set<TextDecoration> decorations, final boolean flag) { final TextDecoration.State state = TextDecoration.State.byBoolean(flag); decorations.forEach(decoration -> this.decoration(decoration, state)); return (B) this; }
/** * Merges the decorations from another component into this component. * * @param that the other component * @return this builder */ @SuppressWarnings("unchecked") default @NonNull B mergeDecorations(final @NonNull Component that) { for(final TextDecoration decoration : TextDecoration.values()) { final TextDecoration.State state = that.decoration(decoration); if(state != TextDecoration.State.NOT_SET) this.decoration(decoration, state); } return (B) this; }
/** * Sets the state of a set of decorations to {@code flag} on this component. * * @param decorations the decorations * @param flag {@code true} if this component should have the decorations, {@code false} if * this component should not have the decorations * @return this builder */ @SuppressWarnings("unchecked") default @NonNull B decorations(final @NonNull Set<TextDecoration> decorations, final boolean flag) { final TextDecoration.State state = TextDecoration.State.byBoolean(flag); decorations.forEach(decoration -> this.decoration(decoration, state)); return (B) this; }
@Test void testResetStyle() { final C c0 = this.builder() .color(TextColor.RED) .decoration(TextDecoration.BOLD, true) .clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/foo")) .build(); final C c1 = (C) c0.resetStyle(); assertNull(c1.color()); assertDecorations(c1, ImmutableMap.of()); assertNull(c1.clickEvent()); assertEquals(c1, c0.color(null).decoration(TextDecoration.BOLD, TextDecoration.State.NOT_SET).clickEvent(null)); }
/** * Merges the decorations from another component into this component. * * @param that the other component * @return this builder */ @SuppressWarnings("unchecked") default @NonNull B mergeDecorations(final @NonNull Component that) { for(final TextDecoration decoration : TextDecoration.values()) { final TextDecoration.State state = that.decoration(decoration); if(state != TextDecoration.State.NOT_SET) this.decoration(decoration, state); } return (B) this; }
/** * Resets all styling on this component. * * @return this builder */ @SuppressWarnings("unchecked") default @NonNull B resetStyle() { this.color(null); for(final TextDecoration decoration : TextDecoration.values()) this.decoration(decoration, TextDecoration.State.NOT_SET); this.clickEvent(null); this.hoverEvent(null); return (B) this; }
/** * Resets all styling on this component. * * @return this builder */ @SuppressWarnings("unchecked") default @NonNull B resetStyle() { this.color(null); for(final TextDecoration decoration : TextDecoration.values()) this.decoration(decoration, TextDecoration.State.NOT_SET); this.clickEvent(null); this.hoverEvent(null); return (B) this; }
/** * Merges the decorations from another component into this component. * * @param that the other component * @return this builder */ default @NonNull B mergeDecorations(final @NonNull Component that) { for(final TextDecoration decoration : TextDecoration.values()) { final TextDecoration.State state = that.decoration(decoration); if(state != TextDecoration.State.NOT_SET) this.decoration(decoration, state); } return (B) this; }
/** * Sets the state of a decoration on this component. * * @param decoration the decoration * @param flag {@code true} if this component should have the decoration, {@code false} if * this component should not have the decoration * @return this builder */ default @NonNull B decoration(final @NonNull TextDecoration decoration, final boolean flag) { return this.decoration(decoration, TextDecoration.State.byBoolean(flag)); }
/** * Sets the state of a decoration on this component. * * @param decoration the decoration * @param flag {@code true} if this component should have the decoration, {@code false} if * this component should not have the decoration * @return this builder */ default @NonNull B decoration(final @NonNull TextDecoration decoration, final boolean flag) { return this.decoration(decoration, TextDecoration.State.byBoolean(flag)); }
/** * Resets all styling on this component. * * @return this builder */ default @NonNull B resetStyle() { this.color(null); for(final TextDecoration decoration : TextDecoration.values()) this.decoration(decoration, TextDecoration.State.NOT_SET); this.clickEvent(null); this.hoverEvent(null); return (B) this; }
/** * Sets the state of a decoration on this component. * * @param decoration the decoration * @param flag {@code true} if this component should have the decoration, {@code false} if * this component should not have the decoration * @return this builder */ default @NonNull B decoration(final @NonNull TextDecoration decoration, final boolean flag) { return this.decoration(decoration, TextDecoration.State.byBoolean(flag)); }