Class MineDownParser

java.lang.Object
de.themoep.minedown.adventure.MineDownParser

public class MineDownParser
extends java.lang.Object
  • 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.IllegalArgumentException
      Create a ComponentBuilder by parsing a MineDown 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 a MineDown event string
      Parameters:
      text - The display text
      definitions - The event definition string
      Returns:
      The parsed ComponentBuilder for this string
    • builder

      protected net.kyori.adventure.text.ComponentBuilder builder()
    • builder

      protected MineDownParser builder​(net.kyori.adventure.text.ComponentBuilder builder)
    • value

      protected MineDownParser value​(java.lang.StringBuilder value)
    • value

      protected java.lang.StringBuilder value()
    • font

      protected java.lang.String font()
    • insertion

      protected java.lang.String insertion()
    • color

      protected MineDownParser color​(net.kyori.adventure.text.format.TextColor color)
    • color

      protected net.kyori.adventure.text.format.TextColor color()
    • 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()
    • clickEvent

      protected MineDownParser clickEvent​(net.kyori.adventure.text.event.ClickEvent clickEvent)
    • clickEvent

      protected net.kyori.adventure.text.event.ClickEvent clickEvent()
    • hoverEvent

      protected MineDownParser hoverEvent​(net.kyori.adventure.text.event.HoverEvent hoverEvent)
    • hoverEvent

      protected net.kyori.adventure.text.event.HoverEvent hoverEvent()
    • parse

      public static net.kyori.adventure.text.format.TextFormat parse​(java.lang.String colorString, java.lang.String prefix, boolean lenient)
      Parse a color/format definition
      Parameters:
      colorString - The string to parse
      prefix - 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

      public MineDownParser copy()
      Copy all the parser's setting to a new instance
      Returns:
      The new parser instance with all settings copied
    • copy

      public MineDownParser copy​(boolean formatting)
      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

      public MineDownParser copy​(MineDownParser from)
      Copy all the parser's settings from another parser.
      Parameters:
      from - The parser to copy from
      Returns:
      This parser's instance
    • copy

      public MineDownParser copy​(MineDownParser from, boolean formatting)
      Copy all the parser's settings from another parser.
      Parameters:
      from - The parser to copy from
      formatting - Should the formatting be copied too?
      Returns:
      This parser's instance
    • reset

      public MineDownParser reset()
      Reset the parser state to the start
      Returns:
      The parser's instance
    • translateLegacyColors

      @Deprecated public boolean translateLegacyColors()
      Deprecated.
      Use isEnabled(Option) instead
      Whether or not to translate legacy color codes (Default: true)
      Returns:
      Whether or not to translate legacy color codes (Default: true)
    • translateLegacyColors

      @Deprecated public MineDownParser translateLegacyColors​(boolean enabled)
      Deprecated.
      Whether or not to translate legacy color codes
      Returns:
      The parser
    • isEnabled

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

      public MineDownParser enable​(MineDownParser.Option option)
      Enable an option.
      Parameters:
      option - The option to enable
      Returns:
      The parser instace
    • disable

      public MineDownParser 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(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

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

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

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

      public MineDownParser colorChar​(char colorChar)
      Set the character to use as a special color code.
      Parameters:
      colorChar - The color char (Default: ampersand &)
      Returns:
      The MineDownParser instance
    • enabledOptions

      public java.util.Set<MineDownParser.Option> enabledOptions()
      Get all enabled options that will be used when parsing
      Returns:
      a modifiable set of options
    • enabledOptions

      public MineDownParser enabledOptions​(java.util.Set<MineDownParser.Option> 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

      public java.util.Set<MineDownParser.Option> filteredOptions()
      Get all filtered options that will be parsed and then removed from the string
      Returns:
      a modifiable set of options
    • filteredOptions

      public MineDownParser 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 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

      public MineDownParser lenient​(boolean 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

      public MineDownParser urlDetection​(boolean 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

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

      public MineDownParser autoAddUrlPrefix​(boolean 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

      public MineDownParser 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 MineDownParser instance