From b80827ed1eb3b6395830086fca0a59be2955d942 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 17 Jul 2022 17:12:48 +0200 Subject: [PATCH 1/4] Fix local colorcodes Signed-off-by: Lixfel --- .../bungeecore/listeners/ChatListener.java | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index a815f6a..b632ef1 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -82,27 +82,27 @@ public class ChatListener extends BasicListener { } public static void sendChat(ChatSender sender, Stream receivers, String format, ChatSender msgReceiver, String message) { - String finalMessage = modifyFilter(sender, message); - if(finalMessage == null) + if(chatFilter(sender, message)) return; SteamwarUser user = sender.user(); + String coloredMessage = (user.getUserGroup() != UserGroup.Member || coloredTeams.contains(user.getTeam())) ? ChatColor.translateAlternateColorCodes('&', message) : message; AtomicBoolean noReceiver = new AtomicBoolean(true); receivers.filter(ChatSender::chatShown).forEach(player -> { if(sender.user().getId() != player.user().getId()) noReceiver.set(false); - chatToReciever(player, msgReceiver, user, format, finalMessage); + chatToReciever(player, msgReceiver, user, format, coloredMessage); }); - chatToReciever(ChatSender.console(), msgReceiver, user, format, finalMessage); + chatToReciever(ChatSender.console(), msgReceiver, user, format, coloredMessage); if(format.equals("CHAT_GLOBAL")) { if (SteamwarDiscordBot.instance() != null) - chatToReciever(ChatSender.discordChannel(SteamwarDiscordBot.instance().getIngameChatListener()), msgReceiver, user, format, finalMessage); + chatToReciever(ChatSender.discordChannel(SteamwarDiscordBot.instance().getIngameChatListener()), msgReceiver, user, format, coloredMessage); } else if (format.equals("CHAT_SERVERTEAM")) { if (SteamwarDiscordBot.instance() != null) - chatToReciever(ChatSender.discordChannel(SteamwarDiscordBot.instance().getServerTeamChatListener()), msgReceiver, user, format, finalMessage); + chatToReciever(ChatSender.discordChannel(SteamwarDiscordBot.instance().getServerTeamChatListener()), msgReceiver, user, format, coloredMessage); } else if (noReceiver.get()) { sender.system("CHAT_NO_RECEIVER"); } @@ -119,40 +119,35 @@ public class ChatListener extends BasicListener { if(ChatListener.filteredCommand(player, message)) return; - if(!message.startsWith("/")) { - message = modifyFilter(sender, message); - if(message == null) - return; - } + + if(!message.startsWith("/") && chatFilter(sender, message)) + return; Chat19.chat(player, message); } - private static String modifyFilter(ChatSender sender, String message) { + private static boolean chatFilter(ChatSender sender, String message) { if(!sender.chatShown()) { sender.system("CHAT_RECEIVE"); - return null; + return true; } SteamwarUser user = sender.user(); UserGroup group = user.getUserGroup(); if(!group.isTeamGroup() && (message.contains("http:") || message.contains("https:") || message.contains("www."))){ sender.system("CHAT_NO_LINKS"); - return null; + return true; } if (user.isPunishedWithMessage(sender, Punishment.PunishmentType.Mute)) - return null; - - if(group != UserGroup.Member || coloredTeams.contains(user.getTeam())) - message = ChatColor.translateAlternateColorCodes('&', message); + return true; if (message.contains("LIXFEL")) specialAlert(sender, "Lixfel", "CHAT_LIXFEL_", 3, 6, 11, 12, 15); if (message.contains("YOYONOW")) specialAlert(sender, "YoyoNow", "CHAT_YOYONOW_", 3, 6, 11, 12); - return message; + return false; } private static void chatToReciever(ChatSender receiver, ChatSender msgReceiver, SteamwarUser sender, String format, String message) { From 3053d5d3012bdbcfdffd3e7ac93aec85e9b953b7 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 17 Jul 2022 17:31:11 +0200 Subject: [PATCH 2/4] Fix empty messages Signed-off-by: Lixfel --- .../steamwar/bungeecore/listeners/ChatListener.java | 12 ++++++++---- src/de/steamwar/messages/BungeeCore.properties | 1 + src/de/steamwar/messages/BungeeCore_de.properties | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index b632ef1..df006f9 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -82,11 +82,10 @@ public class ChatListener extends BasicListener { } public static void sendChat(ChatSender sender, Stream receivers, String format, ChatSender msgReceiver, String message) { - if(chatFilter(sender, message)) - return; - SteamwarUser user = sender.user(); - String coloredMessage = (user.getUserGroup() != UserGroup.Member || coloredTeams.contains(user.getTeam())) ? ChatColor.translateAlternateColorCodes('&', message) : message; + final String coloredMessage = (user.getUserGroup() != UserGroup.Member || coloredTeams.contains(user.getTeam())) ? ChatColor.translateAlternateColorCodes('&', message) : message; + if(chatFilter(sender, coloredMessage)) + return; AtomicBoolean noReceiver = new AtomicBoolean(true); receivers.filter(ChatSender::chatShown).forEach(player -> { @@ -132,6 +131,11 @@ public class ChatListener extends BasicListener { return true; } + if(message.replace("§[a-f0-9klmno]", "").trim().isEmpty()) { + sender.system("CHAT_EMPTY"); + return true; + } + SteamwarUser user = sender.user(); UserGroup group = user.getUserGroup(); if(!group.isTeamGroup() && (message.contains("http:") || message.contains("https:") || message.contains("www."))){ diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 7dfaa7c..58633d2 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -521,6 +521,7 @@ CHAT_RECEIVE=§cTo be able to send chat messages, you must also receive them! CHAT_NO_LINKS=§cYou may not send links. CHAT_BC_USAGE=§8/§7bc §8[§emessage§8] CHAT_NO_RECEIVER=§cNobody receives your message +CHAT_EMPTY=§cDon't write meaningless empty messages. CHAT_SERVERTEAM=§8STC §e{0}§8» §f{2} CHAT_GLOBAL={3}{4}{5}{6}{0}§8» {7}{2} diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 6fc780b..0c93d45 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -500,6 +500,7 @@ CHAT_RECEIVE=§cUm Chatnachrichten versenden zu können, musst du auch welche em CHAT_NO_LINKS=§cDu darfst keine Links versenden. CHAT_BC_USAGE=§8/§7bc §8[§eNachricht§8] CHAT_NO_RECEIVER=§cNiemand empfängt deine Nachricht +CHAT_EMPTY=§cSchreibe keine inhaltslosen Nachrichten. CHAT_SERVERTEAM=§8STC §e{0}§8» §f{2} CHAT_GLOBAL={3}{4}{5}{6}{0}§8» {7}{2} From 3a54797d07c39e50a649da158b7f7f8db7e832c4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 17 Jul 2022 17:34:15 +0200 Subject: [PATCH 3/4] Use strip Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/listeners/ChatListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index df006f9..ba37c77 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -131,7 +131,7 @@ public class ChatListener extends BasicListener { return true; } - if(message.replace("§[a-f0-9klmno]", "").trim().isEmpty()) { + if(message.replace("§[a-f0-9klmno]", "").strip().isEmpty()) { sender.system("CHAT_EMPTY"); return true; } From e30f4cc2eebd3b98522b9ef6b4d8a61ca63cc728 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 17 Jul 2022 17:36:27 +0200 Subject: [PATCH 4/4] Fix strip Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/listeners/ChatListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index ba37c77..df006f9 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -131,7 +131,7 @@ public class ChatListener extends BasicListener { return true; } - if(message.replace("§[a-f0-9klmno]", "").strip().isEmpty()) { + if(message.replace("§[a-f0-9klmno]", "").trim().isEmpty()) { sender.system("CHAT_EMPTY"); return true; }