forked from Minecraft/QoL
Add escape for Discord syntax (#41)
parent
6d73df72a3
commit
ee0867d5cc
|
@ -45,30 +45,45 @@ public class AsyncPlayerChatListener implements Listener {
|
||||||
// Discord syntax for font emphasis
|
// Discord syntax for font emphasis
|
||||||
if (player.hasPermission("qol.discord")) {
|
if (player.hasPermission("qol.discord")) {
|
||||||
String chat = event.getMessage();
|
String chat = event.getMessage();
|
||||||
Pattern syntax;
|
boolean escape = false;
|
||||||
Matcher matcher;
|
|
||||||
for (int i = 0; i < discordSyntax.size(); i++) {
|
// Escape
|
||||||
syntax = discordSyntax.get(i);
|
if (chat.startsWith("\\")) {
|
||||||
matcher = syntax.matcher(chat);
|
escape = true;
|
||||||
switch (i) {
|
event.setMessage(chat.substring(1));
|
||||||
case 0:
|
|
||||||
chat = matcher.replaceAll("&n$1&r");
|
// Escape the escape, this monster wants to start their message with a backslash
|
||||||
break;
|
if (chat.startsWith("\\\\")) {
|
||||||
case 1:
|
escape = false;
|
||||||
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));
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue