No hex codes in console.

This commit is contained in:
Brianna 2020-11-09 12:45:18 -06:00
parent a42ed32460
commit eb1f40f040
3 changed files with 14 additions and 6 deletions

View File

@ -31,6 +31,10 @@ public class ChatMessage {
}
public ChatMessage fromText(String text) {
return fromText(text, false);
}
public ChatMessage fromText(String text, boolean noHex) {
Pattern pattern = Pattern.compile("(.*?)(?!&(o|m|n|l|k))(?=(\\&(1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|r|#)|$)|"
+ "#([a-f]|[A-F]|[0-9]){6})", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(text);
@ -44,7 +48,7 @@ public class ChatMessage {
colorChar = text.substring(matcher.start() - 1, matcher.start()).charAt(0);
if (colorChar != '-') {
if (colorChar == '#') {
color = new ColorContainer(match1.substring(0, 6));
color = new ColorContainer(match1.substring(0, 6), noHex);
match1 = match1.substring(5);
} else if (colorChar == '&')
color = new ColorContainer(ColorCode.getByChar(match1.charAt(0)));
@ -69,13 +73,17 @@ public class ChatMessage {
}
public String toText() {
return toText(false);
}
public String toText(boolean noHex) {
StringBuilder text = new StringBuilder();
for (JsonObject object : textList) {
if (object.has("color")) {
String color = object.get("color").getAsString();
text.append("&");
if (color.length() == 7) {
text.append(new ColorContainer(color).getColor().getCode());
text.append(new ColorContainer(color, noHex).getColor().getCode());
} else {
text.append(ColorCode.valueOf(color.toUpperCase()).getCode());
}
@ -191,7 +199,7 @@ public class ChatMessage {
enabled = false;
}
} else {
sender.sendMessage(TextUtils.formatText((prefix == null ? "" : prefix.toText() + " ") + toText()));
sender.sendMessage(TextUtils.formatText((prefix == null ? "" : prefix.toText(true) + " ") + toText(true)));
}
}

View File

@ -15,9 +15,9 @@ public class ColorContainer {
this.hexCode = null;
}
public ColorContainer(String hexCode) {
public ColorContainer(String hexCode, boolean noHex) {
this.hexCode = hexCode;
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_16)) {
if (noHex || ServerVersion.isServerVersionBelow(ServerVersion.V1_16)) {
this.colorCode = getColor();
this.hexCode = null;
}

View File

@ -59,7 +59,7 @@ public class MainCommand extends AbstractCommand {
sender.sendMessage(header);
} else {
new ChatMessage().fromText(String.format("#ff8080&l%s &8» &7Version %s Created with <3 by #ec4e74&l&oS#fa5b65&l&oo#ff6c55&l&on#ff7f44&l&og#ff9432&l&oo#ffaa1e&l&od#f4c009&l&oa",
plugin.getDescription().getName(), plugin.getDescription().getVersion()))
plugin.getDescription().getName(), plugin.getDescription().getVersion()), true)
.sendTo(sender);
}