Add escape for Discord syntax (#41)

1.16
Etzelia 2019-10-05 04:22:50 +02:00 committed by Gitea
parent 6d73df72a3
commit ee0867d5cc
1 changed files with 37 additions and 22 deletions

View File

@ -45,30 +45,45 @@ public class AsyncPlayerChatListener implements Listener {
// Discord syntax for font emphasis
if (player.hasPermission("qol.discord")) {
String chat = event.getMessage();
Pattern syntax;
Matcher matcher;
for (int i = 0; i < discordSyntax.size(); i++) {
syntax = discordSyntax.get(i);
matcher = syntax.matcher(chat);
switch (i) {
case 0:
chat = matcher.replaceAll("&n$1&r");
break;
case 1:
case 3:
chat = matcher.replaceAll("&o$1&r");
break;
case 2:
chat = matcher.replaceAll("&l$1&r");
break;
case 4:
chat = matcher.replaceAll("&m$1&r");
break;
default:
break;
boolean escape = false;
// Escape
if (chat.startsWith("\\")) {
escape = true;
event.setMessage(chat.substring(1));
// Escape the escape, this monster wants to start their message with a backslash
if (chat.startsWith("\\\\")) {
escape = false;
}
}
event.setMessage(ChatColor.translateAlternateColorCodes('&', chat));
if (!escape) {
Pattern syntax;
Matcher matcher;
for (int i = 0; i < discordSyntax.size(); i++) {
syntax = discordSyntax.get(i);
matcher = syntax.matcher(chat);
switch (i) {
case 0:
chat = matcher.replaceAll("&n$1&r");
break;
case 1:
case 3:
chat = matcher.replaceAll("&o$1&r");
break;
case 2:
chat = matcher.replaceAll("&l$1&r");
break;
case 4:
chat = matcher.replaceAll("&m$1&r");
break;
default:
break;
}
}
event.setMessage(ChatColor.translateAlternateColorCodes('&', chat));
}
}
}