public abstract class StringFormat
extends java.lang.Object
| Modifier and Type | Field | Description |
|---|---|---|
protected char |
colorChar |
| Constructor | Description |
|---|---|
StringFormat(char colorChar) |
| Modifier and Type | Method | Description |
|---|---|---|
static StringFormat |
adventure() |
Create a new
AdventureRgbStringFormat. |
static StringFormat |
adventure(char colorChar) |
Create a new
AdventureRgbStringFormat with the given color character. |
static StringFormat |
ansi() |
Create a new
AnsiStringFormat with true color enabled. |
static StringFormat |
ansi(boolean trueColor) |
Create a new
AnsiStringFormat with the given true color parameter. |
static StringFormat |
bungee() |
Create a new
BungeeRgbStringFormat. |
static StringFormat |
bungee(char colorChar) |
Create a new
BungeeRgbStringFormat with the given color character. |
boolean |
canRead(TextStringReader reader) |
Check if the reader can read the color character of this format.
|
abstract boolean |
canWrite(TextFormatting formatting) |
Check if this format can write the given text formatting.
|
java.lang.String |
convertTo(java.lang.String s,
StringFormat target) |
Convert a string from one format to another.
|
TextComponent |
fromString(java.lang.String s,
ColorHandling colorHandling,
DeserializerUnknownHandling unknownHandling) |
Convert a string to a
TextComponent. |
TextComponent |
fromString(java.lang.String s,
ColorHandling colorHandling,
DeserializerUnknownHandling unknownHandling,
boolean ignoreEmptySections) |
Convert a string to a
TextComponent. |
protected static <T> T |
init(T t,
java.util.function.Consumer<T> initializer) |
|
abstract boolean |
matches(TextStringReader reader) |
Check if the reader matches the format of this string format.
|
java.lang.String |
prependStyle(java.lang.String s,
Style style,
SerializerUnknownHandling unknownHandling) |
Prepend a style to the given string.
|
abstract TextFormatting |
read(TextStringReader reader) |
Read the next formatting code from the reader.
|
ResolvedFormatting |
resolve(TextStringReader reader) |
Resolve the next formatting code in the string.
|
boolean |
shouldResetAtEnd() |
|
java.lang.String[] |
split(java.lang.String s,
java.lang.String split,
ColorHandling colorHandling,
SerializerUnknownHandling serializerUnknownHandling,
DeserializerUnknownHandling deserializerUnknownHandling) |
Split a string by a given separator and keep the formatting of the previous part.
|
Style |
styleAt(java.lang.String s,
int index,
ColorHandling colorHandling,
DeserializerUnknownHandling unknownHandling) |
Get the style of a string at the given index.
|
java.lang.String |
toString(TextComponent component,
ColorHandling colorHandling,
SerializerUnknownHandling unknownHandling) |
Convert a
TextComponent to a string. |
java.lang.String |
toString(TextComponent component,
ColorHandling colorHandling,
SerializerUnknownHandling unknownHandling,
boolean ignoreEmptyComponents) |
Convert a
TextComponent to a string. |
static StringFormat |
vanilla() |
Create a new
VanillaStringFormat. |
static StringFormat |
vanilla(boolean downsampleRgbColors) |
Create a new
VanillaStringFormat with the given down sampling parameter. |
static StringFormat |
vanilla(char colorChar) |
Create a new
VanillaStringFormat with the given color character. |
static StringFormat |
vanilla(char colorChar,
boolean downsampleRgbColors) |
Create a new
VanillaStringFormat with the given color character and down sampling parameter. |
abstract void |
write(java.lang.StringBuilder builder,
TextFormatting formatting) |
Write the given text formatting to the builder.
|
public static StringFormat vanilla()
VanillaStringFormat.'§' and rgb down sampling is disabled.VanillaStringFormatpublic static StringFormat vanilla(char colorChar)
VanillaStringFormat with the given color character.downsampleRgbColors parameter is set to false.colorChar - The color characterVanillaStringFormatpublic static StringFormat vanilla(boolean downsampleRgbColors)
VanillaStringFormat with the given down sampling parameter.'§'.downsampleRgbColors - Downsample rgb colors to the closest vanilla colorVanillaStringFormatpublic static StringFormat vanilla(char colorChar, boolean downsampleRgbColors)
VanillaStringFormat with the given color character and down sampling parameter.colorChar - The color characterdownsampleRgbColors - Downsample rgb colors to the closest vanilla colorVanillaStringFormatpublic static StringFormat bungee()
BungeeRgbStringFormatpublic static StringFormat bungee(char colorChar)
BungeeRgbStringFormat with the given color character.colorChar - The color characterBungeeRgbStringFormatpublic static StringFormat adventure()
AdventureRgbStringFormatpublic static StringFormat adventure(char colorChar)
AdventureRgbStringFormat with the given color character.colorChar - The color characterAdventureRgbStringFormatpublic static StringFormat ansi()
AnsiStringFormat with true color enabled.public static StringFormat ansi(boolean trueColor)
AnsiStringFormat with the given true color parameter.trueColor - If true color should be enabledpublic TextComponent fromString(java.lang.String s, ColorHandling colorHandling, DeserializerUnknownHandling unknownHandling)
TextComponent.s - The string to convertcolorHandling - The color handlingunknownHandling - The unknown handlingpublic TextComponent fromString(java.lang.String s, ColorHandling colorHandling, DeserializerUnknownHandling unknownHandling, boolean ignoreEmptySections)
TextComponent.ignoreEmptySections is true, otherwise they are included as empty components.s - The string to convertcolorHandling - The color handlingunknownHandling - The unknown handlingpublic java.lang.String toString(TextComponent component, ColorHandling colorHandling, SerializerUnknownHandling unknownHandling)
TextComponent to a string.shouldResetAtEnd() return true and the last section had any formattings.component - The component to convertcolorHandling - The color handlingunknownHandling - The unknown handlingpublic java.lang.String toString(TextComponent component, ColorHandling colorHandling, SerializerUnknownHandling unknownHandling, boolean ignoreEmptyComponents)
TextComponent to a string.shouldResetAtEnd() return true and the last section had any formattings.ignoreEmptyComponents is true, otherwise their style will be applied (and immediately overwritten by the next component's style).component - The component to convertcolorHandling - The color handlingunknownHandling - The unknown handlingpublic Style styleAt(java.lang.String s, int index, ColorHandling colorHandling, DeserializerUnknownHandling unknownHandling)
s - The string to get the style fromindex - The index to get the style atcolorHandling - The color handlingunknownHandling - The unknown handlingpublic java.lang.String convertTo(java.lang.String s,
StringFormat target)
shouldResetAtEnd() return true and the last section had any formattings.s - The string in the current formattarget - The target formatpublic java.lang.String prependStyle(java.lang.String s,
Style style,
SerializerUnknownHandling unknownHandling)
SerializerUnknownHandling will be used to resolve it.s - The string to append the style tostyle - The style to appendunknownHandling - The unknown handlingpublic java.lang.String[] split(java.lang.String s,
java.lang.String split,
ColorHandling colorHandling,
SerializerUnknownHandling serializerUnknownHandling,
DeserializerUnknownHandling deserializerUnknownHandling)
s - The string to splitsplit - The split stringcolorHandling - The color handling (for styleAt(String, int, ColorHandling, DeserializerUnknownHandling))serializerUnknownHandling - The serializer unknown handling (for prependStyle(String, Style, SerializerUnknownHandling))deserializerUnknownHandling - The deserializer unknown handling (for styleAt(String, int, ColorHandling, DeserializerUnknownHandling))@Nullable public ResolvedFormatting resolve(TextStringReader reader)
null will be returned if no formatting code is at the current position.ResolvedFormatting.get() method will return null.canRead(TextStringReader), matches(TextStringReader) and read(TextStringReader).reader - The reader to read fromnull if no formatting code was foundpublic boolean canRead(TextStringReader reader)
matches(TextStringReader).reader - The reader to checkpublic abstract boolean matches(TextStringReader reader)
TextStringReader.mark() and TextStringReader.reset().reader - The reader to check@Nullable public abstract TextFormatting read(TextStringReader reader)
matches(TextStringReader) before calling this method.null should be returned.reader - The reader to read fromnull if the formatting code is invalidpublic abstract boolean canWrite(TextFormatting formatting)
formatting - The formatting to checkpublic abstract void write(java.lang.StringBuilder builder,
TextFormatting formatting)
canWrite(TextFormatting) returns true.builder - The builder to write toformatting - The formatting to writepublic boolean shouldResetAtEnd()
protected static <T> T init(T t,
java.util.function.Consumer<T> initializer)