Skip to content

Commit fcf2702

Browse files
committed
Added link regex in config file for chat control
1 parent 50a7f82 commit fcf2702

4 files changed

Lines changed: 22 additions & 13 deletions

File tree

multichat/src/main/java/xyz/olivermartin/multichat/bungee/ChatControl.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ public class ChatControl {
2525
private static Set<UUID> mutedPlayers;
2626
private static Map<UUID, Set<UUID>> ignoreMap;
2727
private static Map<UUID, PlayerSpamInfo> spamMap;
28-
28+
2929
public static boolean controlLinks = false;
30+
public static String linkRegex = "((https|http):\\/\\/)?(www\\.)?([-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.)+[a-zA-Z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)";
3031
public static String linkMessage = "[LINK REMOVED]";
3132

3233
public static Set<UUID> getMutedPlayers() {
@@ -282,10 +283,11 @@ public static void reload() {
282283
}
283284

284285
}
285-
286+
286287
public static String replaceLinks(String message) {
287288
if (!controlLinks) return message;
288-
return message.replaceAll("((https|http):\\/\\/)?(www\\.)?([-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.)+[a-zA-Z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)", linkMessage);
289+
return message.replaceAll(linkRegex, linkMessage);
290+
//return message.replaceAll("((https|http):\\/\\/)?(www\\.)?([-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.)+[a-zA-Z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)", linkMessage);
289291
}
290292

291293
public static void spamPardonPlayer(UUID uuid) {
@@ -297,23 +299,23 @@ public static void spamPardonPlayer(UUID uuid) {
297299
* @return true if the player is spamming and the message should be blocked
298300
*/
299301
public static boolean handleSpam(ProxiedPlayer player, String message, String chatType) {
300-
302+
301303
DebugManager.log(player.getName() + " - checking for spam...");
302304

303305
Configuration config = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig();
304-
306+
305307
if (player.hasPermission("multichat.spam.bypass")) return false;
306-
308+
307309
DebugManager.log(player.getName() + " - does not have bypass perm...");
308310

309311
if (!config.getBoolean("anti_spam")) return false;
310-
312+
311313
DebugManager.log(player.getName() + " - anti spam IS enabled...");
312314

313315
if (!config.contains("apply_anti_spam_to." + chatType)) return false;
314316

315317
if (!config.getBoolean("apply_anti_spam_to." + chatType)) return false;
316-
318+
317319
DebugManager.log(player.getName() + " - anti spam IS enabled for " + chatType + "...");
318320

319321
if (!spamMap.containsKey(player.getUniqueId())) spamMap.put(player.getUniqueId(), new PlayerSpamInfo());
@@ -323,21 +325,21 @@ public static boolean handleSpam(ProxiedPlayer player, String message, String ch
323325
boolean spam = spamInfo.checkSpam(message);
324326

325327
if (spam) {
326-
328+
327329
DebugManager.log(player.getName() + " - PLAYER IS SPAMMING!");
328330

329331
MessageManager.sendSpecialMessage(player, "anti_spam_cooldown", String.valueOf(spamInfo.getCooldownSeconds()));
330-
332+
331333
DebugManager.log(player.getName() + " - sent cooldown message to player...");
332334

333335
if (spamInfo.getSpamTriggerCount() >= config.getInt("anti_spam_trigger")) {
334-
336+
335337
DebugManager.log(player.getName() + " - they have set off the trigger...");
336338

337339
spamInfo.resetSpamTriggerCount();
338340

339341
if (config.getBoolean("anti_spam_action")) {
340-
342+
341343
DebugManager.log(player.getName() + " - trigger IS enabled...");
342344

343345
if (config.getBoolean("anti_spam_spigot")) {
@@ -352,7 +354,7 @@ public static boolean handleSpam(ProxiedPlayer player, String message, String ch
352354
}
353355

354356
}
355-
357+
356358
DebugManager.log(player.getName() + " - returning " + spam);
357359

358360
return spam;

multichat/src/main/java/xyz/olivermartin/multichat/bungee/MultiChat.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ public void onEnable() {
317317
if (chatcontrolYML.contains("link_control")) {
318318
ChatControl.controlLinks = chatcontrolYML.getBoolean("link_control");
319319
ChatControl.linkMessage = chatcontrolYML.getString("link_removal_message");
320+
if (chatcontrolYML.contains("link_regex")) {
321+
ChatControl.linkRegex = chatcontrolYML.getString("link_regex");
322+
}
320323
}
321324

322325
if (configYML.contains("privacy_settings")) {

multichat/src/main/java/xyz/olivermartin/multichat/bungee/commands/MultiChatCommand.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ public void execute(CommandSender sender, String[] args) {
122122
if (ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig().contains("link_control")) {
123123
ChatControl.controlLinks = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig().getBoolean("link_control");
124124
ChatControl.linkMessage = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig().getString("link_removal_message");
125+
if (ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig().contains("link_regex")) {
126+
ChatControl.linkRegex = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig().getString("link_regex");
127+
}
125128
}
126129

127130
if (ConfigManager.getInstance().getHandler("config.yml").getConfig().contains("privacy_settings")) {

multichat/src/main/resources/chatcontrol.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ ignorecommand:
187187
# Should MultiChat control which players can send links to chat?
188188
# If set to true, then only players with multichat.chat.link will be able to send links
189189
link_control: false
190+
link_regex: "((https|http):\/\/)?(www\.)?([-a-zA-Z0-9@:%._\+~#=]{2,256}\.)+[a-zA-Z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)"
190191

191192
# Message to replace links in chat with
192193
link_removal_message: "[LINK REMOVED]"

0 commit comments

Comments
 (0)