Package de.themoep.minedown.adventure
Class MineDown
java.lang.Object
de.themoep.minedown.adventure.MineDown
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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionautoAddUrlPrefix
(boolean enabled) Automatically add http to values of open_url when there doesn't exist any? (Default: true)colorChar
(char colorChar) Set a special character to replace color codes by if translating legacy colors is enabled.protected net.kyori.adventure.text.Component
copy()
Copy all MineDown settings to a new instanceCopy all MineDown settings from another onedisable
(MineDownParser.Option option) Disable an option.enable
(MineDownParser.Option option) Enable an option.static String
Escape all MineDown formatting in a string.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 String
getFormatString
(net.kyori.adventure.text.format.TextDecoration format) Get the string that represents the format in MineDownhoverTextWidth
(int hoverTextWidth) Set the max width the hover text should have.boolean
Get whether or not the case of the placeholder should be ignored when replacingignorePlaceholderCase
(boolean ignorePlaceholderCase) Set whether or not the case of the placeholder should be ignored when replacingmessage()
Get the set message that is to be parsedSet the message that is to be parsedstatic net.kyori.adventure.text.Component
Parse a MineDown string to componentsparser()
Get the parser instance that is currently usedplaceholderIndicator
(String placeholderIndicator) Set the placeholder indicator for both prefix and suffixGet the placeholder indicator's prefix characterplaceholderPrefix
(String placeholderPrefix) Set the placeholder indicator's prefix characterGet the placeholder indicator's suffix characterplaceholderSuffix
(String placeholderSuffix) Set the placeholder indicator's suffix characterAdd an array with placeholders and values that should get replaced in the messageAdd a placeholder to component mapping that should get replaced in the messageAdd a map with placeholders and values that should get replaced in the messageboolean
Get whether or not replacements should be replaced before or after the components are created.replaceFirst
(boolean replaceFirst) Set whether or not replacements should be replaced before or after the components are created.replacer()
Get the replacer instance that is currently usedstatic String
stringify
(net.kyori.adventure.text.Component component) Convert components to a MineDown stringnet.kyori.adventure.text.Component
Parse and convert the message to the componenttranslateLegacyColors
(boolean translateLegacyColors) Deprecated.unfilter
(MineDownParser.Option option) Unfilter an option.urlDetection
(boolean enabled) Detect urls in strings and add events to them? (Default: true)urlHoverText
(String text) The text to display when hovering over an URL
-
Field Details
-
FONT_PREFIX
- See Also:
-
COLOR_PREFIX
- See Also:
-
FORMAT_PREFIX
- See Also:
-
HOVER_PREFIX
- See Also:
-
INSERTION_PREFIX
- See Also:
-
-
Constructor Details
-
MineDown
Create a new MineDown builder with a certain message- Parameters:
message
- The message to parse
-
-
Method Details
-
parse
Parse a MineDown string to components- Parameters:
message
- The message to translatereplacements
- Optional placeholder replacements- Returns:
- The parsed components
-
stringify
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
-
replaceFirst
Set whether or not replacements should be replaced before or after the components are created. When replacing first it will not replace any placeholders with component replacement values! Default is after. (replaceFirst = false)- Parameters:
replaceFirst
- Whether or not to replace first or parse first- Returns:
- The MineDown instance
-
replaceFirst
public boolean replaceFirst()Get whether or not replacements should be replaced before or after the components are created. When replacing first it will not replace any placeholders with component replacement values! Default is after. (replaceFirst = false)- Returns:
- Whether or not to replace first or parse first
-
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
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
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
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
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
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
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)