Package de.themoep.minedown.adventure
Class MineDownParser
java.lang.Object
de.themoep.minedown.adventure.MineDownParser
public class MineDownParser
extends java.lang.Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MineDownParser.Option
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.Pattern
URL_PATTERN
-
Constructor Summary
Constructors Constructor Description MineDownParser()
-
Method Summary
Modifier and Type Method Description boolean
autoAddUrlPrefix()
Get whether or not to automatically add http to values of open_url when there doesn't exist any?MineDownParser
autoAddUrlPrefix(boolean autoAddUrlPrefix)
Set whether or not to automatically add http to values of open_url when there doesn't exist any?protected net.kyori.adventure.text.ComponentBuilder<?,?>
builder()
protected MineDownParser
builder(net.kyori.adventure.text.ComponentBuilder builder)
protected net.kyori.adventure.text.event.ClickEvent
clickEvent()
protected MineDownParser
clickEvent(net.kyori.adventure.text.event.ClickEvent clickEvent)
char
colorChar()
Get The character to use as a special color code.MineDownParser
colorChar(char colorChar)
Set the character to use as a special color code.protected java.util.List<net.kyori.adventure.text.format.TextColor>
colors()
protected MineDownParser
colors(java.util.List<net.kyori.adventure.text.format.TextColor> colors)
MineDownParser
copy()
Copy all the parser's setting to a new instanceMineDownParser
copy(boolean formatting)
Copy all the parser's setting to a new instanceMineDownParser
copy(MineDownParser from)
Copy all the parser's settings from another parser.MineDownParser
copy(MineDownParser from, boolean formatting)
Copy all the parser's settings from another parser.MineDownParser
disable(MineDownParser.Option option)
Disable an option.MineDownParser
enable(MineDownParser.Option option)
Enable an option.java.util.Set<MineDownParser.Option>
enabledOptions()
Get all enabled options that will be used when parsingMineDownParser
enabledOptions(java.util.Set<MineDownParser.Option> enabledOptions)
Set all enabled options that will be used when parsing at once, replaces any existing optionsjava.lang.String
escape(java.lang.String string)
Escape formatting in the string depending on this parser's options.MineDownParser
filter(MineDownParser.Option option)
Filter an option.java.util.Set<MineDownParser.Option>
filteredOptions()
Get all filtered options that will be parsed and then removed from the stringMineDownParser
filteredOptions(java.util.Set<MineDownParser.Option> filteredOptions)
Set all filtered options that will be parsed and then removed from the string at once, replaces any existing optionsprotected java.lang.String
font()
protected java.util.Set<net.kyori.adventure.text.format.TextDecoration>
format()
protected MineDownParser
format(java.util.Set<net.kyori.adventure.text.format.TextDecoration> format)
protected boolean
formattingIsLegacy()
protected MineDownParser
formattingIsLegacy(boolean formattingIsLegacy)
protected net.kyori.adventure.text.event.HoverEvent
hoverEvent()
protected MineDownParser
hoverEvent(net.kyori.adventure.text.event.HoverEvent hoverEvent)
int
hoverTextWidth()
Get the max width the hover text should have.MineDownParser
hoverTextWidth(int hoverTextWidth)
Set the max width the hover text should have.protected java.lang.String
insertion()
boolean
isEnabled(MineDownParser.Option option)
Check whether or not an option is enabledboolean
isFiltered(MineDownParser.Option option)
Check whether or not an option is filteredboolean
lenient()
Get whether to accept malformed strings or notMineDownParser
lenient(boolean lenient)
Set whether to accept malformed strings or notnet.kyori.adventure.text.ComponentBuilder
parse(java.lang.String message)
Create a ComponentBuilder by parsing aMineDown
messagenet.kyori.adventure.text.ComponentBuilder
parseEvent(java.lang.String text, java.lang.String definitions)
Parse aMineDown
event stringstatic java.util.List<net.kyori.adventure.text.format.TextFormat>
parseFormat(java.lang.String colorString, java.lang.String prefix, boolean lenient)
Parse a color/format definitionprotected java.lang.Integer
rainbowPhase()
protected MineDownParser
rainbowPhase(java.lang.Integer rainbowPhase)
MineDownParser
reset()
Reset the parser state to the startboolean
translateLegacyColors()
Deprecated.MineDownParser
translateLegacyColors(boolean enabled)
Deprecated.Useenable(Option)
anddisable(Option)
insteadMineDownParser
unfilter(MineDownParser.Option option)
Unfilter an option.boolean
urlDetection()
Get whether or not urls in strings are detected and get events added to them?MineDownParser
urlDetection(boolean urlDetection)
Set whether or not to detect urls in strings and add events to them?java.lang.String
urlHoverText()
Get the text to display when hovering over an URL.MineDownParser
urlHoverText(java.lang.String urlHoverText)
Set the text to display when hovering over an URL.protected java.lang.StringBuilder
value()
protected MineDownParser
value(java.lang.StringBuilder value)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
URL_PATTERN
public static final java.util.regex.Pattern URL_PATTERN
-
-
Constructor Details
-
MineDownParser
public MineDownParser()
-
-
Method Details
-
parse
public net.kyori.adventure.text.ComponentBuilder parse(java.lang.String message) throws java.lang.IllegalArgumentExceptionCreate a ComponentBuilder by parsing aMineDown
message- Parameters:
message
- The message to parse- Returns:
- The parsed ComponentBuilder
- Throws:
java.lang.IllegalArgumentException
- Thrown when a parsing error occurs and lenient is set to false
-
parseEvent
public net.kyori.adventure.text.ComponentBuilder parseEvent(java.lang.String text, java.lang.String definitions)Parse aMineDown
event string- Parameters:
text
- The display textdefinitions
- The event definition string- Returns:
- The parsed ComponentBuilder for this string
-
builder
protected net.kyori.adventure.text.ComponentBuilder<?,?> builder() -
builder
-
value
-
value
protected java.lang.StringBuilder value() -
font
protected java.lang.String font() -
insertion
protected java.lang.String insertion() -
colors
-
rainbowPhase
-
rainbowPhase
protected java.lang.Integer rainbowPhase() -
colors
protected java.util.List<net.kyori.adventure.text.format.TextColor> colors() -
format
protected MineDownParser format(java.util.Set<net.kyori.adventure.text.format.TextDecoration> format) -
format
protected java.util.Set<net.kyori.adventure.text.format.TextDecoration> format() -
formattingIsLegacy
-
formattingIsLegacy
protected boolean formattingIsLegacy() -
clickEvent
-
clickEvent
protected net.kyori.adventure.text.event.ClickEvent clickEvent() -
hoverEvent
-
hoverEvent
protected net.kyori.adventure.text.event.HoverEvent hoverEvent() -
parseFormat
public static java.util.List<net.kyori.adventure.text.format.TextFormat> parseFormat(java.lang.String colorString, java.lang.String prefix, boolean lenient)Parse a color/format definition- Parameters:
colorString
- The string to parseprefix
- The color prefix e.g. ampersand (&)lenient
- Whether or not to accept malformed strings- Returns:
- The parsed color or
null
if lenient is true and no color was found
-
copy
Copy all the parser's setting to a new instance- Returns:
- The new parser instance with all settings copied
-
copy
Copy all the parser's setting to a new instance- Parameters:
formatting
- Should the formatting be copied too?- Returns:
- The new parser instance with all settings copied
-
copy
Copy all the parser's settings from another parser.- Parameters:
from
- The parser to copy from- Returns:
- This parser's instance
-
copy
Copy all the parser's settings from another parser.- Parameters:
from
- The parser to copy fromformatting
- Should the formatting be copied too?- Returns:
- This parser's instance
-
reset
Reset the parser state to the start- Returns:
- The parser's instance
-
translateLegacyColors
@Deprecated public boolean translateLegacyColors()Deprecated.UseisEnabled(Option)
insteadWhether or not to translate legacy color codes (Default: true)- Returns:
- Whether or not to translate legacy color codes (Default: true)
-
translateLegacyColors
Deprecated.Useenable(Option)
anddisable(Option)
insteadWhether or not to translate legacy color codes- Returns:
- The parser
-
isEnabled
Check whether or not an option is enabled- Parameters:
option
- The option to check for- Returns:
true
if it's enabled;false
if not
-
enable
Enable an option.- Parameters:
option
- The option to enable- Returns:
- The parser instace
-
disable
Disable an option. Disabling an option will stop the parser from replacing this option's chars in the string. Usefilter(Option)
to completely remove the characters used by this option from the message instead.- Parameters:
option
- The option to disable- Returns:
- The parser instace
-
isFiltered
Check whether or not an option is filtered- Parameters:
option
- The option to check for- Returns:
true
if it's enabled;false
if not
-
filter
Filter an option. This enables the parsing of an option and completely removes the characters of this option from the string.- Parameters:
option
- The option to add to the filter- Returns:
- The parser instance
-
unfilter
Unfilter an option. Does not enable it!- Parameters:
option
- The option to remove from the filter- Returns:
- The parser instance
-
escape
public java.lang.String escape(java.lang.String string)Escape formatting in the string depending on this parser's options. This will escape backslashes too!- Parameters:
string
- The string to escape- Returns:
- The string with all formatting of this parser escaped
-
colorChar
public char colorChar()Get The character to use as a special color code.- Returns:
- The color character (Default: ampersand &)
-
colorChar
Set the character to use as a special color code.- Parameters:
colorChar
- The color char (Default: ampersand &)- Returns:
- The MineDownParser instance
-
enabledOptions
Get all enabled options that will be used when parsing- Returns:
- a modifiable set of options
-
enabledOptions
Set all enabled options that will be used when parsing at once, replaces any existing options- Parameters:
enabledOptions
- The enabled options- Returns:
- The MineDownParser instance
-
filteredOptions
Get all filtered options that will be parsed and then removed from the string- Returns:
- a modifiable set of options
-
filteredOptions
Set all filtered options that will be parsed and then removed from the string at once, replaces any existing options- Parameters:
filteredOptions
- The filtered options- Returns:
- The MineDownParser instance
-
lenient
public boolean lenient()Get whether to accept malformed strings or not- Returns:
- whether or not the accept malformed strings (Default: false)
-
lenient
Set whether to accept malformed strings or not- Parameters:
lenient
- Set whether or not to accept malformed string (Default: false)- Returns:
- The MineDownParser instance
-
urlDetection
public boolean urlDetection()Get whether or not urls in strings are detected and get events added to them?- Returns:
- whether or not urls are detected (Default: true)
-
urlDetection
Set whether or not to detect urls in strings and add events to them?- Parameters:
urlDetection
- Whether or not to detect urls in strings (Default: true)- Returns:
- The MineDownParser instance
-
urlHoverText
public java.lang.String urlHoverText()Get the text to display when hovering over an URL. Has a %url% placeholder. -
urlHoverText
Set the text to display when hovering over an URL. Has a %url% placeholder.- Parameters:
urlHoverText
- The url hover text- Returns:
- The MineDownParser instance
-
autoAddUrlPrefix
public boolean autoAddUrlPrefix()Get whether or not to automatically add http to values of open_url when there doesn't exist any?- Returns:
- whether or not to automatically add http to values of open_url when there doesn't exist any? (Default: true)
-
autoAddUrlPrefix
Set whether or not to automatically add http to values of open_url when there doesn't exist any?- Parameters:
autoAddUrlPrefix
- Whether or not automatically add http to values of open_url when there doesn't exist any? (Default: true)- Returns:
- The MineDownParser instance
-
hoverTextWidth
public int hoverTextWidth()Get the max width the hover text should have. Minecraft itself will wrap after 60 characters. Won't apply if the text already includes new lines. -
hoverTextWidth
Set the max width the hover text should have. Minecraft itself will wrap after 60 characters. Won't apply if the text already includes new lines.- Parameters:
hoverTextWidth
- The url hover text length- Returns:
- The MineDownParser instance
-
isEnabled(Option)
instead