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 styling (i.e.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.voidregisterPlaceholder(String name, net.kyori.adventure.text.minimessage.tag.Tag result, String parent) 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.voidregisterResettingPlaceholder(String name, net.kyori.adventure.text.minimessage.tag.Tag result, String parent) 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.voidregisterResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver resolver, String parent) Registers a TagResolver with Skript's safe and unsafe message parsers.voidsetSafeTags(String... safeTags) Sets the tags that are permitted to be parsed by the safe parser.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.
-
setSafeTags
Sets the tags that are permitted to be parsed by the safe parser.- Parameters:
safeTags- An array containing the names of tags or their internal groups
-
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.
-
registerPlaceholder
public void registerPlaceholder(String name, net.kyori.adventure.text.minimessage.tag.Tag result, String parent) 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.parent- If this tag acts as an alias or subset of another tag, the name of that tag. This is used for associating tags permitted for the safe parser.
-
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.
-
registerResettingPlaceholder
public void registerResettingPlaceholder(String name, net.kyori.adventure.text.minimessage.tag.Tag result, String parent) 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.parent- If this tag acts as an alias or subset of another tag, the name of that tag. This is used for associating tags permitted for the safe parser.
-
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.
-
registerResolver
public void registerResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver resolver, String parent) Registers a TagResolver with Skript's safe and unsafe message parsers.- Parameters:
resolver- The TagResolver to register.parent- If this tag acts as an alias or subset of another tag, the name of that tag. This is used for associating tags permitted for the safe parser.
-
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.
-
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 styling (i.e. close all open style tags).
-
colorsCauseReset
public void colorsCauseReset(boolean colorsCauseReset) Sets whether color codes cause a reset of styling (i.e. close all open style tags).- Parameters:
colorsCauseReset- Whether color codes should cause a reset of styling.
-
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
-
escape
-
stripFormatting
-
stripSafeFormatting
-
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.
-