Convert ChatColor to a class from an enum and make it hold string constants

This is because Minecraft now supports any color in chat and anywhere JSON messages are used. Thus, the ChatColor enum has been converted to a class and now holds string constants with the previous string colors, which are still supported.
This commit is contained in:
RednedEpic 2020-04-22 16:19:58 -05:00
parent f39b2a0a23
commit 5dae5286db
3 changed files with 24 additions and 40 deletions

View file

@ -1,38 +1,22 @@
package com.github.steveice10.mc.protocol.data.message;
public enum ChatColor {
BLACK,
DARK_BLUE,
DARK_GREEN,
DARK_AQUA,
DARK_RED,
DARK_PURPLE,
GOLD,
GRAY,
DARK_GRAY,
BLUE,
GREEN,
AQUA,
RED,
LIGHT_PURPLE,
YELLOW,
WHITE,
RESET,
NONE;
public static ChatColor byName(String name) {
name = name.toLowerCase();
for(ChatColor color : values()) {
if(color.toString().equals(name)) {
return color;
}
}
return null;
}
@Override
public String toString() {
return this.name().toLowerCase();
}
public class ChatColor {
public static final String BLACK = "black";
public static final String DARK_BLUE = "dark_blue";
public static final String DARK_GREEN = "dark_green";
public static final String DARK_AQUA = "dark_aqua";
public static final String DARK_RED = "dark_red";
public static final String DARK_PURPLE = "dark_purple";
public static final String GOLD = "gold";
public static final String GRAY = "gray";
public static final String DARK_GRAY = "dark_gray";
public static final String BLUE = "blue";
public static final String GREEN = "green";
public static final String AQUA = "aqua";
public static final String RED = "red";
public static final String LIGHT_PURPLE = "light_purple";
public static final String YELLOW = "yellow";
public static final String WHITE = "white";
public static final String RESET = "reset";
public static final String NONE = "none";
}

View file

@ -68,7 +68,7 @@ public abstract class Message implements Cloneable {
MessageStyle style = new MessageStyle();
if(json.has("color")) {
style.setColor(ChatColor.byName(json.get("color").getAsString()));
style.setColor(json.get("color").getAsString());
}
for(ChatFormat format : ChatFormat.values()) {

View file

@ -12,7 +12,7 @@ import java.util.List;
public class MessageStyle implements Cloneable {
private static final MessageStyle DEFAULT = new MessageStyle();
private ChatColor color = ChatColor.NONE;
private String color = ChatColor.NONE;
private List<ChatFormat> formats = new ArrayList<ChatFormat>();
private ClickEvent clickEvent;
private HoverEvent hoverEvent;
@ -24,16 +24,16 @@ public class MessageStyle implements Cloneable {
}
public boolean hasColor() {
return color != ChatColor.NONE;
return !color.equals(ChatColor.NONE);
}
public MessageStyle setColor(ChatColor color) {
public MessageStyle setColor(String color) {
this.color = color;
return this;
}
public MessageStyle setFormats(List<ChatFormat> formats) {
this.formats = new ArrayList<ChatFormat>(formats);
this.formats = new ArrayList<>(formats);
return this;
}