Skip to content

Commit

Permalink
Prevent errors using MiniMessage mode on Velocity.
Browse files Browse the repository at this point in the history
  • Loading branch information
frafol committed Jun 30, 2024
1 parent baae984 commit 9828e1f
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ private String translateHexToMinecraftColorCode(String hex) {
}

private boolean containsHexColor(String message) {
String[] hexColorPattern = new String[]{"#[a-fA-F0-9]{6}", "&#[a-fA-F0-9]{6}", "<#[a-fA-F0-9]]{6}>"};
String[] hexColorPattern;
if (VelocityConfig.MINIMESSAGE.get(Boolean.class)) {
hexColorPattern = new String[]{"#[a-fA-F0-9]{6}", "&#[a-fA-F0-9]{6}"};
} else {
hexColorPattern = new String[]{"#[a-fA-F0-9]{6}", "&#[a-fA-F0-9]{6}", "<#[a-fA-F0-9]]{6}>"};
}

for (String pattern : hexColorPattern) {
if (Pattern.compile(pattern).matcher(message).find()) {
return true;
Expand All @@ -192,6 +198,14 @@ public void send(CommandSource commandSource, Placeholder... placeholders) {

if (commandSource instanceof Player) {
if (VelocityConfig.MINIMESSAGE.get(Boolean.class)) {

if (ChatUtil.hasColorCodes(get(String.class))) {
instance.getLogger().error("Legacy color codes are not supported in MiniMessage mode.");
instance.getLogger().error("Please remove them from the message: {} in the messages.yml file.", getPath());
commandSource.sendMessage(LegacyComponentSerializer.legacy('§').deserialize(ChatUtil.getFormattedString((Player) commandSource,this, placeholders)));
return;
}

commandSource.sendMessage(getMiniMessage().deserialize(ChatUtil.getFormattedString((Player) commandSource, this, placeholders)));
return;
}
Expand All @@ -201,6 +215,14 @@ public void send(CommandSource commandSource, Placeholder... placeholders) {
}

if (VelocityConfig.MINIMESSAGE.get(Boolean.class)) {

if (ChatUtil.hasColorCodes(get(String.class))) {
instance.getLogger().error("Legacy color codes are not supported in MiniMessage mode.");
instance.getLogger().error("Please remove them from the message: {} in the messages.yml file.", getPath());
commandSource.sendMessage(LegacyComponentSerializer.legacy('§').deserialize(ChatUtil.getFormattedString(this, placeholders)));
return;
}

commandSource.sendMessage(getMiniMessage().deserialize(ChatUtil.getFormattedString(this, placeholders)));
return;
}
Expand Down

0 comments on commit 9828e1f

Please sign in to comment.