diff options
author | Lorenz <ESs95s3P5z8Pheb> | 2022-07-08 13:29:29 +0200 |
---|---|---|
committer | Lorenz <ESs95s3P5z8Pheb> | 2022-07-08 13:29:29 +0200 |
commit | 07ccd2ac5f80679f353f26593c38e497e9de38c3 (patch) | |
tree | 8604ffa6e7546b5ab4728a8a7bbce3c41ba3265e /src/main/java/at/lorenz | |
parent | a4861334a90c7f87318dba5bcbf5ae738fb4136a (diff) | |
download | skyhanni-07ccd2ac5f80679f353f26593c38e497e9de38c3.tar.gz skyhanni-07ccd2ac5f80679f353f26593c38e497e9de38c3.tar.bz2 skyhanni-07ccd2ac5f80679f353f26593c38e497e9de38c3.zip |
moved player chat messages into separate setting
Diffstat (limited to 'src/main/java/at/lorenz')
-rw-r--r-- | src/main/java/at/lorenz/mod/chat/ChatFilter.kt | 1 | ||||
-rw-r--r-- | src/main/java/at/lorenz/mod/chat/PlayerChatFilter.kt | 125 | ||||
-rw-r--r-- | src/main/java/at/lorenz/mod/config/Features.java | 5 |
3 files changed, 73 insertions, 58 deletions
diff --git a/src/main/java/at/lorenz/mod/chat/ChatFilter.kt b/src/main/java/at/lorenz/mod/chat/ChatFilter.kt index 29700a099..2ad5284c9 100644 --- a/src/main/java/at/lorenz/mod/chat/ChatFilter.kt +++ b/src/main/java/at/lorenz/mod/chat/ChatFilter.kt @@ -25,7 +25,6 @@ class ChatFilter { warping(message) -> "warping" welcome(message) -> "welcome" guild(message) -> "guild" - PlayerChatFilter.shouldBlock(message) -> "player_chat" killCombo(message) -> "kill_combo" bazaarAndAHMiniMessages(message) -> "bz_ah_minis" watchdogAnnouncement(message) -> "watchdog" diff --git a/src/main/java/at/lorenz/mod/chat/PlayerChatFilter.kt b/src/main/java/at/lorenz/mod/chat/PlayerChatFilter.kt index b8ec7f87f..db8afe4cd 100644 --- a/src/main/java/at/lorenz/mod/chat/PlayerChatFilter.kt +++ b/src/main/java/at/lorenz/mod/chat/PlayerChatFilter.kt @@ -1,78 +1,89 @@ package at.lorenz.mod.chat +import at.lorenz.mod.events.LorenzChatEvent import at.lorenz.mod.utils.LorenzLogger import at.lorenz.mod.utils.LorenzUtils import at.lorenz.mod.utils.LorenzUtils.removeColorCodes import at.lorenz.mod.events.PlayerSendChatEvent +import com.thatgravyboat.skyblockhud.LorenzMod +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class PlayerChatFilter { - companion object { - val loggerPlayerChat = LorenzLogger("chat/player") + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!LorenzMod.feature.chat.playerMessages) return - fun shouldBlock(originalMessage: String): Boolean { - val split: List<String> = if (originalMessage.contains("§7§r§7: ")) { - originalMessage.split("§7§r§7: ") - } else if (originalMessage.contains("§f: ")) { - originalMessage.split("§f: ") - } else { - return false - } + if (shouldBlock(event.message)) { + event.blockedReason = "player_chat" + } + } - var rawName = split[0] - val message = split[1] - - val channel: PlayerMessageChannel - if (rawName.startsWith("§9Party §8> ")) { - channel = PlayerMessageChannel.PARTY - rawName = rawName.substring(12) - } else if (rawName.startsWith("§2Guild > ")) { - channel = PlayerMessageChannel.GUILD - rawName = rawName.substring(10) - } else if (rawName.startsWith("§bCo-op > ")) { - channel = PlayerMessageChannel.COOP - rawName = rawName.substring(10) - } else { - channel = PlayerMessageChannel.ALL - } + val loggerPlayerChat = LorenzLogger("chat/player") - val nameSplit = rawName.split(" ") - val first = nameSplit[0] + fun shouldBlock(originalMessage: String): Boolean { + val split: List<String> = if (originalMessage.contains("§7§r§7: ")) { + originalMessage.split("§7§r§7: ") + } else if (originalMessage.contains("§f: ")) { + originalMessage.split("§f: ") + } else { + return false + } - val last = nameSplit.last() - val name = if (last.endsWith("]")) { - nameSplit[nameSplit.size - 2] - } else { - last - } + var rawName = split[0] + val message = split[1] - if (first != name) { - if (!first.contains("VIP") && !first.contains("MVP")) { - //TODO support yt + admin - return false - } - } + val channel: PlayerMessageChannel + if (rawName.startsWith("§9Party §8> ")) { + channel = PlayerMessageChannel.PARTY + rawName = rawName.substring(12) + } else if (rawName.startsWith("§2Guild > ")) { + channel = PlayerMessageChannel.GUILD + rawName = rawName.substring(10) + } else if (rawName.startsWith("§bCo-op > ")) { + channel = PlayerMessageChannel.COOP + rawName = rawName.substring(10) + } else { + channel = PlayerMessageChannel.ALL + } + + val nameSplit = rawName.split(" ") + val first = nameSplit[0] - send(channel, name.removeColorCodes(), message.removeColorCodes()) - return true + val last = nameSplit.last() + val name = if (last.endsWith("]")) { + nameSplit[nameSplit.size - 2] + } else { + last } - private fun send(channel: PlayerMessageChannel, name: String, message: String) { - loggerPlayerChat.log("[$channel] $name: $message") - val event = PlayerSendChatEvent(channel, name, message) - event.postAndCatch() - - if (event.cancelledReason != "") { - loggerPlayerChat.log("cancelled: " + event.cancelledReason) - } else { - val finalMessage = event.message - if (finalMessage != message) { - loggerPlayerChat.log("message changed: $finalMessage") - } - - val prefix = channel.prefix - LorenzUtils.chat("$prefix §b$name §f$finalMessage") + if (first != name) { + if (!first.contains("VIP") && !first.contains("MVP")) { + //TODO support yt + admin + return false } } + + send(channel, name.removeColorCodes(), message.removeColorCodes()) + return true } + + private fun send(channel: PlayerMessageChannel, name: String, message: String) { + loggerPlayerChat.log("[$channel] $name: $message") + val event = PlayerSendChatEvent(channel, name, message) + event.postAndCatch() + + if (event.cancelledReason != "") { + loggerPlayerChat.log("cancelled: " + event.cancelledReason) + } else { + val finalMessage = event.message + if (finalMessage != message) { + loggerPlayerChat.log("message changed: $finalMessage") + } + + val prefix = channel.prefix + LorenzUtils.chat("$prefix §b$name §f$finalMessage") + } + } + }
\ No newline at end of file diff --git a/src/main/java/at/lorenz/mod/config/Features.java b/src/main/java/at/lorenz/mod/config/Features.java index 6c484290d..988b65f76 100644 --- a/src/main/java/at/lorenz/mod/config/Features.java +++ b/src/main/java/at/lorenz/mod/config/Features.java @@ -90,6 +90,11 @@ public class Features extends Config { @ConfigOption(name = "Main Chat Filter", desc = "Hides all the annoying chat messages.") @ConfigEditorBoolean public boolean mainFilter = true; + + @Expose + @ConfigOption(name = "Player Messages", desc = "Add a fancy new chat format for player messages.") + @ConfigEditorBoolean + public boolean playerMessages = false; } public static class Dungeon { |