Package de.themoep.minedown.adventure
Class MineDown
java.lang.Object
de.themoep.minedown.adventure.MineDown
public class MineDown
extends java.lang.Object
MineDown-adventure
A MarkDown inspired markup for Minecraft chat componentsThis lets you convert string messages into chat components by using a custom mark up syntax which is loosely based on MarkDown while still supporting legacy formatting codes.
Color legacy | &6Text | TextColor codes |
Color | &gold&Text | TextColor codes |
RGB Hex Color | &ff00ff&Text | Full hexadecimal format |
RGB Hex Color | &f0f&Text | Short format (equivalent to long one) |
Bold | **Text** | |
Italic | ##Text## | |
Underlined | __Text__ | |
Strikethrough | ~~Text~~ | |
Obfuscated | ??Text?? |
Events
You can define click and hover events with the commonly used MarkDown link syntax.
General syntax | [Text](text-color text-formatting... link hover text) |
Simple Link | [Text](https://example.com) |
Simple Command | [Text](/command to run) |
Link + Hover | [Text](https://example.com Hover Text) |
Text formatting + Link + Hover | [Text](blue underline https://example.com Hover Text) |
General syntax | [Text](action=value) | ClickEvent.Action , HoverEvent.Action |
Link | [Text](open_url=https://example.com) | |
Color | [Text](color=red) | |
RGB Hex Color | [Text](color=#ff00ff) | Full hexadecimal format |
RGB Hex Color | [Text](color=#f0f) | Short format (equivalent to long one) |
Formatting | [Text](format=underline,bold) | |
Font | [Text](format=underline,bold) | |
Run Command | [Text](run_command=/command string) | |
Suggest Command | [Text](suggest_command=/command) | |
Simple Hover | [Text](hover=Hover Text) | |
Hover Text | [Text](show_text=Hover Text) | |
Hover Entity Info | [Text](show_entity=uuid:pig Name) | |
Hover Item Info | [Text](show_item=stone*2 nbt...) |
All advanced settings can be chained/included in a event definition. You can't however add multiple different colors or click and hover actions!
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
COLOR_PREFIX
static java.lang.String
FONT_PREFIX
static java.lang.String
FORMAT_PREFIX
static java.lang.String
HOVER_PREFIX
static java.lang.String
INSERTION_PREFIX
-
Constructor Summary
Constructors Constructor Description MineDown(java.lang.String message)
Create a new MineDown builder with a certain message -
Method Summary
Modifier and Type Method Description MineDown
autoAddUrlPrefix(boolean enabled)
Automatically add http to values of open_url when there doesn't exist any? (Default: true)MineDown
colorChar(char colorChar)
Set a special character to replace color codes by if translating legacy colors is enabled.protected net.kyori.adventure.text.Component
components()
MineDown
copy()
Copy all MineDown settings to a new instanceMineDown
copy(MineDown from)
Copy all MineDown settings from another oneMineDown
disable(MineDownParser.Option option)
Disable an option.MineDown
enable(MineDownParser.Option option)
Enable an option.static java.lang.String
escape(java.lang.String string)
Escape all MineDown formatting in a string.MineDown
filter(MineDownParser.Option option)
Filter an option.static net.kyori.adventure.text.format.TextDecoration
getFormatFromChar(char c)
Get the TextColor format from a MineDown stringstatic java.lang.String
getFormatString(net.kyori.adventure.text.format.TextDecoration format)
Get the string that represents the format in MineDownMineDown
hoverTextWidth(int hoverTextWidth)
Set the max width the hover text should have.boolean
ignorePlaceholderCase()
Get whether or not the case of the placeholder should be ignored when replacingMineDown
ignorePlaceholderCase(boolean ignorePlaceholderCase)
Set whether or not the case of the placeholder should be ignored when replacingjava.lang.String
message()
Get the set message that is to be parsedMineDown
message(java.lang.String message)
Set the message that is to be parsedstatic net.kyori.adventure.text.Component
parse(java.lang.String message, java.lang.String... replacements)
Parse a MineDown string to componentsMineDownParser
parser()
Get the parser instance that is currently usedMineDown
placeholderIndicator(java.lang.String placeholderIndicator)
Set the placeholder indicator for both prefix and suffixjava.lang.String
placeholderPrefix()
Get the placeholder indicator's prefix characterMineDown
placeholderPrefix(java.lang.String placeholderPrefix)
Set the placeholder indicator's prefix characterjava.lang.String
placeholderSuffix()
Get the placeholder indicator's suffix characterMineDown
placeholderSuffix(java.lang.String placeholderSuffix)
Set the placeholder indicator's suffix characterMineDown
replace(java.lang.String... replacements)
Add an array with placeholders and values that should get replaced in the messageMineDown
replace(java.lang.String placeholder, net.kyori.adventure.text.Component replacement)
Add a placeholder to component mapping that should get replaced in the messageMineDown
replace(java.util.Map<java.lang.String,?> replacements)
Add a map with placeholders and values that should get replaced in the messageReplacer
replacer()
Get the replacer instance that is currently usedstatic java.lang.String
stringify(net.kyori.adventure.text.Component component)
Convert components to a MineDown stringnet.kyori.adventure.text.Component
toComponent()
Parse and convert the message to the componentMineDown
translateLegacyColors(boolean translateLegacyColors)
Deprecated.MineDown
unfilter(MineDownParser.Option option)
Unfilter an option.MineDown
urlDetection(boolean enabled)
Detect urls in strings and add events to them? (Default: true)MineDown
urlHoverText(java.lang.String text)
The text to display when hovering over an URLMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
FONT_PREFIX
public static final java.lang.String FONT_PREFIX- See Also:
- Constant Field Values
-
COLOR_PREFIX
public static final java.lang.String COLOR_PREFIX- See Also:
- Constant Field Values
-
FORMAT_PREFIX
public static final java.lang.String FORMAT_PREFIX- See Also:
- Constant Field Values
-
HOVER_PREFIX
public static final java.lang.String HOVER_PREFIX- See Also:
- Constant Field Values
-
INSERTION_PREFIX
public static final java.lang.String INSERTION_PREFIX- See Also:
- Constant Field Values
-
-
Constructor Details
-
MineDown
public MineDown(java.lang.String message)Create a new MineDown builder with a certain message- Parameters:
message
- The message to parse
-
-
Method Details
-
parse
public static net.kyori.adventure.text.Component parse(java.lang.String message, java.lang.String... replacements)Parse a MineDown string to components- Parameters:
message
- The message to translatereplacements
- Optional placeholder replacements- Returns:
- The parsed components
-
stringify
public static java.lang.String stringify(net.kyori.adventure.text.Component component)Convert components to a MineDown string- Parameters:
component
- The components to convert- Returns:
- The components represented as a MineDown string
-
toComponent
public net.kyori.adventure.text.Component toComponent()Parse and convert the message to the component- Returns:
- The parsed component message
-
replace
Add an array with placeholders and values that should get replaced in the message- Parameters:
replacements
- The replacements, nth element is the placeholder, n+1th the value- Returns:
- The MineDown instance
-
replace
Add a map with placeholders and values that should get replaced in the message- Parameters:
replacements
- The replacements mapped placeholder to value- Returns:
- The MineDown instance
-
replace
public MineDown replace(java.lang.String placeholder, net.kyori.adventure.text.Component replacement)Add a placeholder to component mapping that should get replaced in the message- Parameters:
placeholder
- The placeholder to replacereplacement
- The replacement component- Returns:
- The Replacer instance
-
placeholderIndicator
Set the placeholder indicator for both prefix and suffix- Parameters:
placeholderIndicator
- The character to use as a placeholder indicator- Returns:
- The MineDown instance
-
placeholderPrefix
Set the placeholder indicator's prefix character- Parameters:
placeholderPrefix
- The character to use as the placeholder indicator's prefix- Returns:
- The MineDown instance
-
placeholderPrefix
public java.lang.String placeholderPrefix()Get the placeholder indicator's prefix character- Returns:
- The placeholder indicator's prefix character
-
placeholderSuffix
Set the placeholder indicator's suffix character- Parameters:
placeholderSuffix
- The character to use as the placeholder indicator's suffix- Returns:
- The MineDown instance
-
placeholderSuffix
public java.lang.String placeholderSuffix()Get the placeholder indicator's suffix character- Returns:
- The placeholder indicator's suffix character
-
ignorePlaceholderCase
Set whether or not the case of the placeholder should be ignored when replacing- Parameters:
ignorePlaceholderCase
- Whether or not to ignore the case of the placeholders- Returns:
- The MineDown instance
-
ignorePlaceholderCase
public boolean ignorePlaceholderCase()Get whether or not the case of the placeholder should be ignored when replacing- Returns:
- Whether or not to ignore the case of the placeholders
-
translateLegacyColors
Deprecated.Enable or disable the translation of legacy color codes- Parameters:
translateLegacyColors
- Whether or not to translate legacy color codes (Default: true)- Returns:
- The MineDown instance
-
urlDetection
Detect urls in strings and add events to them? (Default: true)- Parameters:
enabled
- Whether or not to detect URLs and add events to them- Returns:
- The MineDown instance
-
autoAddUrlPrefix
Automatically add http to values of open_url when there doesn't exist any? (Default: true)- Parameters:
enabled
- Whether or not to automatically add http when missing- Returns:
- The MineDown instance
-
urlHoverText
The text to display when hovering over an URL- Parameters:
text
- The text to display when hovering over an URL- Returns:
- The MineDown instance
-
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 MineDown instance
-
enable
Enable an option. Unfilter it if you filtered it before.- Parameters:
option
- The option to enable- Returns:
- The MineDown instance
-
disable
Disable an option. Disabling an option will stop the parser from replacing this option's chars in the string. Usefilter(MineDownParser.Option)
to completely remove the characters used by this option from the message instead.- Parameters:
option
- The option to disable- Returns:
- The MineDown instance
-
filter
Filter an option. This completely removes the characters of this option from the string ignoring whether the option is enabled or not.- Parameters:
option
- The option to add to the filter- Returns:
- The MineDown instance
-
unfilter
Unfilter an option. Does not enable it!- Parameters:
option
- The option to remove from the filter- Returns:
- The MineDown instance
-
colorChar
Set a special character to replace color codes by if translating legacy colors is enabled.- Parameters:
colorChar
- The character to use as a special color code. (Default: ampersand &)- Returns:
- The MineDown instance
-
message
public java.lang.String message()Get the set message that is to be parsed- Returns:
- The to be parsed message
-
message
Set the message that is to be parsed- Parameters:
message
- The message to be parsed- Returns:
- The MineDown instance
-
replacer
Get the replacer instance that is currently used- Returns:
- The currently used replacer instance
-
parser
Get the parser instance that is currently used- Returns:
- The currently used parser instance
-
components
protected net.kyori.adventure.text.Component components() -
copy
Copy all MineDown settings to a new instance- Returns:
- The new MineDown instance with all settings copied
-
copy
Copy all MineDown settings from another one- Parameters:
from
- The MineDown to copy from- Returns:
- This MineDown instance
-
getFormatString
public static java.lang.String getFormatString(net.kyori.adventure.text.format.TextDecoration format)Get the string that represents the format in MineDown- Parameters:
format
- The format- Returns:
- The MineDown string or an empty one if it's not a format
-
getFormatFromChar
public static net.kyori.adventure.text.format.TextDecoration getFormatFromChar(char c)Get the TextColor format from a MineDown string- Parameters:
c
- The character- Returns:
- The TextColor of that format or
null
it none was found
-
escape
public static java.lang.String escape(java.lang.String string)Escape all MineDown formatting in a string. This will escape backslashes too!- Parameters:
string
- The string to escape in- Returns:
- The string with formatting escaped
-
enable(MineDownParser.Option)
anddisable(MineDownParser.Option)