|
1 | | -package com.mairwunnx.projectessentials.chat |
2 | | - |
3 | | -import com.mairwunnx.projectessentials.chat.EntryPoint.Companion.hasPermission |
4 | | -import com.mairwunnx.projectessentials.chat.models.ChatModelUtils |
5 | | -import com.mairwunnx.projectessentials.core.extensions.empty |
6 | | -import net.minecraft.util.Tuple |
7 | | -import net.minecraftforge.event.ServerChatEvent |
8 | | - |
9 | | -object ChatUtils { |
10 | | - fun processBlockedWords(event: ServerChatEvent): Tuple<Boolean, String> { |
11 | | - val blockedWords = ChatModelUtils.chatModel.moderation.blockedWords |
12 | | - val blockedWordsMask = ChatModelUtils.chatModel.moderation.blockedWordsMask |
13 | | - val modifyBlockedWords = ChatModelUtils.chatModel.moderation.modifyBlockedWords |
14 | | - |
15 | | - var fixedMessage = event.message |
16 | | - |
17 | | - blockedWords.forEach { |
18 | | - if (fixedMessage.toLowerCase().contains(Regex(it, RegexOption.IGNORE_CASE)) || |
19 | | - fixedMessage.toLowerCase().matches(Regex(it, RegexOption.IGNORE_CASE)) || |
20 | | - fixedMessage.toLowerCase().contains(it, true) |
21 | | - ) { |
22 | | - if (hasPermission( |
23 | | - event.player, "ess.chat.blockedwords.bypass", 3 |
24 | | - ) |
25 | | - ) return Tuple(true, fixedMessage) |
26 | | - |
27 | | - if (modifyBlockedWords) { |
28 | | - if (blockedWordsMask.isNotEmpty()) { |
29 | | - val newMessage = fixedMessage.replace(it, blockedWordsMask).replace( |
30 | | - Regex(it, RegexOption.IGNORE_CASE), blockedWordsMask |
31 | | - ) |
32 | | - fixedMessage = newMessage |
33 | | - } |
34 | | - } else { |
35 | | - sendMessage( |
36 | | - event.player.commandSource, |
37 | | - "chat.blocked_word", |
38 | | - it |
39 | | - ) |
40 | | - return Tuple(false, String.empty) |
41 | | - } |
42 | | - } |
43 | | - } |
44 | | - return Tuple(true, fixedMessage) |
45 | | - } |
46 | | - |
47 | | - fun processBlockedChars(event: ServerChatEvent): Boolean { |
48 | | - if (hasPermission( |
49 | | - event.player, "ess.chat.blockedchars.bypass", 3 |
50 | | - ) |
51 | | - ) return true |
52 | | - |
53 | | - val blockedChars = ChatModelUtils.chatModel.moderation.blockedChars |
54 | | - blockedChars.forEach { |
55 | | - if (event.message.contains(it)) { |
56 | | - sendMessage( |
57 | | - event.player.commandSource, |
58 | | - "chat.blocked_char" |
59 | | - ) |
60 | | - return false |
61 | | - } |
62 | | - } |
63 | | - return true |
64 | | - } |
65 | | - |
66 | | - fun processMessageLength(event: ServerChatEvent): Boolean { |
67 | | - if (hasPermission( |
68 | | - event.player, "ess.chat.messagelength.bypass", 4 |
69 | | - ) |
70 | | - ) return true |
71 | | - |
72 | | - val maxLength = ChatModelUtils.chatModel.moderation.maxMessageLength |
73 | | - if (event.message.length > maxLength) { |
74 | | - sendMessage( |
75 | | - event.player.commandSource, "chat.message_maxlength" |
76 | | - ) |
77 | | - return false |
78 | | - } |
79 | | - return true |
80 | | - } |
81 | | - |
82 | | - fun isGlobalChat(event: ServerChatEvent): Boolean = event.message.startsWith('!') |
83 | | - |
84 | | - fun isCommonChat(): Boolean = !ChatModelUtils.chatModel.messaging.enableRangedChat |
85 | | - |
86 | | - fun getMessagePattern(event: ServerChatEvent): String { |
87 | | - return when { |
88 | | - !ChatModelUtils.chatModel.messaging.enableRangedChat -> ChatModelUtils.chatModel.messaging.messageCommonPattern |
89 | | - isGlobalChat(event) -> ChatModelUtils.chatModel.messaging.messageGlobalPattern |
90 | | - else -> ChatModelUtils.chatModel.messaging.messageLocalPattern |
91 | | - } |
92 | | - } |
93 | | - |
94 | | - fun getMessageColor(event: ServerChatEvent): String { |
95 | | - val messageRegex = Regex("(&.|§.){1,2}%message") |
96 | | - when { |
97 | | - isCommonChat() -> { |
98 | | - val targetVariable = messageRegex.find( |
99 | | - ChatModelUtils.chatModel.messaging.messageCommonPattern |
100 | | - ) |
101 | | - return getMessageVariable(targetVariable!!, "§f") |
102 | | - } |
103 | | - else -> return if (isGlobalChat(event)) { |
104 | | - val targetVariable = messageRegex.find( |
105 | | - ChatModelUtils.chatModel.messaging.messageGlobalPattern |
106 | | - ) |
107 | | - |
108 | | - getMessageVariable(targetVariable!!, "§f") |
109 | | - } else { |
110 | | - val targetVariable = messageRegex.find( |
111 | | - ChatModelUtils.chatModel.messaging.messageLocalPattern |
112 | | - ) |
113 | | - getMessageVariable(targetVariable!!, "§7§o") |
114 | | - } |
115 | | - } |
116 | | - } |
117 | | - |
118 | | - private fun getMessageVariable(matchResult: MatchResult, callback: String): String { |
119 | | - return matchResult.groups[0]?.value |
120 | | - ?.removeRange( |
121 | | - matchResult.groups[0]?.value!!.lastIndexOf("%"), |
122 | | - matchResult.groups[0]?.value!!.length |
123 | | - ) |
124 | | - ?.replace("&", "§") ?: callback |
125 | | - } |
126 | | -} |
| 1 | +//package com.mairwunnx.projectessentials.chat |
| 2 | +// |
| 3 | +//import com.mairwunnx.projectessentials.chat.EntryPoint.Companion.hasPermission |
| 4 | +//import com.mairwunnx.projectessentials.chat.models.ChatModelUtils |
| 5 | +//import com.mairwunnx.projectessentials.core.extensions.empty |
| 6 | +//import net.minecraft.util.Tuple |
| 7 | +//import net.minecraftforge.event.ServerChatEvent |
| 8 | +// |
| 9 | +//object ChatUtils { |
| 10 | +// fun processBlockedWords(event: ServerChatEvent): Tuple<Boolean, String> { |
| 11 | +// val blockedWords = ChatModelUtils.chatModel.moderation.blockedWords |
| 12 | +// val blockedWordsMask = ChatModelUtils.chatModel.moderation.blockedWordsMask |
| 13 | +// val modifyBlockedWords = ChatModelUtils.chatModel.moderation.modifyBlockedWords |
| 14 | +// |
| 15 | +// var fixedMessage = event.message |
| 16 | +// |
| 17 | +// blockedWords.forEach { |
| 18 | +// if (fixedMessage.toLowerCase().contains(Regex(it, RegexOption.IGNORE_CASE)) || |
| 19 | +// fixedMessage.toLowerCase().matches(Regex(it, RegexOption.IGNORE_CASE)) || |
| 20 | +// fixedMessage.toLowerCase().contains(it, true) |
| 21 | +// ) { |
| 22 | +// if (hasPermission( |
| 23 | +// event.player, "ess.chat.blockedwords.bypass", 3 |
| 24 | +// ) |
| 25 | +// ) return Tuple(true, fixedMessage) |
| 26 | +// |
| 27 | +// if (modifyBlockedWords) { |
| 28 | +// if (blockedWordsMask.isNotEmpty()) { |
| 29 | +// val newMessage = fixedMessage.replace(it, blockedWordsMask).replace( |
| 30 | +// Regex(it, RegexOption.IGNORE_CASE), blockedWordsMask |
| 31 | +// ) |
| 32 | +// fixedMessage = newMessage |
| 33 | +// } |
| 34 | +// } else { |
| 35 | +// sendMessage( |
| 36 | +// event.player.commandSource, |
| 37 | +// "chat.blocked_word", |
| 38 | +// it |
| 39 | +// ) |
| 40 | +// return Tuple(false, String.empty) |
| 41 | +// } |
| 42 | +// } |
| 43 | +// } |
| 44 | +// return Tuple(true, fixedMessage) |
| 45 | +// } |
| 46 | +// |
| 47 | +// fun processBlockedChars(event: ServerChatEvent): Boolean { |
| 48 | +// if (hasPermission( |
| 49 | +// event.player, "ess.chat.blockedchars.bypass", 3 |
| 50 | +// ) |
| 51 | +// ) return true |
| 52 | +// |
| 53 | +// val blockedChars = ChatModelUtils.chatModel.moderation.blockedChars |
| 54 | +// blockedChars.forEach { |
| 55 | +// if (event.message.contains(it)) { |
| 56 | +// sendMessage( |
| 57 | +// event.player.commandSource, |
| 58 | +// "chat.blocked_char" |
| 59 | +// ) |
| 60 | +// return false |
| 61 | +// } |
| 62 | +// } |
| 63 | +// return true |
| 64 | +// } |
| 65 | +// |
| 66 | +// fun processMessageLength(event: ServerChatEvent): Boolean { |
| 67 | +// if (hasPermission( |
| 68 | +// event.player, "ess.chat.messagelength.bypass", 4 |
| 69 | +// ) |
| 70 | +// ) return true |
| 71 | +// |
| 72 | +// val maxLength = ChatModelUtils.chatModel.moderation.maxMessageLength |
| 73 | +// if (event.message.length > maxLength) { |
| 74 | +// sendMessage( |
| 75 | +// event.player.commandSource, "chat.message_maxlength" |
| 76 | +// ) |
| 77 | +// return false |
| 78 | +// } |
| 79 | +// return true |
| 80 | +// } |
| 81 | +// |
| 82 | +// fun isGlobalChat(event: ServerChatEvent): Boolean = event.message.startsWith('!') |
| 83 | +// |
| 84 | +// fun isCommonChat(): Boolean = !ChatModelUtils.chatModel.messaging.enableRangedChat |
| 85 | +// |
| 86 | +// fun getMessagePattern(event: ServerChatEvent): String { |
| 87 | +// return when { |
| 88 | +// !ChatModelUtils.chatModel.messaging.enableRangedChat -> ChatModelUtils.chatModel.messaging.messageCommonPattern |
| 89 | +// isGlobalChat(event) -> ChatModelUtils.chatModel.messaging.messageGlobalPattern |
| 90 | +// else -> ChatModelUtils.chatModel.messaging.messageLocalPattern |
| 91 | +// } |
| 92 | +// } |
| 93 | +// |
| 94 | +// fun getMessageColor(event: ServerChatEvent): String { |
| 95 | +// val messageRegex = Regex("(&.|§.){1,2}%message") |
| 96 | +// when { |
| 97 | +// isCommonChat() -> { |
| 98 | +// val targetVariable = messageRegex.find( |
| 99 | +// ChatModelUtils.chatModel.messaging.messageCommonPattern |
| 100 | +// ) |
| 101 | +// return getMessageVariable(targetVariable!!, "§f") |
| 102 | +// } |
| 103 | +// else -> return if (isGlobalChat(event)) { |
| 104 | +// val targetVariable = messageRegex.find( |
| 105 | +// ChatModelUtils.chatModel.messaging.messageGlobalPattern |
| 106 | +// ) |
| 107 | +// |
| 108 | +// getMessageVariable(targetVariable!!, "§f") |
| 109 | +// } else { |
| 110 | +// val targetVariable = messageRegex.find( |
| 111 | +// ChatModelUtils.chatModel.messaging.messageLocalPattern |
| 112 | +// ) |
| 113 | +// getMessageVariable(targetVariable!!, "§7§o") |
| 114 | +// } |
| 115 | +// } |
| 116 | +// } |
| 117 | +// |
| 118 | +// private fun getMessageVariable(matchResult: MatchResult, callback: String): String { |
| 119 | +// return matchResult.groups[0]?.value |
| 120 | +// ?.removeRange( |
| 121 | +// matchResult.groups[0]?.value!!.lastIndexOf("%"), |
| 122 | +// matchResult.groups[0]?.value!!.length |
| 123 | +// ) |
| 124 | +// ?.replace("&", "§") ?: callback |
| 125 | +// } |
| 126 | +//} |
0 commit comments