package fr.pandacube.lib.util; /** * Provides utility methods around Minecraft and Web stuff. */ public class MinecraftWebUtil { /** * Convert a legacy Minecraft color coded String into HTML Format. *
* Each colored part of the text will be contained in a {@code } tag with {@code class="cX"} where {@code X}
* is the color code from 0 to F in uppercase.
* The bold, struck, underlined and italic parts will be contained in a {@code } tag with respectively the
* classes {@code cL}, {@code cM}, {@code cN} and {@code cO}.
* Some CSS properties are needed to apply the colors to the CSS classes.
* @param chatColorPrefix the prefix used for the color codes
* @param legacyText the legacy text to convert to HTML.
* @return The text formatted in HTML.
* @implNote the current implementation does not yet support the RGB colors.
*/
// TODO update to support RGB colors (Bungee and Essentials notation). (see JS implementation at https://www.pandacube.fr/assets/js/global.js )
// TODO moves this to pandalib-chat and use Adventure API to help serializing to HTML
public static String fromMinecraftColorCodeToHTML(char chatColorPrefix, String legacyText)
{
String color_char = "0123456789abcdefr";
StringBuilder builder = new StringBuilder();
char currentColor = 'r';
boolean bold = false, italic = false, underlined = false, strikethrough = false;
for (int i=0; i