@CatalogedBy(value=TextStyles.class) public class TextStyle extends Object implements TextElement
Text
. It is a utility that is
not normally present in Minecraft. It can be either empty, a TextStyle.Base
with an additional legacy formatting code or a composite.
Combined styles can be created using TextStyles.of(TextStyle...)
or using one of the and(TextStyle...)
, andNot(TextStyle...)
or negate()
method.
Each individual style within a TextStyle, e.g. bold, italic is not just a
boolean, but an Optional<Boolean>
since it can be unapplied
(or, in Optional terms, "empty"). These styles will hereafter be referred to
as properties.
See the OptBool
utility class for working with
properties.
Implementation note: Absent styles should not appear in the final chat component JSON. Properties that are set to true or false should appear, even if they override inherited properties.
TextStyles
Modifier and Type | Class and Description |
---|---|
static class |
TextStyle.Base
Represents a
TextStyle that is not a composite, for example
TextStyles.BOLD . |
Modifier and Type | Field and Description |
---|---|
protected Optional<Boolean> |
bold
Whether text where this style is applied is bolded.
|
protected Optional<Boolean> |
italic
Whether text where this style is applied is italicized.
|
protected Optional<Boolean> |
obfuscated
Whether text where this style is applied is obfuscated.
|
protected Optional<Boolean> |
strikethrough
Whether text where this style is applied has a strikethrough.
|
protected Optional<Boolean> |
underline
Whether text where this style is applied is underlined.
|
Constructor and Description |
---|
TextStyle(Boolean bold,
Boolean italic,
Boolean underline,
Boolean strikethrough,
Boolean obfuscated)
Constructs a new
TextStyle . |
Modifier and Type | Method and Description |
---|---|
TextStyle |
and(TextStyle... styles)
Composes this
TextStyle with the specified text styles. |
TextStyle |
andNot(TextStyle... styles)
Composes this
TextStyle with the passed in TextStyles, but
negates them before composition. |
void |
applyTo(Text.Builder builder)
Applies this element to the end of the specified builder.
|
TextStyle |
bold(Boolean bold)
Returns a new
TextStyle with the bold property changed. |
boolean |
contains(TextStyle... styles)
|
boolean |
equals(Object o) |
int |
hashCode() |
Optional<Boolean> |
hasStrikethrough()
Checks for whether text where this style is applied has a strikethrough.
|
Optional<Boolean> |
hasUnderline()
Checks for whether text where this style is applied has an underline.
|
Optional<Boolean> |
isBold()
Checks for whether text where this style is applied is bolded.
|
boolean |
isComposite()
Returns whether this
TextStyle is a composite of multiple text
styles. |
boolean |
isEmpty()
Returns whether this
TextStyle has no set properties. |
Optional<Boolean> |
isItalic()
Checks for whether text where this style is applied is italicized.
|
Optional<Boolean> |
isObfuscated()
Checks for whether text where this style is obfuscated.
|
TextStyle |
italic(Boolean italic)
Returns a new
TextStyle with the italic property changed. |
TextStyle |
negate()
Negates this
TextStyle . |
TextStyle |
obfuscated(Boolean obfuscated)
Returns a new
TextStyle with the obfuscated property changed. |
TextStyle |
strikethrough(Boolean strikethrough)
Returns a new
TextStyle with the strikethrough property changed. |
String |
toString() |
TextStyle |
underline(Boolean underline)
Returns a new
TextStyle with the underline property changed. |
protected final Optional<Boolean> italic
protected final Optional<Boolean> underline
protected final Optional<Boolean> strikethrough
public TextStyle(@Nullable Boolean bold, @Nullable Boolean italic, @Nullable Boolean underline, @Nullable Boolean strikethrough, @Nullable Boolean obfuscated)
TextStyle
.bold
- Whether text where this style is applied is boldeditalic
- Whether text where this style is applied is italicizedunderline
- Whether text where this style is applied is underlinedobfuscated
- Whether text where this style is applied is obfuscatedstrikethrough
- Whether text where this style is applied has a
strikethroughpublic boolean isComposite()
TextStyle
is a composite of multiple text
styles.true
if this text style is a compositepublic boolean isEmpty()
TextStyle
has no set properties.true
if this style is emptypublic TextStyle bold(@Nullable Boolean bold)
TextStyle
with the bold property changed.bold
- Whether text where the new style is applied is boldedpublic TextStyle italic(@Nullable Boolean italic)
TextStyle
with the italic property changed.italic
- Whether text where the new style is applied is italicizedpublic TextStyle underline(@Nullable Boolean underline)
TextStyle
with the underline property changed.underline
- Whether text where the new style is applied is underlinepublic TextStyle strikethrough(@Nullable Boolean strikethrough)
TextStyle
with the strikethrough property changed.strikethrough
- Whether text where the new style is applied has a
strikethroughpublic TextStyle obfuscated(@Nullable Boolean obfuscated)
TextStyle
with the obfuscated property changed.obfuscated
- Whether text where the new style is applied is
obfuscatedpublic Optional<Boolean> isBold()
Optional.empty()
public Optional<Boolean> isItalic()
Optional.empty()
public Optional<Boolean> hasUnderline()
Optional.empty()
public Optional<Boolean> hasStrikethrough()
Optional.empty()
public Optional<Boolean> isObfuscated()
Optional.empty()
public boolean contains(TextStyle... styles)
TextStyle
is contained in this
TextStyle
.
For example, a TextStyle
with bold: true, italic:
true
} would return true
for contains(
and TextStyles.BOLD
)contains(
TextStyles.ITALIC
).
If the specified TextStyle
is a composite of multiple styles
it returns true
if this style has at least all of the properties
set in the specified style.
styles
- The text styles to checktrue
if the given text styles are contained in this text
stylepublic TextStyle negate()
TextStyle
. This is useful for undoing text styles
that are inherited from parent messages.public TextStyle and(TextStyle... styles)
TextStyle
with the specified text styles.styles
- The text styles to compose this one withpublic TextStyle andNot(TextStyle... styles)
TextStyle
with the passed in TextStyles, but
negates them before composition. This is the same as negating all the
passed in TextStyle
and then using the and(TextStyle...)
method.styles
- The text styles to compose this one withpublic void applyTo(Text.Builder builder)
TextElement
applyTo
in interface TextElement
builder
- Text builder to apply to