@@ -20,6 +20,8 @@ object Hex {
2020 Pattern .compile(" <(?<type>rainbow|r)(#(?<speed>\\ d+))?(:(?<saturation>\\ d*\\ .?\\ d+))?(:(?<brightness>\\ d*\\ .?\\ d+))?(:(?<loop>l|L|loop))?>" )
2121 private val GRADIENT_PATTERN =
2222 Pattern .compile(" <(?<type>gradient|g)(#(?<speed>\\ d+))?(?<hex>(:#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})){2,})(:(?<loop>l|L|loop))?>" )
23+ private val LEGACY_HEX_PATTERN =
24+ Pattern .compile(" &\\ {#([A-Fa-f0-9]){6}}" ) // &{#FFFFFF}
2325 private val HEX_PATTERNS = listOf (
2426 Pattern .compile(" <#([A-Fa-f0-9]){6}>" ), // <#FFFFFF>
2527 Pattern .compile(" \\ {#([A-Fa-f0-9]){6}}" ), // {#FFFFFF}
@@ -70,8 +72,9 @@ object Hex {
7072 * @param message The message
7173 * @return A color-replaced message
7274 */
73- private fun colorify (message : String ): String {
75+ internal fun colorify (message : String ): String {
7476 var parsed = message
77+ parsed = normalizeLegacyHex(parsed)
7578 parsed = parseRainbow(parsed)
7679 parsed = parseGradients(parsed)
7780 parsed = parseHex(parsed)
@@ -222,6 +225,11 @@ object Hex {
222225 return ChatColor .translateAlternateColorCodes(' &' , message)
223226 }
224227
228+ private fun normalizeLegacyHex (message : String ): String {
229+ val matcher = LEGACY_HEX_PATTERN .matcher(message)
230+ return if (matcher.find()) matcher.replaceAll(" &#\$ 1" ) else message
231+ }
232+
225233 /* *
226234 * Returns the index before the color changes
227235 *
@@ -422,5 +430,6 @@ object Hex {
422430 }
423431}
424432
433+ fun String.colorify () = Hex .colorify(this )
425434fun String.parseRainbow () = Hex .parseRainbow(this )
426435fun String.parseGradients () = Hex .parseGradients(this )
0 commit comments