Class ChatParser


  • public class ChatParser
    extends Object
    Handles parsing raw strings into rich json components with hover/click events.
    Author:
    Majekdor
    • Constructor Detail

      • ChatParser

        public ChatParser()
    • Method Detail

      • parse

        public ChatParser parse​(String string,
                                int start)
        Parse the provided string starting at the provided start location. This will find all functions and format them into Components. If there is an error parsing the text this will throw ChatParser.ParseException.
        Parameters:
        string - The string containing the functions to parse.
        start - The location to start parsing in the string.
        Returns:
        Instance of itself. Use getAsComponent(), getAsBaseComponent(), or getAsRawString() to finish the process.
      • parse

        public ChatParser parse​(String delimiter,
                                String... strings)
        Parse the provided strings starting at the beginning. This will find all functions and format them into Components. If there is an error parsing the text this will throw ChatParser.ParseException.
        Parameters:
        strings - These strings will be joined using the provided delimiter.
        delimiter - The delimiter to join the string with.
        Returns:
        Instance of itself. Use getAsComponent(), getAsBaseComponent(), or getAsRawString() to finish the process.
      • insertItemHover

        public ChatParser insertItemHover​(String target,
                                          String replacement,
                                          org.bukkit.inventory.ItemStack hover)
        Insert a hover item on a certain bit of text in the component.
        Parameters:
        target - The current text to target for the hover event.
        replacement - The replacement for the current text.
        hover - The ItemStack to create a hover event from.
        Returns:
        Instance of itself. Use getAsComponent(), getAsBaseComponent(), or getAsRawString() to finish the process.
      • getAsBaseComponent

        public net.md_5.bungee.api.chat.BaseComponent[] getAsBaseComponent()
        Get the parsed string as an array of BaseComponents.
        Returns:
        BaseComponent array of the parsed string.
      • getAsComponent

        public net.kyori.adventure.text.Component getAsComponent()
        Get the parsed string as a Component.
        Returns:
        Component of the parsed string.
      • getAsRawString

        public String getAsRawString()
        Get the parsed string as a raw string. This will remove all hover and click events but retain colors. If you want to clear colors as well call clearColors() before this.
        Returns:
        Raw string of parsed string.