Skip to content

Commit e6ae829

Browse files
committed
Better handling of legacy colors & actionbars
1 parent 84bd517 commit e6ae829

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/main/java/me/rayzr522/jsonmessage/JSONMessage.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ public static class MessagePart {
891891
private MessageEvent onClick;
892892
private MessageEvent onHover;
893893
private String color;
894+
private ChatColor legacyColor;
894895
private String font;
895896
private String text;
896897

@@ -938,9 +939,12 @@ public JsonObject toJSON() {
938939
*/
939940
public String toLegacy() {
940941
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);
943946
}
947+
944948
styles.stream()
945949
.map(ChatColor::toString)
946950
.forEach(output::append);
@@ -989,6 +993,10 @@ public String getColorValue() {
989993
*/
990994
@Deprecated
991995
public ChatColor getColor() {
996+
if (legacyColor != null) {
997+
return legacyColor;
998+
}
999+
9921000
if (this.color.startsWith("#") && ReflectionHelper.MAJOR_VER < 16)
9931001
throw new IllegalStateException("Custom Hex colors can only be used in Minecraft 1.16 or newer!");
9941002

@@ -1005,14 +1013,15 @@ public ChatColor getColor() {
10051013
*/
10061014
@Deprecated
10071015
public void setColor(ChatColor color) {
1008-
setColor(color.name().toLowerCase());
1016+
setColor(color == null ? null : color.name().toLowerCase());
1017+
legacyColor = color;
10091018
}
10101019

10111020
/**
10121021
* @param color The color to set
10131022
*/
10141023
public void setColor(String color) {
1015-
if (color == null || color.isEmpty()) {
1024+
if (color != null && color.isEmpty()) {
10161025
throw new IllegalArgumentException("Color cannot be null!");
10171026
}
10181027
this.color = color;

0 commit comments

Comments
 (0)