ColorParser
Usage

Basic Usage

Don't forget to check out the MiniMessage Documentation (opens in a new tab) so you can style messages to their full potential!

Simple Example

A ColorParser is always instantiated with the ColorParser#of(String str) method. The string is only serialized into a Component when ColorParser#build() is executed (Which returns the Component).

This is the simplest example of serializing a MiniMessage string into a Component.

ColorParser.of("<green>Teleported to you.").build();

Methods

parseMinimessagePlaceholder

The parseMinimessagePlaceholder() method allows you to dynamically replace custom tags with a String or any ComponentLike value.

player.sendMessage(
    ColorParser.of("<green><player> Teleported to you.")
        .parseMinimessagePlaceholder("player", player.getName()) // Replace <player> with the players username
        .build();
);

parseLegacy

The parseLegacy() method replaces all old color & style tags with their MiniMessage equivalents.

player.sendMessage(
    ColorParser.of("&6So<green>me §5String &4Here")
        .parseLegacy() // You only need to run this once to replace all legacy formatting codes
        .build();
);

parsePAPIPlaceholders

If PAPI isn't installed on the server this method does nothing.

You can use this method to parse PlaceholderAPI placeholders.

Component message = ColorParser.of("Your Displayname is: %player_displayname%")
    .parsePAPIPlaceholders(player)
    .build();
 
player.sendMessage(message);

Examples

Custom message color and hover message.

player.sendMessage(
    ColorParser.of("<#00ff00><hover:show_text:'<red>test'>R G B!")
        .build();
);

Add as many placeholders as you'd like, and have backwards compatibility!

player.sendMessage(
    ColorParser.of("<green><player1> Teleported &6to <player2>.")
        .parseMinimessagePlaceholder("player1", player.getName())
        .parseMinimessagePlaceholder("player2", otherPlayer.getName())
        .parseLegacy()
        .build();
);
player.sendMessage(
    ColorParser.of("Your Displayname is: %player_displayname%")
        .parsePAPIPlaceholders(player)
        .build();
);