2020
2121import dev .hypera .ultrastaffchat .UltraStaffChat ;
2222import dev .hypera .ultrastaffchat .utils .DiscordWebhook .EmbedObject ;
23+ import net .md_5 .bungee .api .ChatColor ;
2324import net .md_5 .bungee .api .CommandSender ;
2425import net .md_5 .bungee .api .ProxyServer ;
2526import net .md_5 .bungee .api .connection .ProxiedPlayer ;
@@ -83,7 +84,7 @@ public static void broadcastDiscordJoin(ProxiedPlayer p) {
8384 ProxyServer .getInstance ().getScheduler ().runAsync (UltraStaffChat .getInstance (), () -> {
8485 try {
8586 DiscordWebhook hook = getHook ();
86- if (UltraStaffChat .getConfig ().getBoolean ("discord-embed" ). equals ( false )) {
87+ if (! UltraStaffChat .getConfig ().getBoolean ("discord-embed" )) {
8788 Configuration textFormat = UltraStaffChat .getConfig ().getConfiguration ().getSection ("discord-join-format" );
8889 hook .setContent (join_leavePlaceholders (textFormat .getString ("text" ), p ));
8990 hook .execute ();
@@ -118,7 +119,7 @@ public static void broadcastDiscordLeave(ProxiedPlayer p) {
118119 try {
119120 DiscordWebhook hook = getHook ();
120121
121- if (UltraStaffChat .getConfig ().getBoolean ("discord-embed" ). equals ( false )) {
122+ if (! UltraStaffChat .getConfig ().getBoolean ("discord-embed" )) {
122123 Configuration textFormat = UltraStaffChat .getConfig ().getConfiguration ().getSection ("discord-leave-format" );
123124 hook .setContent (join_leavePlaceholders (textFormat .getString ("text" ), p ));
124125 hook .execute ();
@@ -153,7 +154,7 @@ public static void broadcastDiscordSwitch(ProxiedPlayer p, String from, String t
153154 try {
154155 DiscordWebhook hook = getHook ();
155156
156- if (UltraStaffChat .getConfig ().getBoolean ("discord-embed" ). equals ( false )) {
157+ if (! UltraStaffChat .getConfig ().getBoolean ("discord-embed" )) {
157158 Configuration textFormat = UltraStaffChat .getConfig ().getConfiguration ().getSection ("discord-switch-format" );
158159 hook .setContent (switchPlaceholders (textFormat .getString ("text" ), p , from , to ));
159160 try {
@@ -192,7 +193,7 @@ public static void broadcastDiscordStaffChatMessage(CommandSender s, String mess
192193 try {
193194 DiscordWebhook hook = getHook ();
194195
195- if (UltraStaffChat .getConfig ().getBoolean ("discord-embed" ). equals ( false )) {
196+ if (! UltraStaffChat .getConfig ().getBoolean ("discord-embed" )) {
196197 Configuration textFormat = UltraStaffChat .getConfig ().getConfiguration ().getSection ("discord-format" );
197198 hook .setContent (messagePlaceholders (textFormat .getString ("text" ), s , message ));
198199 try {
@@ -231,9 +232,9 @@ public static void broadcastDiscordAFKEnable(ProxiedPlayer p) {
231232 try {
232233 DiscordWebhook hook = getHook ();
233234
234- if (UltraStaffChat .getConfig ().getBoolean ("discord-embed" ). equals ( false )) {
235+ if (! UltraStaffChat .getConfig ().getBoolean ("discord-embed" )) {
235236 Configuration textFormat = UltraStaffChat .getConfig ().getConfiguration ().getSection ("discord-afk-enable-format" );
236- hook .setContent (join_leavePlaceholders (textFormat .getString ("text" ), p ));
237+ hook .setContent (afkPlaceholders (textFormat .getString ("text" ), p ));
237238 hook .execute ();
238239 return ;
239240 }
@@ -266,9 +267,9 @@ public static void broadcastDiscordAFKDisable(ProxiedPlayer p) {
266267 try {
267268 DiscordWebhook hook = getHook ();
268269
269- if (UltraStaffChat .getConfig ().getBoolean ("discord-embed" ). equals ( false )) {
270+ if (! UltraStaffChat .getConfig ().getBoolean ("discord-embed" )) {
270271 Configuration textFormat = UltraStaffChat .getConfig ().getConfiguration ().getSection ("discord-afk-disable-format" );
271- hook .setContent (join_leavePlaceholders (textFormat .getString ("text" ), p ));
272+ hook .setContent (afkPlaceholders (textFormat .getString ("text" ), p ));
272273 hook .execute ();
273274 return ;
274275 }
@@ -295,19 +296,19 @@ public static void broadcastDiscordAFKDisable(ProxiedPlayer p) {
295296 }
296297
297298 private static String messagePlaceholders (String string , CommandSender s , String m ) {
298- return string .replaceAll ("\\ {message}" , m ) .replaceAll ("\\ {player}" , Common .getDisplayNameSafe (s )).replaceAll ("\\ {server}" , Common .getServerSafe (s ));
299+ return escape ( string .replaceAll ("\\ {message}" , stripColor ( m )) .replaceAll ("\\ {player}" , Common .getDisplayNameSafe (s )).replaceAll ("\\ {server}" , Common .getServerSafe (s ) ));
299300 }
300301
301302 private static String join_leavePlaceholders (String string , ProxiedPlayer p ) {
302- return string .replaceAll ("\\ {player}" , Common .getDisplayNameSafe (p )).replaceAll ("\\ {server}" , Common .getServerSafe (p ));
303+ return escape ( string .replaceAll ("\\ {player}" , Common .getDisplayNameSafe (p )).replaceAll ("\\ {server}" , Common .getServerSafe (p ) ));
303304 }
304305
305306 private static String switchPlaceholders (String string , ProxiedPlayer p , String from , String to ) {
306- return string .replaceAll ("\\ {player}" , Common .getDisplayNameSafe (p )).replaceAll ("\\ {to}" , to ).replaceAll ("\\ {from}" , from );
307+ return escape ( string .replaceAll ("\\ {player}" , Common .getDisplayNameSafe (p )).replaceAll ("\\ {to}" , to ).replaceAll ("\\ {from}" , from ) );
307308 }
308309
309310 private static String afkPlaceholders (String string , ProxiedPlayer p ) {
310- return string .replaceAll ("\\ {player}" , Common .getDisplayNameSafe (p ));
311+ return escape ( string .replaceAll ("\\ {player}" , Common .getDisplayNameSafe (p ) ));
311312 }
312313
313314 private static DiscordWebhook getHook () {
@@ -321,4 +322,12 @@ private static DiscordWebhook.EmbedObject createEmbed() {
321322 return new DiscordWebhook .EmbedObject ().setFooter (footer , footerUrl );
322323 }
323324
325+ private static String escape (String input ) {
326+ return input .replaceAll ("\" " , "\\ \\ \" " );
327+ }
328+
329+ private static String stripColor (String input ) {
330+ return input .replaceAll ("(?i)[§&][0-9A-FK-ORX]" , "" );
331+ }
332+
324333}
0 commit comments