Class TextComponentParser
java.lang.Object
org.skriptlang.skript.bukkit.text.TextComponentParser
Used for parsing
The safe parser is intended to only parse tags that would be okay to process for any message, regardless of the source. This includes simple component features such as colors and text decorations.
The unsafe parser parses all tags, regardless of any potential risk (e.g. components that can run commands). Typically, users have to opt-in (in some manner) for this parser to be used.
Strings as Components.
This class makes use of two parses: a safe parser and an unsafe parser.
The safe parser is intended to only parse tags that would be okay to process for any message, regardless of the source. This includes simple component features such as colors and text decorations.
The unsafe parser parses all tags, regardless of any potential risk (e.g. components that can run commands). Typically, users have to opt-in (in some manner) for this parser to be used.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDescribes how this parser should handle potential links (outside of formatting tags). -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidcolorsCauseReset(boolean colorsCauseReset) Sets whether color codes cause a reset of existing formatting.Escapes all tags known to this parser in the given string.static TextComponentParserinstance()voidlinkParseMode(TextComponentParser.LinkParseMode linkParseMode) Sets the link parse mode for this parser, which describes how potential links should be treated.net.kyori.adventure.text.ComponentParses a string using the safe and unsafe parsers.net.kyori.adventure.text.ComponentParses a string using the safe parser.reformatText(String text) Reformats user component text for maximum compatibility with MiniMessage.voidregisterPlaceholder(String name, net.kyori.adventure.text.minimessage.tag.Tag result) Registers a simple key-value placeholder with Skript's unsafe message parser.voidregisterResettingPlaceholder(String name, net.kyori.adventure.text.minimessage.tag.Tag result) Registers a simple key-value placeholder with Skript's unsafe message parser.voidregisterResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver resolver) Registers a TagResolver with Skript's unsafe message parser.voidregisterSafePlaceholder(String name, net.kyori.adventure.text.minimessage.tag.Tag result) Registers a simple key-value placeholder with Skript's safe and unsafe message parsers.voidregisterSafeResettingPlaceholder(String name, net.kyori.adventure.text.minimessage.tag.Tag result) Registers a simple key-value placeholder with Skript's safe and unsafe message parsers.voidregisterSafeResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver resolver) Registers a TagResolver with Skript's safe and unsafe message parsers.stripFormatting(String string) Strips all formatting from a string.stripFormatting(net.kyori.adventure.text.Component component) Strips all formatting from a component.stripSafeFormatting(String string) Strips safe formatting from a string, meaning only safe tags such as colors and decorations will be stripped.toLegacyString(net.kyori.adventure.text.Component component) Converts a component into a legacy formatted string using the section character (§) for formatting codes.toString(net.kyori.adventure.text.Component component) Converts a component back into a formatted string.voidUnregisters a simple key-value placeholder from Skript's message parsers.voidunregisterResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver resolver) Unregisters a TagResolver from Skript's message parsers.
-
Method Details
-
instance
- Returns:
- The global parser instance used by Skript.
-
linkParseMode
- Returns:
- The link parse mode for this parser, which describes how potential links should be treated.
-
linkParseMode
Sets the link parse mode for this parser, which describes how potential links should be treated.- Parameters:
linkParseMode- The link parse mode to use.
-
colorsCauseReset
public boolean colorsCauseReset()- Returns:
- Whether color codes cause a reset of existing formatting.
Essentially, this setting controls whether all color tags should be prepended with a
<reset>tag. - See Also:
-
colorsCauseReset
public void colorsCauseReset(boolean colorsCauseReset) Sets whether color codes cause a reset of existing formatting. Essentially, this setting controls whether all color tags should be prepended with a<reset>tag.- Parameters:
colorsCauseReset- Whether color codes should cause a reset.- See Also:
-
registerPlaceholder
Registers a simple key-value placeholder with Skript's unsafe message parser.- Parameters:
name- The name/key of the placeholder.result- The result/value of the placeholder.
-
registerResettingPlaceholder
public void registerResettingPlaceholder(String name, net.kyori.adventure.text.minimessage.tag.Tag result) Registers a simple key-value placeholder with Skript's unsafe message parser. The registered placeholder will instruct the parser to reset existing formatting before applying the tag ifcolorsCauseReset()is true.- Parameters:
name- The name/key of the placeholder.result- The result/value of the placeholder.
-
registerSafePlaceholder
public void registerSafePlaceholder(String name, net.kyori.adventure.text.minimessage.tag.Tag result) Registers a simple key-value placeholder with Skript's safe and unsafe message parsers.- Parameters:
name- The name/key of the placeholder.result- The result/value of the placeholder.
-
registerSafeResettingPlaceholder
public void registerSafeResettingPlaceholder(String name, net.kyori.adventure.text.minimessage.tag.Tag result) Registers a simple key-value placeholder with Skript's safe and unsafe message parsers. The registered placeholder will instruct the parser to reset existing formatting before applying the tag ifcolorsCauseReset()is true.- Parameters:
name- The name/key of the placeholder.result- The result/value of the placeholder.
-
unregisterPlaceholder
Unregisters a simple key-value placeholder from Skript's message parsers.- Parameters:
tag- The name of the placeholder to unregister.
-
registerResolver
public void registerResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver resolver) Registers a TagResolver with Skript's unsafe message parser.- Parameters:
resolver- The TagResolver to register.
-
registerSafeResolver
public void registerSafeResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver resolver) Registers a TagResolver with Skript's safe and unsafe message parsers.- Parameters:
resolver- The TagResolver to register.
-
unregisterResolver
public void unregisterResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver resolver) Unregisters a TagResolver from Skript's message parsers.- Parameters:
resolver- The TagResolver to unregister.
-
parse
Parses a string using the safe and unsafe parsers.- Parameters:
message- The message to parse.- Returns:
- A component from the parsed message.
-
parseSafe
Parses a string using the safe parser. Only safe tags, such as color and decoration, will be parsed.- Parameters:
message- The message to parse.- Returns:
- A component from the parsed message.
-
reformatText
Reformats user component text for maximum compatibility with MiniMessage.- Parameters:
text- The text to reformat.- Returns:
- Reformatted
text.
-
escape
Escapes all tags known to this parser in the given string. This method will also escape legacy color codes by prepending them with a backslash.- Parameters:
string- The string to escape tags in.- Returns:
- The string with tags escaped.
-
stripFormatting
Strips all formatting from a string. This will handle nested tags, such as"<red<red>>".- Parameters:
string- The string to strip formatting from.- Returns:
- The stripped string.
-
stripSafeFormatting
Strips safe formatting from a string, meaning only safe tags such as colors and decorations will be stripped. This will handle nested tags, such as"<red<red>>".- Parameters:
string- The string to strip formatting from.- Returns:
- The stripped string.
-
stripFormatting
Strips all formatting from a component.- Parameters:
component- The component to strip formatting from.- Returns:
- A stripped string from a component.
-
toString
Converts a component back into a formatted string.- Parameters:
component- The component to convert.- Returns:
- A formatted string.
-
toLegacyString
Converts a component into a legacy formatted string using the section character (§) for formatting codes.- Parameters:
component- The component to convert.- Returns:
- The legacy string.
-