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 components

This 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.

Inline Formatting
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.

Simple 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)

Advanced Syntax
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 instance
    MineDown copy​(MineDown from)
    Copy all MineDown settings from another one
    MineDown 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 string
    static java.lang.String getFormatString​(net.kyori.adventure.text.format.TextDecoration format)
    Get the string that represents the format in MineDown
    MineDown 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 replacing
    MineDown ignorePlaceholderCase​(boolean ignorePlaceholderCase)
    Set whether or not the case of the placeholder should be ignored when replacing
    java.lang.String message()
    Get the set message that is to be parsed
    MineDown message​(java.lang.String message)
    Set the message that is to be parsed
    static net.kyori.adventure.text.Component parse​(java.lang.String message, java.lang.String... replacements)
    Parse a MineDown string to components
    MineDownParser parser()
    Get the parser instance that is currently used
    MineDown placeholderIndicator​(java.lang.String placeholderIndicator)
    Set the placeholder indicator for both prefix and suffix
    java.lang.String placeholderPrefix()
    Get the placeholder indicator's prefix character
    MineDown placeholderPrefix​(java.lang.String placeholderPrefix)
    Set the placeholder indicator's prefix character
    java.lang.String placeholderSuffix()
    Get the placeholder indicator's suffix character
    MineDown placeholderSuffix​(java.lang.String placeholderSuffix)
    Set the placeholder indicator's suffix character
    MineDown replace​(java.lang.String... replacements)
    Add an array with placeholders and values that should get replaced in the message
    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
    MineDown replace​(java.util.Map<java.lang.String,​?> replacements)
    Add a map with placeholders and values that should get replaced in the message
    Replacer replacer()
    Get the replacer instance that is currently used
    static java.lang.String stringify​(net.kyori.adventure.text.Component component)
    Convert components to a MineDown string
    net.kyori.adventure.text.Component toComponent()
    Parse and convert the message to the component
    MineDown translateLegacyColors​(boolean translateLegacyColors)
    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 URL

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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 translate
      replacements - 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

      public MineDown replace​(java.lang.String... replacements)
      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

      public MineDown replace​(java.util.Map<java.lang.String,​?> replacements)
      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 replace
      replacement - The replacement component
      Returns:
      The Replacer instance
    • placeholderIndicator

      public MineDown placeholderIndicator​(java.lang.String 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

      public MineDown placeholderPrefix​(java.lang.String 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

      public MineDown placeholderSuffix​(java.lang.String 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

      public MineDown ignorePlaceholderCase​(boolean 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 public MineDown translateLegacyColors​(boolean translateLegacyColors)
      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

      public MineDown urlDetection​(boolean enabled)
      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

      public MineDown autoAddUrlPrefix​(boolean enabled)
      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

      public MineDown urlHoverText​(java.lang.String text)
      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

      public MineDown hoverTextWidth​(int 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

      public MineDown enable​(MineDownParser.Option option)
      Enable an option. Unfilter it if you filtered it before.
      Parameters:
      option - The option to enable
      Returns:
      The MineDown instance
    • disable

      public MineDown disable​(MineDownParser.Option option)
      Disable an option. Disabling an option will stop the parser from replacing this option's chars in the string. Use filter(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

      public MineDown filter​(MineDownParser.Option option)
      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

      public MineDown unfilter​(MineDownParser.Option option)
      Unfilter an option. Does not enable it!
      Parameters:
      option - The option to remove from the filter
      Returns:
      The MineDown instance
    • colorChar

      public MineDown colorChar​(char 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

      public MineDown message​(java.lang.String message)
      Set the message that is to be parsed
      Parameters:
      message - The message to be parsed
      Returns:
      The MineDown instance
    • replacer

      public Replacer replacer()
      Get the replacer instance that is currently used
      Returns:
      The currently used replacer instance
    • parser

      public MineDownParser parser()
      Get the parser instance that is currently used
      Returns:
      The currently used parser instance
    • components

      protected net.kyori.adventure.text.Component components()
    • copy

      public MineDown copy()
      Copy all MineDown settings to a new instance
      Returns:
      The new MineDown instance with all settings copied
    • copy

      public MineDown copy​(MineDown from)
      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