Package com.ranull.graves.integration
Class MiniMessage
java.lang.Object
com.ranull.graves.integration.MiniMessage
Utility class for parsing MiniMessage formatted strings into legacy text format.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate 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 -
Method Summary
Modifier and TypeMethodDescriptionstatic net.kyori.adventure.text.Component
convertLegacyToComponent
(String legacyText) Attempts to convert legacy color codes to Kyori's Adventure Text MiniMessage format.static String
convertLegacyToMiniMessage
(String legacyText) Attempts to convert legacy color codes to Kyori's Adventure Text MiniMessage format.convertLegacyToMiniMessage
(List<String> legacyTexts) 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
parseString
(String string) Parses a MiniMessage formatted string into a legacy text format.parseString
(List<String> strings) 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.
-
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
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
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
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
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
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
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
.
-