Package net.kyori.adventure.text.format
Interface Style
-
- All Superinterfaces:
Buildable<Style,Style.Builder>
,net.kyori.examination.Examinable
,StyleGetter
,StyleSetter<Style>
@NonExtendable public interface Style extends Buildable<Style,Style.Builder>, net.kyori.examination.Examinable, StyleGetter, StyleSetter<Style>
A style applies visual effects or extra functionality toComponent
s, such asTextColor
s,TextDecoration
s,ClickEvent
s etc.Some examples of valid styles:
Style myStyle = Style.style(ClickEvent.openUrl(url), NamedTextColor.RED, TextDecoration.BOLD); Style yourStyle = Style.style(TextColor.color(20, 30, 40), HoverEvent.showText(Component.text("Wow!")); Style ourStyle = Style.style().color(NamedTextColor.WHITE).build();
A note about fonts: the
Key
in this context represents the resource location of the font in the same way asSound
s- Since:
- 4.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Style.Builder
A style builder.static class
Style.Merge
A merge choice.
-
Field Summary
Fields Modifier and Type Field Description static Key
DEFAULT_FONT
The default font.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description @Nullable ClickEvent
clickEvent()
Gets the click event.@NotNull Style
clickEvent(@Nullable ClickEvent event)
Sets the click event.@Nullable TextColor
color()
Gets the color.@NotNull Style
color(@Nullable TextColor color)
Sets the color.@NotNull Style
colorIfAbsent(@Nullable TextColor color)
Sets the color if there isn't one set already.default @NotNull Style
decorate(@NotNull TextDecoration decoration)
Sets the state ofdecoration
toTextDecoration.State.TRUE
on this style.@NotNull TextDecoration.State
decoration(@NotNull TextDecoration decoration)
Gets the state of a decoration on this style.default @NotNull Style
decoration(@NotNull TextDecoration decoration, boolean flag)
Sets the state of a decoration on this style.@NotNull Style
decoration(@NotNull TextDecoration decoration, @NotNull TextDecoration.State state)
Sets the value of a decoration on this style.@NotNull Style
decorationIfAbsent(@NotNull TextDecoration decoration, @NotNull TextDecoration.State state)
Sets the state of a decoration on this style tostate
if the current state of the decoration isTextDecoration.State.NOT_SET
.default @Unmodifiable @NotNull java.util.Map<TextDecoration,TextDecoration.State>
decorations()
Gets a map of decorations this style has.@NotNull Style
decorations(@NotNull java.util.Map<TextDecoration,TextDecoration.State> decorations)
Sets decorations for this style using the specifieddecorations
map.default @NotNull Style
edit(@NotNull java.util.function.Consumer<Style.Builder> consumer)
Edits this style.default @NotNull Style
edit(@NotNull java.util.function.Consumer<Style.Builder> consumer, @NotNull Style.Merge.Strategy strategy)
Edits this style.static @NotNull Style
empty()
Gets an empty style.@Nullable Key
font()
Gets the font.@NotNull Style
font(@Nullable Key font)
Sets the font.default boolean
hasDecoration(@NotNull TextDecoration decoration)
Tests if this style has a decoration.@Nullable HoverEvent<?>
hoverEvent()
Gets the hover event.@NotNull Style
hoverEvent(@Nullable HoverEventSource<?> source)
Sets the hover event.@Nullable java.lang.String
insertion()
Gets the string to be inserted when this style is shift-clicked.@NotNull Style
insertion(@Nullable java.lang.String insertion)
Sets the string to be inserted when this style is shift-clicked.boolean
isEmpty()
Tests if this style is empty.default @NotNull Style
merge(@NotNull Style that)
Merges from another style into this style.default @NotNull Style
merge(@NotNull Style that, @NotNull java.util.Set<Style.Merge> merges)
Merges from another style into this style.default @NotNull Style
merge(@NotNull Style that, @NotNull Style.Merge merge)
Merges from another style into this style.default @NotNull Style
merge(@NotNull Style that, @NotNull Style.Merge.Strategy strategy)
Merges from another style into this style.@NotNull Style
merge(@NotNull Style that, @NotNull Style.Merge.Strategy strategy, @NotNull java.util.Set<Style.Merge> merges)
Merges from another style into this style.default @NotNull Style
merge(@NotNull Style that, @NotNull Style.Merge.Strategy strategy, @NotNull Style.Merge merge)
Merges from another style into this style.default @NotNull Style
merge(@NotNull Style that, @NotNull Style.Merge.Strategy strategy, @NotNull Style.Merge @NotNull ... merges)
Merges from another style into this style.default @NotNull Style
merge(@NotNull Style that, @NotNull Style.Merge @NotNull ... merges)
Merges from another style into this style.static @NotNull Style.Builder
style()
Creates a builder.static @NotNull Style
style(@NotNull java.lang.Iterable<? extends StyleBuilderApplicable> applicables)
Creates a style withapplicables
applied.static @NotNull Style
style(@NotNull java.util.function.Consumer<Style.Builder> consumer)
Creates a style.static @NotNull Style
style(@NotNull TextDecoration decoration)
Creates a style with decoration.static @NotNull Style
style(@Nullable TextColor color)
Creates a style with color.static @NotNull Style
style(@Nullable TextColor color, java.util.Set<TextDecoration> decorations)
Creates a style with color and decorations.static @NotNull Style
style(@Nullable TextColor color, TextDecoration @NotNull ... decorations)
Creates a style with color and decorations.static @NotNull Style
style(@UnknownNullability StyleBuilderApplicable @NotNull ... applicables)
Creates a style withapplicables
applied.@NotNull Style.Builder
toBuilder()
Create a builder from this style.@NotNull Style
unmerge(@NotNull Style that)
Simplify this style to remove any information that is redundant.-
Methods inherited from interface net.kyori.examination.Examinable
examinableName, examinableProperties, examine
-
Methods inherited from interface net.kyori.adventure.text.format.StyleSetter
decorate, decorations
-
-
-
-
Field Detail
-
DEFAULT_FONT
static final Key DEFAULT_FONT
The default font.- Since:
- 4.0.0
- Since Minecraft:
- 1.16
-
-
Method Detail
-
empty
@NotNull static @NotNull Style empty()
Gets an empty style.- Returns:
- empty style
- Since:
- 4.0.0
-
style
@NotNull static @NotNull Style.Builder style()
Creates a builder.- Returns:
- a builder
- Since:
- 4.0.0
-
style
@NotNull static @NotNull Style style(@NotNull @NotNull java.util.function.Consumer<Style.Builder> consumer)
Creates a style.- Parameters:
consumer
- the builder consumer- Returns:
- a style
- Since:
- 4.0.0
-
style
@NotNull static @NotNull Style style(@Nullable @Nullable TextColor color)
Creates a style with color.- Parameters:
color
- the style- Returns:
- a style
- Since:
- 4.0.0
-
style
@NotNull static @NotNull Style style(@NotNull @NotNull TextDecoration decoration)
Creates a style with decoration.- Parameters:
decoration
- the decoration- Returns:
- a style
- Since:
- 4.0.0
-
style
@NotNull static @NotNull Style style(@Nullable @Nullable TextColor color, TextDecoration @NotNull ... decorations)
Creates a style with color and decorations.- Parameters:
color
- the styledecorations
- the decorations- Returns:
- a style
- Since:
- 4.0.0
-
style
@NotNull static @NotNull Style style(@Nullable @Nullable TextColor color, java.util.Set<TextDecoration> decorations)
Creates a style with color and decorations.- Parameters:
color
- the styledecorations
- the decorations- Returns:
- a style
- Since:
- 4.0.0
-
style
@NotNull static @NotNull Style style(@UnknownNullability StyleBuilderApplicable @NotNull ... applicables)
Creates a style withapplicables
applied.- Parameters:
applicables
- the applicables- Returns:
- a style
- Since:
- 4.0.0
-
style
@NotNull static @NotNull Style style(@NotNull @NotNull java.lang.Iterable<? extends StyleBuilderApplicable> applicables)
Creates a style withapplicables
applied.- Parameters:
applicables
- the applicables- Returns:
- a style
- Since:
- 4.0.0
-
edit
@NotNull default @NotNull Style edit(@NotNull @NotNull java.util.function.Consumer<Style.Builder> consumer)
Edits this style.The old style will be merge into the new style before
consumer
is called.- Parameters:
consumer
- the consumer- Returns:
- a new style
- Since:
- 4.0.0
-
edit
@NotNull default @NotNull Style edit(@NotNull @NotNull java.util.function.Consumer<Style.Builder> consumer, @NotNull Style.Merge.Strategy strategy)
Edits this style.- Parameters:
consumer
- the consumerstrategy
- the merge strategy- Returns:
- a new style
- Since:
- 4.0.0
-
font
@Nullable @Nullable Key font()
Gets the font.- Specified by:
font
in interfaceStyleGetter
- Returns:
- the font
- Since:
- 4.0.0
- Since Minecraft:
- 1.16
-
font
@NotNull @NotNull Style font(@Nullable @Nullable Key font)
Sets the font.- Specified by:
font
in interfaceStyleSetter<Style>
- Parameters:
font
- the font- Returns:
- a style
- Since:
- 4.0.0
- Since Minecraft:
- 1.16
-
color
@Nullable @Nullable TextColor color()
Gets the color.- Specified by:
color
in interfaceStyleGetter
- Returns:
- the color
- Since:
- 4.0.0
-
color
@NotNull @NotNull Style color(@Nullable @Nullable TextColor color)
Sets the color.- Specified by:
color
in interfaceStyleSetter<Style>
- Parameters:
color
- the color- Returns:
- a style
- Since:
- 4.0.0
-
colorIfAbsent
@NotNull @NotNull Style colorIfAbsent(@Nullable @Nullable TextColor color)
Sets the color if there isn't one set already.- Specified by:
colorIfAbsent
in interfaceStyleSetter<Style>
- Parameters:
color
- the color- Returns:
- this builder
- Since:
- 4.0.0
-
hasDecoration
default boolean hasDecoration(@NotNull @NotNull TextDecoration decoration)
Tests if this style has a decoration.- Specified by:
hasDecoration
in interfaceStyleGetter
- Parameters:
decoration
- the decoration- Returns:
true
if this style has the decoration,false
if this style does not have the decoration- Since:
- 4.0.0
-
decoration
@NotNull TextDecoration.State decoration(@NotNull @NotNull TextDecoration decoration)
Gets the state of a decoration on this style.- Specified by:
decoration
in interfaceStyleGetter
- Parameters:
decoration
- the decoration- Returns:
TextDecoration.State.TRUE
if this style has the decoration,TextDecoration.State.FALSE
if this style does not have the decoration, andTextDecoration.State.NOT_SET
if not set- Since:
- 4.0.0
-
decorate
@NotNull default @NotNull Style decorate(@NotNull @NotNull TextDecoration decoration)
Sets the state ofdecoration
toTextDecoration.State.TRUE
on this style.- Specified by:
decorate
in interfaceStyleSetter<Style>
- Parameters:
decoration
- the decoration- Returns:
- a style
- Since:
- 4.0.0
-
decoration
@NotNull default @NotNull Style decoration(@NotNull @NotNull TextDecoration decoration, boolean flag)
Sets the state of a decoration on this style.- Specified by:
decoration
in interfaceStyleSetter<Style>
- Parameters:
decoration
- the decorationflag
-true
if this style should have the decoration,false
if this style should not have the decoration- Returns:
- a style
- Since:
- 4.0.0
-
decoration
@NotNull @NotNull Style decoration(@NotNull @NotNull TextDecoration decoration, @NotNull TextDecoration.State state)
Sets the value of a decoration on this style.- Specified by:
decoration
in interfaceStyleSetter<Style>
- Parameters:
decoration
- the decorationstate
-TextDecoration.State.TRUE
if this style should have the decoration,TextDecoration.State.FALSE
if this style should not have the decoration, andTextDecoration.State.NOT_SET
if the decoration should not have a set value- Returns:
- a style
- Since:
- 4.0.0
-
decorationIfAbsent
@NotNull @NotNull Style decorationIfAbsent(@NotNull @NotNull TextDecoration decoration, @NotNull TextDecoration.State state)
Sets the state of a decoration on this style tostate
if the current state of the decoration isTextDecoration.State.NOT_SET
.- Specified by:
decorationIfAbsent
in interfaceStyleSetter<Style>
- Parameters:
decoration
- the decorationstate
- the state- Returns:
- a style
- Since:
- 4.12.0
-
decorations
@NotNull default @Unmodifiable @NotNull java.util.Map<TextDecoration,TextDecoration.State> decorations()
Gets a map of decorations this style has.- Specified by:
decorations
in interfaceStyleGetter
- Returns:
- a set of decorations this style has
- Since:
- 4.0.0
-
decorations
@NotNull @NotNull Style decorations(@NotNull @NotNull java.util.Map<TextDecoration,TextDecoration.State> decorations)
Sets decorations for this style using the specifieddecorations
map.If a given decoration does not have a value explicitly set, the value of that particular decoration is not changed.
- Specified by:
decorations
in interfaceStyleSetter<Style>
- Parameters:
decorations
- the decorations- Returns:
- a style
- Since:
- 4.0.0
-
clickEvent
@Nullable @Nullable ClickEvent clickEvent()
Gets the click event.- Specified by:
clickEvent
in interfaceStyleGetter
- Returns:
- the click event
- Since:
- 4.0.0
-
clickEvent
@NotNull @NotNull Style clickEvent(@Nullable @Nullable ClickEvent event)
Sets the click event.- Specified by:
clickEvent
in interfaceStyleSetter<Style>
- Parameters:
event
- the click event- Returns:
- a style
- Since:
- 4.0.0
-
hoverEvent
@Nullable @Nullable HoverEvent<?> hoverEvent()
Gets the hover event.- Specified by:
hoverEvent
in interfaceStyleGetter
- Returns:
- the hover event
- Since:
- 4.0.0
-
hoverEvent
@NotNull @NotNull Style hoverEvent(@Nullable @Nullable HoverEventSource<?> source)
Sets the hover event.- Specified by:
hoverEvent
in interfaceStyleSetter<Style>
- Parameters:
source
- the hover event source- Returns:
- a style
- Since:
- 4.0.0
-
insertion
@Nullable @Nullable java.lang.String insertion()
Gets the string to be inserted when this style is shift-clicked.- Specified by:
insertion
in interfaceStyleGetter
- Returns:
- the insertion string
- Since:
- 4.0.0
-
insertion
@NotNull @NotNull Style insertion(@Nullable @Nullable java.lang.String insertion)
Sets the string to be inserted when this style is shift-clicked.- Specified by:
insertion
in interfaceStyleSetter<Style>
- Parameters:
insertion
- the insertion string- Returns:
- a style
- Since:
- 4.0.0
-
merge
@NotNull default @NotNull Style merge(@NotNull @NotNull Style that)
Merges from another style into this style.- Parameters:
that
- the other style- Returns:
- a style
- Since:
- 4.0.0
-
merge
@NotNull default @NotNull Style merge(@NotNull @NotNull Style that, @NotNull Style.Merge.Strategy strategy)
Merges from another style into this style.- Parameters:
that
- the other stylestrategy
- the merge strategy- Returns:
- a style
- Since:
- 4.0.0
-
merge
@NotNull default @NotNull Style merge(@NotNull @NotNull Style that, @NotNull @NotNull Style.Merge merge)
Merges from another style into this style.- Parameters:
that
- the other stylemerge
- the part to merge- Returns:
- a style
- Since:
- 4.0.0
-
merge
@NotNull default @NotNull Style merge(@NotNull @NotNull Style that, @NotNull Style.Merge.Strategy strategy, @NotNull @NotNull Style.Merge merge)
Merges from another style into this style.- Parameters:
that
- the other stylestrategy
- the merge strategymerge
- the part to merge- Returns:
- a style
- Since:
- 4.0.0
-
merge
@NotNull default @NotNull Style merge(@NotNull @NotNull Style that, @NotNull @NotNull Style.Merge @NotNull ... merges)
Merges from another style into this style.- Parameters:
that
- the other stylemerges
- the parts to merge- Returns:
- a style
- Since:
- 4.0.0
-
merge
@NotNull default @NotNull Style merge(@NotNull @NotNull Style that, @NotNull Style.Merge.Strategy strategy, @NotNull @NotNull Style.Merge @NotNull ... merges)
Merges from another style into this style.- Parameters:
that
- the other stylestrategy
- the merge strategymerges
- the parts to merge- Returns:
- a style
- Since:
- 4.0.0
-
merge
@NotNull default @NotNull Style merge(@NotNull @NotNull Style that, @NotNull @NotNull java.util.Set<Style.Merge> merges)
Merges from another style into this style.- Parameters:
that
- the other stylemerges
- the parts to merge- Returns:
- a style
- Since:
- 4.0.0
-
merge
@NotNull @NotNull Style merge(@NotNull @NotNull Style that, @NotNull Style.Merge.Strategy strategy, @NotNull @NotNull java.util.Set<Style.Merge> merges)
Merges from another style into this style.- Parameters:
that
- the other stylestrategy
- the merge strategymerges
- the parts to merge- Returns:
- a style
- Since:
- 4.0.0
-
unmerge
@NotNull @NotNull Style unmerge(@NotNull @NotNull Style that)
Simplify this style to remove any information that is redundant.- Parameters:
that
- parent to compare against- Returns:
- a new, simplified style
- Since:
- 4.12.0
-
isEmpty
boolean isEmpty()
Tests if this style is empty.- Returns:
true
if this style is empty,false
if this style is not empty- Since:
- 4.0.0
-
toBuilder
@NotNull @NotNull Style.Builder toBuilder()
Create a builder from this style.- Specified by:
toBuilder
in interfaceBuildable<Style,Style.Builder>
- Returns:
- a builder
-
-