Class MineDown

java.lang.Object
de.themoep.minedown.MineDown

public class MineDown extends Object

MineDown

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 ChatColor codes
Color &gold&Text ChatColor 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 Details

  • Constructor Details

    • MineDown

      public MineDown(String message)
      Create a new MineDown builder with a certain message
      Parameters:
      message - The message to parse
  • Method Details

    • parse

      public static net.md_5.bungee.api.chat.BaseComponent[] parse(String message, 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 String stringify(net.md_5.bungee.api.chat.BaseComponent[] components)
      Convert components to a MineDown string
      Parameters:
      components - The components to convert
      Returns:
      The components represented as a MineDown string
    • toComponent

      public net.md_5.bungee.api.chat.BaseComponent[] toComponent()
      Parse and convert the message to the component
      Returns:
      The parsed component message
    • replaceFirst

      public MineDown replaceFirst(boolean 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

      public MineDown replace(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(Map<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(String placeholder, net.md_5.bungee.api.chat.BaseComponent... replacement)
      Add a placeholder to component mapping that should get replaced in the message
      Parameters:
      placeholder - The placeholder to replace
      replacement - The replacement components
      Returns:
      The Replacer instance
    • placeholderIndicator

      public MineDown placeholderIndicator(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(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 String placeholderPrefix()
      Get the placeholder indicator's prefix character
      Returns:
      The placeholder indicator's prefix character
    • placeholderSuffix

      public MineDown placeholderSuffix(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 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(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 String message()
      Get the set message that is to be parsed
      Returns:
      The to be parsed message
    • message

      public MineDown message(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
    • baseComponents

      protected net.md_5.bungee.api.chat.BaseComponent[] baseComponents()
    • 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 String getFormatString(net.md_5.bungee.api.ChatColor 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.md_5.bungee.api.ChatColor getFormatFromChar(char c)
      Get the ChatColor format from a MineDown string
      Parameters:
      c - The character
      Returns:
      The ChatColor of that format or null it none was found
    • escape

      public static String escape(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