@@ -53,28 +53,48 @@ object ComponentUtils {
5353 get() = fromMiniMessage(this )
5454
5555 val String .legacyColorCharParsed
56- get() = replace(" &0" , " <black>" )
57- .replace(" &1" , " <dark_blue>" )
58- .replace(" &2" , " <dark_green>" )
59- .replace(" &3" , " <dark_aqua>" )
60- .replace(" &4" , " <dark_red>" )
61- .replace(" &5" , " <dark_purple>" )
62- .replace(" &6" , " <gold>" )
63- .replace(" &7" , " <gray>" )
64- .replace(" &8" , " <dark_gray>" )
65- .replace(" &9" , " <blue>" )
66- .replace(" &[Aa]" .toRegex(), " <green>" )
67- .replace(" &[Bb]" .toRegex(), " <aqua>" )
68- .replace(" &[Cc]" .toRegex(), " <red>" )
69- .replace(" &[Dd]" .toRegex(), " <light_purple>" )
70- .replace(" &[Ee]" .toRegex(), " <yellow>" )
71- .replace(" &[Ff]" .toRegex(), " <white>" )
72- .replace(" &[Kk]" .toRegex(), " <obf>" )
73- .replace(" &[Ll]" .toRegex(), " <b>" )
74- .replace(" &[Mm]" .toRegex(), " <st>" )
75- .replace(" &[Nn]" .toRegex(), " <u>" )
76- .replace(" &[Oo]" .toRegex(), " <i>" )
77- .replace(" &[Rr]" .toRegex(), " <reset>" )
56+ get() = if (isEmpty()) this else buildString(this .length) {
57+ var last = this @legacyColorCharParsed[0 ]
58+ var i = 1
59+ while (i < this @legacyColorCharParsed.length) {
60+ if (last == ' &' ) {
61+ var parsed = true
62+ when (this @legacyColorCharParsed[i]) {
63+ ' 0' -> append(" <black>" )
64+ ' 1' -> append(" <dark_blue>" )
65+ ' 2' -> append(" <dark_green>" )
66+ ' 3' -> append(" <dark_aqua>" )
67+ ' 4' -> append(" <dark_red>" )
68+ ' 5' -> append(" <dark_purple>" )
69+ ' 6' -> append(" <gold>" )
70+ ' 7' -> append(" <gray>" )
71+ ' 8' -> append(" <dark_gray>" )
72+ ' 9' -> append(" <blue>" )
73+ ' A' , ' a' -> append(" <green>" )
74+ ' B' , ' b' -> append(" <aqua>" )
75+ ' C' , ' c' -> append(" <red>" )
76+ ' D' , ' d' -> append(" <light_purple>" )
77+ ' E' , ' e' -> append(" <yellow>" )
78+ ' F' , ' f' -> append(" <white>" )
79+ ' K' , ' k' -> append(" <obf>" )
80+ ' L' , ' l' -> append(" <b>" )
81+ ' M' , ' m' -> append(" <st>" )
82+ ' N' , ' n' -> append(" <u>" )
83+ ' O' , ' o' -> append(" <i>" )
84+ ' R' , ' r' -> append(" <reset>" )
85+ else -> {
86+ append(last)
87+ parsed = false
88+ }
89+ }
90+ if (parsed) i++
91+ } else {
92+ append(last)
93+ }
94+ last = this @legacyColorCharParsed[i++ ]
95+ }
96+ append(last)
97+ }
7898
7999 val Component .legacy
80100 get() = legacySerializer.serialize(this )
0 commit comments