Skip to content

Commit 90ad9d1

Browse files
committed
Anti-advertising implemented.
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent b6bbbae commit 90ad9d1

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

src/main/kotlin/com/mairwunnx/projectessentials/chat/EntryPoint.kt

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,40 @@ class EntryPoint : EssBase() {
7777
return
7878
}
7979

80-
if (!hasPermission(event.player, "ess.chat.chatdelay.bypass", 3)) {
81-
if (ChatCooldown.getCooldownIsExpired(
82-
event.player.name.string,
83-
ChatModelUtils.chatModel.moderation.messagingCooldown
84-
)
85-
) {
86-
ChatCooldown.addCooldown(event.player.name.string)
87-
} else {
88-
sendMsg(
89-
"chat",
90-
event.player.commandSource,
91-
"chat.cooldown_not_expired"
92-
)
93-
event.isCanceled = true
94-
return
80+
if (ChatModelUtils.chatModel.moderation.messagingCooldownEnabled) {
81+
if (!hasPermission(event.player, "ess.chat.chatdelay.bypass", 3)) {
82+
if (ChatCooldown.getCooldownIsExpired(
83+
event.player.name.string,
84+
ChatModelUtils.chatModel.moderation.messagingCooldown
85+
)
86+
) {
87+
ChatCooldown.addCooldown(event.player.name.string)
88+
} else {
89+
sendMsg(
90+
"chat",
91+
event.player.commandSource,
92+
"chat.cooldown_not_expired"
93+
)
94+
event.isCanceled = true
95+
return
96+
}
97+
}
98+
}
99+
100+
if (!ChatModelUtils.chatModel.moderation.advertisingAllowed) {
101+
if (!hasPermission(event.player, "ess.chat.advertising.bypass", 3)) {
102+
if (event.message.matches(
103+
Regex(ChatModelUtils.chatModel.moderation.advertisingRegex)
104+
)
105+
) {
106+
sendMsg(
107+
"chat",
108+
event.player.commandSource,
109+
"chat.advertising_not_allowed"
110+
)
111+
event.isCanceled = true
112+
return
113+
}
95114
}
96115
}
97116

src/main/kotlin/com/mairwunnx/projectessentials/chat/models/ChatModel.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ data class ChatModel(
1515
var modifyBlockedWords: Boolean = true,
1616
var blockedWordsMask: String = "**beep**",
1717
var maxMessageLength: Int = 128,
18-
var messagingCooldown: Int = 5
18+
var messagingCooldownEnabled: Boolean = true,
19+
var messagingCooldown: Int = 5,
20+
var advertisingAllowed: Boolean = false,
21+
var advertisingRegex: String = "(http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?"
1922
)
2023

2124
@Serializable

src/main/resources/assets/projectessentialschat/lang/en_us.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"project_essentials_chat.chat.blocked_char": "§cMessage not sent, your message contains blocked symbol.",
77
"project_essentials_chat.chat.message_maxlength": "§cMessage not sent, your message length exceeds maximum allowed length.",
88
"project_essentials_chat.chat.mention_all_aborted": "§cMention not sent to all players, you §7don't have permission§c to mention all players.",
9-
"project_essentials_chat.chat.cooldown_not_expired": "§cMessage not sent, wait chat cooldown after your previous message."
9+
"project_essentials_chat.chat.cooldown_not_expired": "§cMessage not sent, wait chat cooldown after your previous message.",
10+
"project_essentials_chat.chat.advertising_not_allowed": "§cMessage not sent, maybe it contains a link or advertisement."
1011
}

src/main/resources/assets/projectessentialschat/lang/ru_ru.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"project_essentials_chat.chat.blocked_char": "§cСообщение не отправлено, ваше сообщение содержит заблокированный символ.",
77
"project_essentials_chat.chat.message_maxlength": "§cСообщение не отправлено, ваше сообщение превышает максимально допустимую длину.",
88
"project_essentials_chat.chat.mention_all_aborted": "§cОповещение не было отправлено всем игрокам, у вас §7нет прав§c на оповещение всех игроков.",
9-
"project_essentials_chat.chat.cooldown_not_expired": "§cСообщение не отправлено, дождитесь окончания задержки в чате после предыдущего Вашего сообщения."
9+
"project_essentials_chat.chat.cooldown_not_expired": "§cСообщение не отправлено, дождитесь окончания задержки в чате после предыдущего Вашего сообщения.",
10+
"project_essentials_chat.chat.advertising_not_allowed": "§cСообщение не отправлено, возможно оно содержит ссылку или рекламу."
1011
}

0 commit comments

Comments
 (0)