Class MiniMessage

java.lang.Object
com.ranull.graves.integration.MiniMessage

public final class MiniMessage extends Object
Utility class for parsing MiniMessage formatted strings into legacy text format.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static net.kyori.adventure.platform.bukkit.BukkitAudiences
     
    private static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
     
    static net.kyori.adventure.text.minimessage.MiniMessage
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes a new MiniMessage instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    static net.kyori.adventure.text.Component
    Attempts to convert legacy color codes to Kyori's Adventure Text MiniMessage format.
    static String
    Attempts to convert legacy color codes to Kyori's Adventure Text MiniMessage format.
    static List<String>
    Attempts to convert legacy color codes to Kyori's Adventure Text MiniMessage format.
    static org.bukkit.inventory.ItemStack
    formatBookMeta(Graves plugin, Grave grave, org.bukkit.inventory.ItemStack itemStack, net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, List<net.kyori.adventure.text.Component> pages, List<net.kyori.adventure.text.Component> lore)
    Formats a written book's metadata (title, author, pages, lore, and optionally custom model data) using Adventure components and legacy section serialization.
    static net.kyori.adventure.text.minimessage.MiniMessage
    Gets a MiniMessage instance from the Adventure API.
    static String
    Parses a MiniMessage formatted string into a legacy text format.
    static List<String>
    Parses a list of MiniMessage formatted strings into legacy text formats.
    static void
    sendMessage(org.bukkit.entity.Player player, String message)
    Sends a formatted message to a player using MiniMessage, falling back to plain legacy format if MiniMessage is unavailable.

    Methods inherited from class java.lang.Object

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

    • miniMessage

      public static net.kyori.adventure.text.minimessage.MiniMessage miniMessage
    • audiences

      private static net.kyori.adventure.platform.bukkit.BukkitAudiences audiences
    • legacyComponentSerializer

      private static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer legacyComponentSerializer
  • Constructor Details

    • MiniMessage

      public MiniMessage()
      Initializes a new MiniMessage instance. Attempts to instantiate the MiniMessage parser. If the MiniMessage class is not found, the instance will be null.
  • Method Details

    • parseString

      public static List<String> parseString(List<String> strings)
      Parses a list of MiniMessage formatted strings into legacy text formats.
      Parameters:
      strings - The list of MiniMessage formatted strings to parse.
      Returns:
      A list of legacy text representations of the MiniMessage formatted strings. If MiniMessage is not initialized, returns the original list of strings.
    • parseString

      public static String parseString(String string)
      Parses a MiniMessage formatted string into a legacy text format.
      Parameters:
      string - The MiniMessage formatted string to parse.
      Returns:
      The legacy text representation of the MiniMessage formatted string. If MiniMessage is not initialized, returns the original string.
    • convertLegacyToMiniMessage

      public static List<String> convertLegacyToMiniMessage(List<String> legacyTexts)
      Attempts to convert legacy color codes to Kyori's Adventure Text MiniMessage format.
      Parameters:
      legacyTexts - The Legacy Text to be converted.
      Returns:
      All text to be converted to StringBuilder, that is required by net.kyori.adventure.text.minimessage
    • convertLegacyToMiniMessage

      public static String convertLegacyToMiniMessage(String legacyText)
      Attempts to convert legacy color codes to Kyori's Adventure Text MiniMessage format.
      Parameters:
      legacyText - The Legacy Text to be converted.
      Returns:
      All text to be converted to StringBuilder, that is required by net.kyori.adventure.text.minimessage
    • convertLegacyToComponent

      public static net.kyori.adventure.text.Component convertLegacyToComponent(String legacyText)
      Attempts to convert legacy color codes to Kyori's Adventure Text MiniMessage format.
      Parameters:
      legacyText - The Legacy Text to be converted.
      Returns:
      All text to be converted to StringBuilder, that is required by net.kyori.adventure.text.minimessage
    • formatBookMeta

      public static org.bukkit.inventory.ItemStack formatBookMeta(Graves plugin, Grave grave, org.bukkit.inventory.ItemStack itemStack, net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, List<net.kyori.adventure.text.Component> pages, List<net.kyori.adventure.text.Component> lore)
      Formats a written book's metadata (title, author, pages, lore, and optionally custom model data) using Adventure components and legacy section serialization.
      Parameters:
      plugin - The plugin instance used to access configuration.
      grave - The Grave instance associated with this book (used for configuration context).
      itemStack - The ItemStack to modify. Must be a written book or it will be returned unchanged.
      title - The title of the book, as an Adventure Component.
      author - The author of the book, as an Adventure Component.
      pages - A list of Adventure Components representing the pages of the book.
      lore - A list of Adventure Components representing the lore of the book.
      Returns:
      The updated ItemStack with modified book metadata, or the original ItemStack if invalid.
    • sendMessage

      public static void sendMessage(org.bukkit.entity.Player player, String message)
      Sends a formatted message to a player using MiniMessage, falling back to plain legacy format if MiniMessage is unavailable.
      Parameters:
      player - The player to send the message to.
      message - The message to send. This should be in legacy format if MiniMessage is enabled.
    • miniMessage

      public static net.kyori.adventure.text.minimessage.MiniMessage miniMessage()
      Gets a MiniMessage instance from the Adventure API.
      Returns:
      A singleton instance of MiniMessage.