@@ -891,6 +891,7 @@ public static class MessagePart {
891
891
private MessageEvent onClick ;
892
892
private MessageEvent onHover ;
893
893
private String color ;
894
+ private ChatColor legacyColor ;
894
895
private String font ;
895
896
private String text ;
896
897
@@ -938,9 +939,12 @@ public JsonObject toJSON() {
938
939
*/
939
940
public String toLegacy () {
940
941
StringBuilder output = new StringBuilder ();
941
- if (color != null ) {
942
- output .append (color );
942
+ ChatColor legacyColor = getColor ();
943
+
944
+ if (legacyColor != null ) {
945
+ output .append (legacyColor );
943
946
}
947
+
944
948
styles .stream ()
945
949
.map (ChatColor ::toString )
946
950
.forEach (output ::append );
@@ -989,6 +993,10 @@ public String getColorValue() {
989
993
*/
990
994
@ Deprecated
991
995
public ChatColor getColor () {
996
+ if (legacyColor != null ) {
997
+ return legacyColor ;
998
+ }
999
+
992
1000
if (this .color .startsWith ("#" ) && ReflectionHelper .MAJOR_VER < 16 )
993
1001
throw new IllegalStateException ("Custom Hex colors can only be used in Minecraft 1.16 or newer!" );
994
1002
@@ -1005,14 +1013,15 @@ public ChatColor getColor() {
1005
1013
*/
1006
1014
@ Deprecated
1007
1015
public void setColor (ChatColor color ) {
1008
- setColor (color .name ().toLowerCase ());
1016
+ setColor (color == null ? null : color .name ().toLowerCase ());
1017
+ legacyColor = color ;
1009
1018
}
1010
1019
1011
1020
/**
1012
1021
* @param color The color to set
1013
1022
*/
1014
1023
public void setColor (String color ) {
1015
- if (color == null || color .isEmpty ()) {
1024
+ if (color != null && color .isEmpty ()) {
1016
1025
throw new IllegalArgumentException ("Color cannot be null!" );
1017
1026
}
1018
1027
this .color = color ;
0 commit comments