From d7955826cd13c8c9c22964ad79e558fcec2795de Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 22 Jul 2025 17:04:10 +0200 Subject: [PATCH 01/11] Small clarification --- src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt index 68c963f..27cb729 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt @@ -46,12 +46,12 @@ internal class ChatOG : JavaPlugin() { if (Companion.config.openAIEnabled) { if (Companion.config.openAIBaseUrl == null) { this.logger.warning( - "You have enabled OpenAI but have not set up the base url, not enabling the translator" + "You have enabled OpenAI translation but have not set up the base url, not enabling the translator" ) null } else if (Companion.config.openAIApiKey == null) { this.logger.warning( - "You have enabled OpenAI but have not set up the api key, not enabling the translator" + "You have enabled OpenAI translation but have not set up the api key, not enabling the translator" ) null } else { -- 2.47.3 From 08148a57b1ff119fd14330efac165996bd7b7a60 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 22 Jul 2025 22:14:38 +0200 Subject: [PATCH 02/11] Ding in Minecraft for mentions --- .../nl/skbotnl/chatog/BlocklistManager.kt | 2 +- .../kotlin/nl/skbotnl/chatog/ChatHelper.kt | 20 +++++++++++++++++++ src/main/kotlin/nl/skbotnl/chatog/Events.kt | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/nl/skbotnl/chatog/BlocklistManager.kt b/src/main/kotlin/nl/skbotnl/chatog/BlocklistManager.kt index 5d5e192..4b7b2fa 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/BlocklistManager.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/BlocklistManager.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.launch class BlocklistManager { private val lock = Any() - private var blockList = mutableListOf() + private val blockList = mutableListOf() init { ChatOG.plugin.logger.info("Loading the blocklists...") diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatHelper.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatHelper.kt index 2a9606e..b12e32c 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatHelper.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatHelper.kt @@ -1,9 +1,14 @@ package nl.skbotnl.chatog +import java.util.UUID import me.clip.placeholderapi.PlaceholderAPI +import net.kyori.adventure.text.Component import net.kyori.adventure.text.TextComponent +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer import net.trueog.utilitiesog.UtilitiesOG import nl.skbotnl.chatog.Helper.legacyToMm +import org.bukkit.Bukkit +import org.bukkit.Sound import org.bukkit.entity.Player internal object ChatHelper { @@ -29,4 +34,19 @@ internal object ChatHelper { return playerPart } + + val mentionRegex = Regex("@([A-Za-z0-9_]{3,16})") + + fun dingForMentions(dontDingFor: UUID, component: Component) { + val messageContent = PlainTextComponentSerializer.plainText().serialize(component) + + val namesToMention = mutableListOf() + mentionRegex.findAll(messageContent).iterator().forEach { namesToMention += it.groups[1]!!.value.lowercase() } + + for (player in Bukkit.getOnlinePlayers()) { + if (player.uniqueId == dontDingFor) continue + if (player.name.lowercase() !in namesToMention) continue + player.playSound(player, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f) + } + } } diff --git a/src/main/kotlin/nl/skbotnl/chatog/Events.kt b/src/main/kotlin/nl/skbotnl/chatog/Events.kt index dc917b2..1cd779a 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/Events.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/Events.kt @@ -207,6 +207,8 @@ internal class Events : Listener { event.viewers().forEach { it.sendMessage(textComponent) } + ChatHelper.dingForMentions(event.player.uniqueId, messageComponent) + TranslateMessage.chatMessages[randomUUID] = TranslateMessage.SentChatMessage(eventMessage.content(), event.player) } -- 2.47.3 From 31cf6a4b2614aaae11bff768e197c27cea654b10 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 22 Jul 2025 22:23:46 +0200 Subject: [PATCH 03/11] Clean up and merge Helper and ChatHelper into ChatUtil --- .../kotlin/nl/skbotnl/chatog/ChatHelper.kt | 52 ---------------- .../kotlin/nl/skbotnl/chatog/ChatSystem.kt | 27 +++------ .../skbotnl/chatog/{Helper.kt => ChatUtil.kt} | 60 +++++++++++++++---- .../kotlin/nl/skbotnl/chatog/DiscordBridge.kt | 8 +-- src/main/kotlin/nl/skbotnl/chatog/Events.kt | 29 +++++---- .../kotlin/nl/skbotnl/chatog/PlayerAffix.kt | 34 +---------- .../skbotnl/chatog/commands/PrivateMessage.kt | 4 +- .../nl/skbotnl/chatog/commands/Reply.kt | 4 +- .../chatog/commands/TranslateMessage.kt | 6 +- 9 files changed, 83 insertions(+), 141 deletions(-) delete mode 100644 src/main/kotlin/nl/skbotnl/chatog/ChatHelper.kt rename src/main/kotlin/nl/skbotnl/chatog/{Helper.kt => ChatUtil.kt} (81%) mode change 100755 => 100644 diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatHelper.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatHelper.kt deleted file mode 100644 index b12e32c..0000000 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatHelper.kt +++ /dev/null @@ -1,52 +0,0 @@ -package nl.skbotnl.chatog - -import java.util.UUID -import me.clip.placeholderapi.PlaceholderAPI -import net.kyori.adventure.text.Component -import net.kyori.adventure.text.TextComponent -import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer -import net.trueog.utilitiesog.UtilitiesOG -import nl.skbotnl.chatog.Helper.legacyToMm -import org.bukkit.Bukkit -import org.bukkit.Sound -import org.bukkit.entity.Player - -internal object ChatHelper { - fun getPlayerPart(player: Player, addSuffix: Boolean): TextComponent { - val playerPartString = getPlayerPartString(player) - - val suffix = - if (addSuffix) { - PlayerAffix.getSuffix(player.uniqueId) - } else { - "" - } - - return UtilitiesOG.trueogColorize(legacyToMm("$playerPartString$suffix")) - } - - fun getPlayerPartString(player: Player): String { - var playerPart = "${PlayerAffix.getPrefix(player.uniqueId)}${player.name}" - - if (PlaceholderAPI.setPlaceholders(player, "%simpleclans_clan_color_tag%") != "") { - playerPart = PlaceholderAPI.setPlaceholders(player, "&8[%simpleclans_clan_color_tag%&8] $playerPart") - } - - return playerPart - } - - val mentionRegex = Regex("@([A-Za-z0-9_]{3,16})") - - fun dingForMentions(dontDingFor: UUID, component: Component) { - val messageContent = PlainTextComponentSerializer.plainText().serialize(component) - - val namesToMention = mutableListOf() - mentionRegex.findAll(messageContent).iterator().forEach { namesToMention += it.groups[1]!!.value.lowercase() } - - for (player in Bukkit.getOnlinePlayers()) { - if (player.uniqueId == dontDingFor) continue - if (player.name.lowercase() !in namesToMention) continue - player.playSound(player, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f) - } - } -} diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt index c580238..f3b3234 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt @@ -11,8 +11,7 @@ import net.kyori.adventure.text.event.HoverEvent import net.trueog.utilitiesog.UtilitiesOG import nl.skbotnl.chatog.ChatOG.Companion.config import nl.skbotnl.chatog.ChatOG.Companion.discordBridgeLock -import nl.skbotnl.chatog.Helper.legacyToMm -import nl.skbotnl.chatog.Helper.removeColor +import nl.skbotnl.chatog.ChatUtil.legacyToMm import nl.skbotnl.chatog.commands.TranslateMessage import org.bukkit.Bukkit import org.bukkit.entity.Player @@ -28,24 +27,20 @@ internal object ChatSystem { var inChat: MutableMap = HashMap() fun sendMessageInStaffChat(player: Player, text: String) { - var playerPartString = ChatHelper.getPlayerPartString(player) + var playerPartString = ChatUtil.getPlayerPartString(player) playerPartString = "&cSTAFF | $playerPartString" if (config.staffDiscordEnabled) { - val discordMessageString = Helper.convertEmojis(text) + val discordMessageString = ChatUtil.convertEmojis(text) ChatOG.scope.launch { discordBridgeLock.read { - ChatOG.discordBridge?.sendStaffMessage( - discordMessageString, - removeColor(playerPartString), - player.uniqueId, - ) + ChatOG.discordBridge?.sendStaffMessage(discordMessageString, playerPartString, player.uniqueId) } } } - val messageComponent = Helper.processText(text, player) + val messageComponent = ChatUtil.processText(text, player) if (messageComponent == null) { return } @@ -78,24 +73,20 @@ internal object ChatSystem { } fun sendMessageInPremiumChat(player: Player, text: String) { - var playerPartString = ChatHelper.getPlayerPartString(player) + var playerPartString = ChatUtil.getPlayerPartString(player) playerPartString = "&aPREMIUM | $playerPartString" if (config.premiumDiscordEnabled) { - val discordMessageString = Helper.convertEmojis(text) + val discordMessageString = ChatUtil.convertEmojis(text) ChatOG.scope.launch { discordBridgeLock.read { - ChatOG.discordBridge?.sendPremiumMessage( - discordMessageString, - removeColor(playerPartString), - player.uniqueId, - ) + ChatOG.discordBridge?.sendPremiumMessage(discordMessageString, playerPartString, player.uniqueId) } } } - val messageComponent = Helper.processText(text, player) + val messageComponent = ChatUtil.processText(text, player) if (messageComponent == null) { return } diff --git a/src/main/kotlin/nl/skbotnl/chatog/Helper.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt old mode 100755 new mode 100644 similarity index 81% rename from src/main/kotlin/nl/skbotnl/chatog/Helper.kt rename to src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt index 4d9339f..c827d09 --- a/src/main/kotlin/nl/skbotnl/chatog/Helper.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt @@ -1,9 +1,13 @@ package nl.skbotnl.chatog import dev.minn.jda.ktx.coroutines.await -import java.util.* +import java.util.HashMap +import java.util.UUID +import kotlin.collections.forEach import kotlin.concurrent.read +import me.clip.placeholderapi.PlaceholderAPI import net.kyori.adventure.text.Component +import net.kyori.adventure.text.TextComponent import net.kyori.adventure.text.event.ClickEvent import net.kyori.adventure.text.event.HoverEvent import net.kyori.adventure.text.format.TextColor @@ -13,14 +17,54 @@ import net.kyori.adventure.text.minimessage.tag.Tag import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver import net.kyori.adventure.text.minimessage.tag.standard.StandardTags +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer import net.trueog.utilitiesog.UtilitiesOG import nl.skbotnl.chatog.ChatOG.Companion.blocklistManager import nl.skbotnl.chatog.ChatOG.Companion.config import nl.skbotnl.chatog.ChatOG.Companion.discordBridgeLock import org.bukkit.Bukkit +import org.bukkit.Sound import org.bukkit.entity.Player -internal object Helper { +internal object ChatUtil { + fun getPlayerPart(player: Player, addSuffix: Boolean): TextComponent { + val playerPartString = getPlayerPartString(player) + + val suffix = + if (addSuffix) { + PlayerAffix.getSuffix(player.uniqueId) + } else { + "" + } + + return UtilitiesOG.trueogColorize(legacyToMm("$playerPartString$suffix")) + } + + fun getPlayerPartString(player: Player): String { + var playerPart = "${PlayerAffix.getPrefix(player.uniqueId)}${player.name}" + + if (PlaceholderAPI.setPlaceholders(player, "%simpleclans_clan_color_tag%") != "") { + playerPart = PlaceholderAPI.setPlaceholders(player, "&8[%simpleclans_clan_color_tag%&8] $playerPart") + } + + return playerPart + } + + val mentionRegex = Regex("@([A-Za-z0-9_]{3,16})") + + fun dingForMentions(dontDingFor: UUID, component: Component) { + val messageContent = PlainTextComponentSerializer.plainText().serialize(component) + + val namesToMention = mutableListOf() + mentionRegex.findAll(messageContent).iterator().forEach { namesToMention += it.groups[1]!!.value.lowercase() } + + for (player in Bukkit.getOnlinePlayers()) { + if (player.uniqueId == dontDingFor) continue + if (player.name.lowercase() !in namesToMention) continue + player.playSound(player, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f) + } + } + private var translateTimeout: MutableMap = HashMap() fun getTranslateTimeout(uuid: UUID): Long { @@ -70,14 +114,6 @@ internal object Helper { return legacyRegex.replace(text) { legacyToMmMap[it.groupValues[1].lowercase()] ?: it.value } } - private val colorRegex = Regex("[§&]?[§&]([0-9a-fk-orA-FK-OR])") - - fun removeColor(text: String): String { - var tempText = text - colorRegex.findAll(text).iterator().forEach { tempText = tempText.replace(it.value, "") } - return tempText - } - private val getHandle = Regex("@([a-z0-9_.]{2,32})") suspend fun convertMentions(text: String): String { @@ -103,7 +139,7 @@ internal object Helper { private val urlRegex = Regex("(.*?)((?:https?://)?[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}(?:/?[a-zA-Z]*)+)(.*)") - val noColorMm = MiniMessage.builder().editTags { b -> b.tag("a", Helper::createA) }.build() + val noColorMm = MiniMessage.builder().editTags { b -> b.tag("a", ChatUtil::createA) }.build() val colorMm = MiniMessage.builder() @@ -117,7 +153,7 @@ internal object Helper { .resolver(StandardTags.gradient()) .build() ) - .editTags { b -> b.tag("a", Helper::createA) } + .editTags { b -> b.tag("a", ChatUtil::createA) } .build() fun createA(args: ArgumentQueue, @Suppress("unused") ctx: Context): Tag { diff --git a/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt b/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt index 1a27195..eae34f2 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt @@ -29,8 +29,8 @@ import net.kyori.adventure.text.format.NamedTextColor import net.kyori.adventure.text.format.TextColor import net.trueog.utilitiesog.UtilitiesOG import nl.skbotnl.chatog.ChatOG.Companion.config -import nl.skbotnl.chatog.Helper.convertMentions -import nl.skbotnl.chatog.Helper.stripGroupMentions +import nl.skbotnl.chatog.ChatUtil.convertMentions +import nl.skbotnl.chatog.ChatUtil.stripGroupMentions import nl.skbotnl.chatog.commands.TranslateMessage import org.bukkit.Bukkit import org.bukkit.entity.Player @@ -245,7 +245,7 @@ internal class DiscordBridge private constructor() { if (message.contentDisplay != "") { messageComponents += - Helper.processText( + ChatUtil.processText( EmojiConverter.replaceEmojisWithNames(message.contentDisplay), "@${user.name}", ) @@ -381,7 +381,7 @@ internal class DiscordBridge private constructor() { suspend fun sendMessage(message: String, player: Player) { val webhookMessage = WebhookMessageBuilder() - .setUsername(UtilitiesOG.stripFormatting(ChatHelper.getPlayerPartString(player))) + .setUsername(UtilitiesOG.stripFormatting(ChatUtil.getPlayerPartString(player))) .setContent(UtilitiesOG.stripFormatting(stripGroupMentions(convertMentions(message)))) .setAvatarUrl("https://minotar.net/helm/${player.uniqueId}.png") diff --git a/src/main/kotlin/nl/skbotnl/chatog/Events.kt b/src/main/kotlin/nl/skbotnl/chatog/Events.kt index 1cd779a..47916f2 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/Events.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/Events.kt @@ -21,8 +21,7 @@ import net.trueog.utilitiesog.UtilitiesOG import nl.skbotnl.chatog.ChatOG.Companion.config import nl.skbotnl.chatog.ChatOG.Companion.discordBridgeLock import nl.skbotnl.chatog.ChatSystem.ChatType -import nl.skbotnl.chatog.Helper.legacyToMm -import nl.skbotnl.chatog.Helper.removeColor +import nl.skbotnl.chatog.ChatUtil.legacyToMm import nl.skbotnl.chatog.commands.TranslateMessage import org.bukkit.Bukkit import org.bukkit.event.EventHandler @@ -43,7 +42,7 @@ internal class Events : Listener { return } - val playerPartString = ChatHelper.getPlayerPartString(event.player) + val playerPartString = ChatUtil.getPlayerPartString(event.player) ChatOG.scope.launch { discordBridgeLock.read { @@ -67,12 +66,12 @@ internal class Events : Listener { return } - val playerPartString = ChatHelper.getPlayerPartString(event.player) + val playerPartString = ChatUtil.getPlayerPartString(event.player) ChatOG.scope.launch { discordBridgeLock.read { ChatOG.discordBridge?.sendEmbed( - "${removeColor(playerPartString)} has left the game. ${ + "$playerPartString has left the game. ${ Bukkit.getOnlinePlayers().count() - 1 } player(s) online.", event.player.uniqueId, @@ -91,14 +90,14 @@ internal class Events : Listener { return } - val playerPartString = ChatHelper.getPlayerPartString(event.player) + val playerPartString = ChatUtil.getPlayerPartString(event.player) val reason = PlainTextComponentSerializer.plainText().serialize(event.reason()) ChatOG.scope.launch { discordBridgeLock.read { ChatOG.discordBridge?.sendEmbed( - "${removeColor(playerPartString)} was kicked with reason: \"${reason}\". ${ + "$playerPartString was kicked with reason: \"${reason}\". ${ Bukkit.getOnlinePlayers().count() - 1 } player(s) online.", event.player.uniqueId, @@ -117,7 +116,7 @@ internal class Events : Listener { return } - val playerPartString = ChatHelper.getPlayerPartString(event.player) + val playerPartString = ChatUtil.getPlayerPartString(event.player) val advancementTitleKey = event.advancement.display?.title() ?: return val advancementTitle = PlainTextComponentSerializer.plainText().serialize(advancementTitleKey) @@ -135,7 +134,7 @@ internal class Events : Listener { ChatOG.scope.launch { discordBridgeLock.read { ChatOG.discordBridge?.sendEmbed( - "${removeColor(playerPartString)} $advancementMessage.", + "$playerPartString $advancementMessage.", event.player.uniqueId, 0xFFFF00, ) @@ -178,14 +177,14 @@ internal class Events : Listener { return } - val discordMessageString = Helper.convertEmojis(eventMessage.content()) + val discordMessageString = ChatUtil.convertEmojis(eventMessage.content()) ChatOG.scope.launch { discordBridgeLock.read { ChatOG.discordBridge?.sendMessage(discordMessageString, event.player) } } - val playerPart = ChatHelper.getPlayerPart(event.player, true) + val playerPart = ChatUtil.getPlayerPart(event.player, true) - val messageComponent = Helper.processText(eventMessage.content(), event.player) + val messageComponent = ChatUtil.processText(eventMessage.content(), event.player) if (messageComponent == null) { return } @@ -207,7 +206,7 @@ internal class Events : Listener { event.viewers().forEach { it.sendMessage(textComponent) } - ChatHelper.dingForMentions(event.player.uniqueId, messageComponent) + ChatUtil.dingForMentions(event.player.uniqueId, messageComponent) TranslateMessage.chatMessages[randomUUID] = TranslateMessage.SentChatMessage(eventMessage.content(), event.player) @@ -226,7 +225,7 @@ internal class Events : Listener { ChatOG.scope.launch { discordBridgeLock.read { ChatOG.discordBridge?.sendEmbed( - removeColor((event.deathMessage() as TextComponent).content()), + (event.deathMessage() as TextComponent).content(), event.player.uniqueId, 0xFF0000, ) @@ -256,7 +255,7 @@ internal class Events : Listener { ChatOG.scope.launch { discordBridgeLock.read { - ChatOG.discordBridge?.sendEmbed(removeColor(translatedDeathMessage), event.player.uniqueId, 0xFF0000) + ChatOG.discordBridge?.sendEmbed(translatedDeathMessage, event.player.uniqueId, 0xFF0000) } } } diff --git a/src/main/kotlin/nl/skbotnl/chatog/PlayerAffix.kt b/src/main/kotlin/nl/skbotnl/chatog/PlayerAffix.kt index d42189c..e93c030 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/PlayerAffix.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/PlayerAffix.kt @@ -1,41 +1,9 @@ package nl.skbotnl.chatog import java.util.* +import nl.skbotnl.chatog.ChatUtil.legacyToMm internal object PlayerAffix { - private val legacyToMmMap = - mapOf( - "0" to "", - "1" to "", - "2" to "", - "3" to "", - "4" to "", - "5" to "", - "6" to "", - "7" to "", - "8" to "", - "9" to "", - "a" to "", - "b" to "", - "c" to "", - "d" to "", - "e" to "", - "f" to "", - "k" to "", - "l" to "", - "m" to "", - "n" to "", - "o" to "", - "r" to "", - "*" to "", - ) - - val legacyRegex = Regex("[§&]([0-9a-fk-or*])", RegexOption.IGNORE_CASE) - - fun legacyToMm(text: String): String { - return legacyRegex.replace(text) { legacyToMmMap[it.groupValues[1].lowercase()] ?: it.value } - } - fun getPrefix(uuid: UUID): String { var user = ChatOG.luckPerms.userManager.getUser(uuid) if (user == null) { diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/PrivateMessage.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/PrivateMessage.kt index 01bdd64..110e0ae 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/PrivateMessage.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/PrivateMessage.kt @@ -9,7 +9,7 @@ import net.kyori.adventure.text.event.HoverEvent import net.trueog.utilitiesog.UtilitiesOG import nl.skbotnl.chatog.ChatOG.Companion.config import nl.skbotnl.chatog.ChatOG.Companion.lastMessagedMap -import nl.skbotnl.chatog.Helper +import nl.skbotnl.chatog.ChatUtil import org.bukkit.Bukkit import org.bukkit.command.Command import org.bukkit.command.CommandExecutor @@ -57,7 +57,7 @@ internal class PrivateMessage : CommandExecutor { TranslateMessage.pmMessages[randomUUID] = TranslateMessage.SentPMMessage(message, sender.uniqueId, toPlayer.uniqueId) - val messageComponent = Helper.processText(message, sender) + val messageComponent = ChatUtil.processText(message, sender) if (messageComponent == null) { return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/Reply.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/Reply.kt index 8dbcf9a..1a3e20a 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/Reply.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/Reply.kt @@ -9,7 +9,7 @@ import net.kyori.adventure.text.event.HoverEvent import net.trueog.utilitiesog.UtilitiesOG import nl.skbotnl.chatog.ChatOG.Companion.config import nl.skbotnl.chatog.ChatOG.Companion.lastMessagedMap -import nl.skbotnl.chatog.Helper +import nl.skbotnl.chatog.ChatUtil import org.bukkit.Bukkit import org.bukkit.command.Command import org.bukkit.command.CommandExecutor @@ -53,7 +53,7 @@ internal class Reply : CommandExecutor { TranslateMessage.pmMessages[randomUUID] = TranslateMessage.SentPMMessage(message, sender.uniqueId, toPlayer.uniqueId) - val messageComponent = Helper.processText(message, sender) + val messageComponent = ChatUtil.processText(message, sender) if (messageComponent == null) { return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateMessage.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateMessage.kt index ebe4f59..2825fbf 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateMessage.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateMessage.kt @@ -9,8 +9,8 @@ import net.kyori.adventure.text.format.NamedTextColor import net.trueog.utilitiesog.UtilitiesOG import nl.skbotnl.chatog.ChatOG import nl.skbotnl.chatog.ChatOG.Companion.config -import nl.skbotnl.chatog.Helper -import nl.skbotnl.chatog.Helper.legacyToMm +import nl.skbotnl.chatog.ChatUtil +import nl.skbotnl.chatog.ChatUtil.legacyToMm import nl.skbotnl.chatog.PlayerAffix import org.bukkit.Bukkit import org.bukkit.command.Command @@ -56,7 +56,7 @@ internal class TranslateMessage : CommandExecutor { } val player: Player = sender - if (Helper.getTranslateTimeout(player.uniqueId) != 0L) { + if (ChatUtil.getTranslateTimeout(player.uniqueId) != 0L) { player.sendMessage(UtilitiesOG.trueogColorize("${config.prefix}: You're doing that too fast.")) return true } -- 2.47.3 From 40056e76b3e6f024afff7fcc7ca0e244a4f7ac4f Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 22 Jul 2025 22:46:58 +0200 Subject: [PATCH 04/11] Configurable blocklists and config improvements --- .../nl/skbotnl/chatog/BlocklistManager.kt | 7 +- src/main/kotlin/nl/skbotnl/chatog/ChatAPI.kt | 18 ++--- src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt | 22 +++--- .../kotlin/nl/skbotnl/chatog/ChatSystem.kt | 4 +- src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt | 10 +-- src/main/kotlin/nl/skbotnl/chatog/Config.kt | 17 ++++- .../kotlin/nl/skbotnl/chatog/DiscordBridge.kt | 71 ++++++++++--------- src/main/kotlin/nl/skbotnl/chatog/Events.kt | 12 ++-- .../nl/skbotnl/chatog/LanguageDatabase.kt | 2 +- src/main/kotlin/nl/skbotnl/chatog/OpenAI.kt | 8 +-- .../chatog/commands/ChatConfigReload.kt | 33 ++++++++- .../nl/skbotnl/chatog/commands/PremiumChat.kt | 6 +- .../skbotnl/chatog/commands/PrivateMessage.kt | 6 +- .../nl/skbotnl/chatog/commands/Reply.kt | 6 +- .../nl/skbotnl/chatog/commands/StaffChat.kt | 6 +- .../chatog/commands/TranslateMessage.kt | 22 +++--- .../chatog/commands/TranslateSettings.kt | 4 +- src/main/resources/config.yml | 5 ++ 18 files changed, 156 insertions(+), 103 deletions(-) diff --git a/src/main/kotlin/nl/skbotnl/chatog/BlocklistManager.kt b/src/main/kotlin/nl/skbotnl/chatog/BlocklistManager.kt index 4b7b2fa..cf49909 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/BlocklistManager.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/BlocklistManager.kt @@ -24,14 +24,13 @@ class BlocklistManager { private fun refresh() { blockList.clear() - URI("https://raw.githubusercontent.com/hagezi/dns-blocklists/main/domains/multi.txt") - .toURL() - .openStream() - .use { input -> + ChatOG.config!!.blocklists.forEach { blocklist -> + URI(blocklist).toURL().openStream().use { input -> input.bufferedReader().use { bufferedReader -> synchronized(lock) { bufferedReader.lines().forEach { if (!it.startsWith("#")) blockList.add(it) } } } } + } } private val urlRegex = Regex("(?:https?://)?([a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})") diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatAPI.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatAPI.kt index f9fb2c5..06c9014 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatAPI.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatAPI.kt @@ -10,22 +10,22 @@ import org.bukkit.entity.Player class ChatAPI { @Suppress("unused") fun isDiscordEnabled(): Boolean { - return ChatOG.config.discordEnabled + return ChatOG.config!!.discordEnabled } @Suppress("unused") fun isStaffDiscordEnabled(): Boolean { - return ChatOG.config.staffDiscordEnabled + return ChatOG.config!!.staffDiscordEnabled } @Suppress("unused") fun isPremiumDiscordEnabled(): Boolean { - return ChatOG.config.premiumDiscordEnabled + return ChatOG.config!!.premiumDiscordEnabled } @Suppress("unused") fun sendMessageWithBot(message: String) { - if (!ChatOG.config.discordEnabled) return + if (!ChatOG.config!!.discordEnabled) return scope.launch { discordBridgeLock.read { val discordBridge = ChatOG.discordBridge @@ -37,7 +37,7 @@ class ChatAPI { @Suppress("unused") fun sendMessage(message: String, player: Player) { - if (!ChatOG.config.discordEnabled) return + if (!ChatOG.config!!.discordEnabled) return discordBridgeLock.read { val discordBridge = ChatOG.discordBridge scope.launch { discordBridge!!.sendMessage(message, player) } @@ -47,7 +47,7 @@ class ChatAPI { @Suppress("unused") fun sendMessage(message: String, name: String, uuid: UUID?) { - if (!ChatOG.config.discordEnabled) return + if (!ChatOG.config!!.discordEnabled) return discordBridgeLock.read { val discordBridge = ChatOG.discordBridge scope.launch { discordBridge!!.sendMessage(message, name, uuid) } @@ -57,7 +57,7 @@ class ChatAPI { @Suppress("unused") fun sendStaffMessage(message: String, name: String, uuid: UUID?) { - if (!ChatOG.config.discordEnabled) return + if (!ChatOG.config!!.discordEnabled) return discordBridgeLock.read { val discordBridge = ChatOG.discordBridge scope.launch { discordBridge!!.sendStaffMessage(message, name, uuid) } @@ -67,7 +67,7 @@ class ChatAPI { @Suppress("unused") fun sendPremiumMessage(message: String, name: String, uuid: UUID?) { - if (!ChatOG.config.discordEnabled) return + if (!ChatOG.config!!.discordEnabled) return discordBridgeLock.read { val discordBridge = ChatOG.discordBridge scope.launch { discordBridge!!.sendPremiumMessage(message, name, uuid) } @@ -77,7 +77,7 @@ class ChatAPI { @Suppress("unused") fun sendEmbed(message: String, uuid: UUID?, color: Int?) { - if (!ChatOG.config.discordEnabled) return + if (!ChatOG.config!!.discordEnabled) return discordBridgeLock.read { val discordBridge = ChatOG.discordBridge scope.launch { discordBridge!!.sendEmbed(message, uuid, color) } diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt index 27cb729..0c4f4ce 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt @@ -18,8 +18,8 @@ internal class ChatOG : JavaPlugin() { val scope = CoroutineScope(Dispatchers.Default + SupervisorJob()) lateinit var plugin: JavaPlugin - lateinit var config: Config - lateinit var blocklistManager: BlocklistManager + var config: Config? = null + var blocklistManager: BlocklistManager? = null lateinit var luckPerms: LuckPerms lateinit var languageDatabase: LanguageDatabase var translator: OpenAI? = null @@ -40,16 +40,18 @@ internal class ChatOG : JavaPlugin() { return } - blocklistManager = BlocklistManager() + if (Companion.config!!.blocklistEnabled) { + blocklistManager = BlocklistManager() + } translator = - if (Companion.config.openAIEnabled) { - if (Companion.config.openAIBaseUrl == null) { + if (Companion.config!!.openAIEnabled) { + if (Companion.config!!.openAIBaseUrl == null) { this.logger.warning( "You have enabled OpenAI translation but have not set up the base url, not enabling the translator" ) null - } else if (Companion.config.openAIApiKey == null) { + } else if (Companion.config!!.openAIApiKey == null) { this.logger.warning( "You have enabled OpenAI translation but have not set up the api key, not enabling the translator" ) @@ -91,7 +93,7 @@ internal class ChatOG : JavaPlugin() { this.getCommand("reply")?.setExecutor(Reply()) this.getCommand("r")?.setExecutor(Reply()) - if (Companion.config.discordEnabled) { + if (Companion.config!!.discordEnabled) { scope.launch { discordBridgeLock.write { discordBridge = DiscordBridge.create() } } } @@ -100,17 +102,17 @@ internal class ChatOG : JavaPlugin() { } override fun onDisable() { - if (Companion.config.discordEnabled) { + if (Companion.config?.discordEnabled == true) { discordBridgeLock.read { val discordBridge = discordBridge val serverHasStoppedMessage = - if (Companion.config.serverHasStoppedMessage == null) { + if (Companion.config!!.serverHasStoppedMessage == null) { this.logger.warning( "You have enabled Discord but have not set up the server has stopped message, using the default one instead" ) "The server has stopped" } else { - Companion.config.serverHasStoppedMessage!! + Companion.config!!.serverHasStoppedMessage!! } discordBridge!!.sendMessageWithBot(serverHasStoppedMessage) discordBridge.shutdownNow() diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt index f3b3234..82536c0 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt @@ -30,7 +30,7 @@ internal object ChatSystem { var playerPartString = ChatUtil.getPlayerPartString(player) playerPartString = "&cSTAFF | $playerPartString" - if (config.staffDiscordEnabled) { + if (config!!.staffDiscordEnabled) { val discordMessageString = ChatUtil.convertEmojis(text) ChatOG.scope.launch { @@ -76,7 +76,7 @@ internal object ChatSystem { var playerPartString = ChatUtil.getPlayerPartString(player) playerPartString = "&aPREMIUM | $playerPartString" - if (config.premiumDiscordEnabled) { + if (config!!.premiumDiscordEnabled) { val discordMessageString = ChatUtil.convertEmojis(text) ChatOG.scope.launch { diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt index c827d09..1b7a581 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt @@ -117,7 +117,7 @@ internal object ChatUtil { private val getHandle = Regex("@([a-z0-9_.]{2,32})") suspend fun convertMentions(text: String): String { - val guild = discordBridgeLock.read { ChatOG.discordBridge?.getGuildById(config.guildId!!) } + val guild = discordBridgeLock.read { ChatOG.discordBridge?.getGuildById(config!!.guildId!!) } if (guild == null) { ChatOG.plugin.logger.warning("Guild was null") return text @@ -184,17 +184,17 @@ internal object ChatUtil { if (url != null) { val link = url.groups[2]?.value ?: "" - if (blocklistManager.checkUrl(link)) { + if (blocklistManager?.checkUrl(link) == true) { player?.sendMessage( UtilitiesOG.trueogColorize( - "${config.prefix}: WARNING: You are not allowed to post links like that here." + "${config!!.prefix}: WARNING: You are not allowed to post links like that here." ) ) for (onlinePlayer in Bukkit.getOnlinePlayers()) { if (onlinePlayer.hasPermission("group.moderator")) { onlinePlayer.sendMessage( UtilitiesOG.trueogColorize( - "${config.prefix}: ${player?.name ?: username} has posted a disallowed link: ${ + "${config!!.prefix}: ${player?.name ?: username} has posted a disallowed link: ${ word.replace( ".", "[dot]", @@ -226,7 +226,7 @@ internal object ChatUtil { fun convertEmojis(text: String): String { var discordMessageString = text - val guildEmojis = discordBridgeLock.read { ChatOG.discordBridge?.getGuildById(config.guildId!!)?.emojis } + val guildEmojis = discordBridgeLock.read { ChatOG.discordBridge?.getGuildById(config!!.guildId!!)?.emojis } if (guildEmojis == null) { ChatOG.plugin.logger.warning("Guild emojis was null") } diff --git a/src/main/kotlin/nl/skbotnl/chatog/Config.kt b/src/main/kotlin/nl/skbotnl/chatog/Config.kt index 7c71df2..fe3f165 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/Config.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/Config.kt @@ -6,6 +6,8 @@ import org.bukkit.configuration.file.YamlConfiguration internal class Config private constructor() { lateinit var prefix: String + var blocklistEnabled = false + var blocklists = listOf() lateinit var redisUrl: String var openAIEnabled = false var openAIBaseUrl: String? = null @@ -27,8 +29,8 @@ internal class Config private constructor() { var premiumWebhook: String? = null var listCommandName: String? = null var listCommandText: String? = null - var colorCodeRoles: List = listOf() - var roles: Set = setOf() + var colorCodeRoles = listOf() + var roles = setOf() var roleMessageColor: MutableMap = mutableMapOf() data class RGBColor(val r: Int, val g: Int, val b: Int) @@ -50,6 +52,17 @@ internal class Config private constructor() { return null } + try { + config.blocklistEnabled = yamlConfig.get("blocklistEnabled") as Boolean + } catch (_: Exception) { + ChatOG.plugin.logger.severe("Failed to parse config option \"blocklistEnabled\" as a string") + return null + } + + if (config.blocklistEnabled) { + config.blocklists = yamlConfig.getStringList("blocklists") + } + try { config.redisUrl = yamlConfig.get("redisUrl") as String } catch (_: Exception) { diff --git a/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt b/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt index eae34f2..41aedab 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt @@ -44,9 +44,9 @@ internal class DiscordBridge private constructor() { companion object { fun create(): DiscordBridge? { val discordBridge = DiscordBridge() - if (config.webhook != null) { + if (config!!.webhook != null) { try { - discordBridge.webhook = WebhookClient.withUrl(config.webhook!!) + discordBridge.webhook = WebhookClient.withUrl(config!!.webhook!!) } catch (_: IllegalArgumentException) { ChatOG.plugin.logger.warning("Config option \"webhook\" is invalid") } @@ -54,87 +54,87 @@ internal class DiscordBridge private constructor() { ChatOG.plugin.logger.severe("You have enabled Discord but have not set up the webhook") return null } - if (config.staffWebhook != null) { + if (config!!.staffWebhook != null) { try { - discordBridge.staffWebhook = WebhookClient.withUrl(config.staffWebhook!!) + discordBridge.staffWebhook = WebhookClient.withUrl(config!!.staffWebhook!!) } catch (_: IllegalArgumentException) { ChatOG.plugin.logger.warning("Config option \"staffWebhook\" is invalid") } - } else if (config.staffDiscordEnabled) { + } else if (config!!.staffDiscordEnabled) { ChatOG.plugin.logger.warning("You have enabled staff Discord but have not set up the staff webhook") } - if (config.premiumWebhook != null) { + if (config!!.premiumWebhook != null) { try { - discordBridge.premiumWebhook = WebhookClient.withUrl(config.premiumWebhook!!) + discordBridge.premiumWebhook = WebhookClient.withUrl(config!!.premiumWebhook!!) } catch (_: IllegalArgumentException) { ChatOG.plugin.logger.warning("Config option \"premiumWebhook\" is invalid") } - } else if (config.premiumDiscordEnabled) { + } else if (config!!.premiumDiscordEnabled) { ChatOG.plugin.logger.warning("You have enabled premium Discord but have not set up the premium webhook") } - if (config.botToken == null) { + if (config!!.botToken == null) { ChatOG.plugin.logger.severe("You have enabled Discord but have not set up the bot token") return null } discordBridge.jda = - light(config.botToken!!, enableCoroutines = true) { + light(config!!.botToken!!, enableCoroutines = true) { intents += listOf(GatewayIntent.GUILD_MEMBERS, GatewayIntent.MESSAGE_CONTENT) cache += listOf(CacheFlag.EMOJI) setMemberCachePolicy(MemberCachePolicy.ALL) } val status = - if (config.status == null) { + if (config!!.status == null) { ChatOG.plugin.logger.warning( "You have enabled Discord but have not set up the status, using the default one instead" ) "Minecraft" } else { - config.status!! + config!!.status!! } discordBridge.jda.presence.setPresence(Activity.playing(status), false) val serverHasStartedMessage = - if (config.serverHasStartedMessage == null) { + if (config!!.serverHasStartedMessage == null) { ChatOG.plugin.logger.warning( "You have enabled Discord but have not set up the server has started message, using the default one instead" ) "The server has started" } else { - config.serverHasStartedMessage!! + config!!.serverHasStartedMessage!! } - if (config.guildId == null) { + if (config!!.guildId == null) { ChatOG.plugin.logger.severe("You have enabled Discord but have not set up the guild ID") return null } discordBridge.jda.listener { discordBridge.sendMessageWithBot(serverHasStartedMessage) - val guild = discordBridge.jda.getGuildById(config.guildId!!) + val guild = discordBridge.jda.getGuildById(config!!.guildId!!) if (guild == null) { ChatOG.plugin.logger.severe("Guild was null") return@listener } - if (config.listCommandName == null) { + if (config!!.listCommandName == null) { ChatOG.plugin.logger.warning( "You have enabled Discord but have not set up the list command name, the command will not be created" ) return@listener } - if (config.listCommandText == null) { + if (config!!.listCommandText == null) { ChatOG.plugin.logger.warning( "You have enabled Discord but have not set up the list command text, the command will not be created" ) } - guild.upsertCommand(config.listCommandName!!, "List all online players.").queue() + guild.upsertCommand(config!!.listCommandName!!, "List all online players.").queue() } discordBridge.jda.listener { - if (it.name == config.listCommandName) { + if (it.name == config!!.listCommandName) { it.deferReply().queue() try { if (Bukkit.getOnlinePlayers().isEmpty()) { @@ -144,7 +144,7 @@ internal class DiscordBridge private constructor() { it.hook .sendMessage( "${ - config.listCommandText!! + config!!.listCommandText!! .replace("%onlineplayers%", Bukkit.getOnlinePlayers().count().toString()) .replace("%maxplayers%", Bukkit.getMaxPlayers().toString()) }\n${ @@ -160,9 +160,9 @@ internal class DiscordBridge private constructor() { discordBridge.jda.listener { if ( - it.channel.id != config.channelId && - (if (config.staffDiscordEnabled) it.channel.id != config.staffChannelId else true) && - (if (config.premiumDiscordEnabled) it.channel.id != config.premiumChannelId else true) + it.channel.id != config!!.channelId && + (if (config!!.staffDiscordEnabled) it.channel.id != config!!.staffChannelId else true) && + (if (config!!.premiumDiscordEnabled) it.channel.id != config!!.premiumChannelId else true) ) { return@listener } @@ -195,18 +195,19 @@ internal class DiscordBridge private constructor() { } val messageColor = - if (config.roles.isEmpty()) { + if (config!!.roles.isEmpty()) { NamedTextColor.GRAY } else { val roleId = message.guild .getRoleById( - config.roles + config!! + .roles .filter { role -> topRole!!.id == message.guild.getRoleById(role)?.id }[0] ) ?.id if (roleId != null) { - val roleColor = config.roleMessageColor[roleId] + val roleColor = config!!.roleMessageColor[roleId] if (roleColor is Config.RGBColor) { TextColor.color(roleColor.r, roleColor.g, roleColor.b) @@ -273,7 +274,7 @@ internal class DiscordBridge private constructor() { var messageComponent = when (it.channel.id) { - config.staffChannelId -> { + config!!.staffChannelId -> { val staffComponent = Component.text("STAFF | ").color(NamedTextColor.RED) Component.join( JoinConfiguration.noSeparators(), @@ -285,7 +286,7 @@ internal class DiscordBridge private constructor() { ) } - config.premiumChannelId -> { + config!!.premiumChannelId -> { val premiumComponent = Component.text("PREMIUM | ").color(NamedTextColor.GREEN) Component.join( JoinConfiguration.noSeparators(), @@ -323,7 +324,7 @@ internal class DiscordBridge private constructor() { ) when (it.channel.id) { - config.staffChannelId -> { + config!!.staffChannelId -> { for (p in Bukkit.getOnlinePlayers()) { if (p.hasPermission("chat-og.staff")) { p.sendMessage(messageComponent) @@ -331,7 +332,7 @@ internal class DiscordBridge private constructor() { } } - config.premiumChannelId -> { + config!!.premiumChannelId -> { for (p in Bukkit.getOnlinePlayers()) { if (p.hasPermission("chat-og.premium")) { p.sendMessage(messageComponent) @@ -367,9 +368,9 @@ internal class DiscordBridge private constructor() { } fun sendMessageWithBot(message: String) { - if (config.channelId == null) return + if (config!!.channelId == null) return - val channel = jda.getChannel(config.channelId!!) + val channel = jda.getChannel(config!!.channelId!!) if (channel == null) { ChatOG.plugin.logger.warning("channelId has not been set or is invalid") return @@ -400,7 +401,7 @@ internal class DiscordBridge private constructor() { } suspend fun sendStaffMessage(message: String, name: String, uuid: UUID?) { - if (!config.staffDiscordEnabled) return + if (!config!!.staffDiscordEnabled) return if (staffWebhook == null) { ChatOG.plugin.logger.warning("staffWebhook has not been set or is invalid") @@ -418,7 +419,7 @@ internal class DiscordBridge private constructor() { } suspend fun sendPremiumMessage(message: String, name: String, uuid: UUID?) { - if (!config.premiumDiscordEnabled) return + if (!config!!.premiumDiscordEnabled) return if (premiumWebhook == null) { ChatOG.plugin.logger.warning("premiumWebhook has not been set or is invalid") diff --git a/src/main/kotlin/nl/skbotnl/chatog/Events.kt b/src/main/kotlin/nl/skbotnl/chatog/Events.kt index 47916f2..3087452 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/Events.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/Events.kt @@ -35,7 +35,7 @@ import xyz.jpenilla.announcerplus.listener.JoinQuitListener internal class Events : Listener { @EventHandler fun onJoin(event: PlayerJoinEvent) { - if (!config.discordEnabled) { + if (!config!!.discordEnabled) { return } if (ChatOG.essentials.getUser(event.player).isVanished && event.joinMessage() !is TextComponent) { @@ -59,7 +59,7 @@ internal class Events : Listener { @EventHandler fun onQuit(event: PlayerQuitEvent) { - if (!config.discordEnabled) { + if (!config!!.discordEnabled) { return } if (ChatOG.essentials.getUser(event.player).isVanished) { @@ -83,7 +83,7 @@ internal class Events : Listener { @EventHandler fun onKick(event: PlayerKickEvent) { - if (!config.discordEnabled) { + if (!config!!.discordEnabled) { return } if (ChatOG.essentials.getUser(event.player).isVanished) { @@ -109,7 +109,7 @@ internal class Events : Listener { @EventHandler fun onAdvancement(event: PlayerAdvancementDoneEvent) { - if (!config.discordEnabled) { + if (!config!!.discordEnabled) { return } if (ChatOG.essentials.getUser(event.player).isVanished) { @@ -144,7 +144,7 @@ internal class Events : Listener { @EventHandler fun onBroadcast(event: BroadcastMessageEvent) { - if (!config.discordEnabled) { + if (!config!!.discordEnabled) { return } if (event.message() !is TextComponent) { @@ -214,7 +214,7 @@ internal class Events : Listener { @EventHandler fun onDeath(event: PlayerDeathEvent) { - if (!config.discordEnabled) { + if (!config!!.discordEnabled) { return } if (ChatOG.essentials.getUser(event.player).isVanished) { diff --git a/src/main/kotlin/nl/skbotnl/chatog/LanguageDatabase.kt b/src/main/kotlin/nl/skbotnl/chatog/LanguageDatabase.kt index 6d3dafb..cc53fae 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/LanguageDatabase.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/LanguageDatabase.kt @@ -6,7 +6,7 @@ import java.util.* import nl.skbotnl.chatog.ChatOG.Companion.config internal class LanguageDatabase { - private val redisClient: RedisClient = RedisClient.create(config.redisUrl) + private val redisClient: RedisClient = RedisClient.create(config!!.redisUrl) /** @return True if failed */ fun testConnection(): Boolean { diff --git a/src/main/kotlin/nl/skbotnl/chatog/OpenAI.kt b/src/main/kotlin/nl/skbotnl/chatog/OpenAI.kt index 358b2a0..899240e 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/OpenAI.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/OpenAI.kt @@ -31,7 +31,7 @@ internal class OpenAI { fun translate(text: String, language: String): Translated { val openAICompletion = CompletionReq( - model = config.openAIModel ?: "", + model = config!!.openAIModel ?: "", messages = listOf( Message( @@ -44,8 +44,8 @@ internal class OpenAI { val request: Request = Request.Builder() - .url(config.openAIBaseUrl + "/v1/chat/completions") - .header("Authorization", "Bearer ${config.openAIApiKey}") + .url(config!!.openAIBaseUrl + "/v1/chat/completions") + .header("Authorization", "Bearer ${config!!.openAIApiKey}") .post(gson.toJson(openAICompletion).toRequestBody("application/json".toMediaType())) .build() @@ -61,7 +61,7 @@ internal class OpenAI { null, null, UtilitiesOG.trueogColorize( - "${config.prefix}: Something went wrong while translating that message." + "${config!!.prefix}: Something went wrong while translating that message." ), ) } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/ChatConfigReload.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/ChatConfigReload.kt index 766ebea..246713b 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/ChatConfigReload.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/ChatConfigReload.kt @@ -3,13 +3,17 @@ package nl.skbotnl.chatog.commands import kotlin.concurrent.write import kotlinx.coroutines.launch import net.trueog.utilitiesog.UtilitiesOG +import nl.skbotnl.chatog.BlocklistManager import nl.skbotnl.chatog.ChatOG +import nl.skbotnl.chatog.ChatOG.Companion.blocklistManager import nl.skbotnl.chatog.ChatOG.Companion.config import nl.skbotnl.chatog.ChatOG.Companion.discordBridgeLock import nl.skbotnl.chatog.ChatOG.Companion.scope +import nl.skbotnl.chatog.ChatOG.Companion.translator import nl.skbotnl.chatog.Config import nl.skbotnl.chatog.DiscordBridge import nl.skbotnl.chatog.LanguageDatabase +import nl.skbotnl.chatog.OpenAI import org.bukkit.Bukkit import org.bukkit.command.Command import org.bukkit.command.CommandExecutor @@ -29,6 +33,27 @@ internal class ChatConfigReload : CommandExecutor { return true } + if (config!!.blocklistEnabled) { + blocklistManager = BlocklistManager() + } + + translator = + if (config!!.openAIEnabled) { + if (config!!.openAIBaseUrl == null) { + ChatOG.plugin.logger.warning( + "You have enabled OpenAI translation but have not set up the base url, not enabling the translator" + ) + null + } else if (config!!.openAIApiKey == null) { + ChatOG.plugin.logger.warning( + "You have enabled OpenAI translation but have not set up the api key, not enabling the translator" + ) + null + } else { + OpenAI() + } + } else null + ChatOG.languageDatabase = LanguageDatabase() if (ChatOG.languageDatabase.testConnection()) { ChatOG.plugin.logger.severe("Could not connect to Redis") @@ -36,7 +61,7 @@ internal class ChatConfigReload : CommandExecutor { return true } - if (config.discordEnabled) { + if (config!!.discordEnabled) { scope.launch { discordBridgeLock.write { val discordBridge = ChatOG.discordBridge @@ -46,13 +71,15 @@ internal class ChatConfigReload : CommandExecutor { } ChatOG.discordBridge = DiscordBridge.create() sender.sendMessage( - UtilitiesOG.trueogColorize("${config.prefix}: Successfully reloaded the config.") + UtilitiesOG.trueogColorize( + "${config!!.prefix}: Successfully reloaded the config." + ) ) } } } else { sender.sendMessage( - UtilitiesOG.trueogColorize("${config.prefix}: Successfully reloaded the config.") + UtilitiesOG.trueogColorize("${config!!.prefix}: Successfully reloaded the config.") ) } return true diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/PremiumChat.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/PremiumChat.kt index d9dec83..722d75c 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/PremiumChat.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/PremiumChat.kt @@ -18,7 +18,7 @@ internal class PremiumChat : CommandExecutor { if (!sender.hasPermission("chat-og.premium")) { sender.sendMessage( UtilitiesOG.trueogColorize( - "${config.prefix}: You do not have permission to run this command." + "${config!!.prefix}: You do not have permission to run this command." ) ) return true @@ -28,13 +28,13 @@ internal class PremiumChat : CommandExecutor { ChatSystem.inChat[sender.uniqueId] = ChatType.GENERAL_CHAT sender.sendMessage( - UtilitiesOG.trueogColorize("${config.prefix}: You are now talking in normal chat.") + UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in normal chat.") ) return true } ChatSystem.inChat[sender.uniqueId] = ChatType.PREMIUM_CHAT sender.sendMessage( - UtilitiesOG.trueogColorize("${config.prefix}: You are now talking in premium chat.") + UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in premium chat.") ) return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/PrivateMessage.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/PrivateMessage.kt index 110e0ae..a7f7baf 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/PrivateMessage.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/PrivateMessage.kt @@ -26,7 +26,7 @@ internal class PrivateMessage : CommandExecutor { if (args == null || args.isEmpty()) { sender.sendMessage( UtilitiesOG.trueogColorize( - "${config.prefix}: You did not provide the player that you want to send a message to and your message." + "${config!!.prefix}: You did not provide the player that you want to send a message to and your message." ) ) return true @@ -34,7 +34,7 @@ internal class PrivateMessage : CommandExecutor { if (args.size < 2) { sender.sendMessage( UtilitiesOG.trueogColorize( - "${config.prefix}: Please provide the player that you want to send a message to and your message." + "${config!!.prefix}: Please provide the player that you want to send a message to and your message." ) ) return true @@ -45,7 +45,7 @@ internal class PrivateMessage : CommandExecutor { val toPlayer = Bukkit.getPlayer(playerName) if (toPlayer == null) { sender.sendMessage( - UtilitiesOG.trueogColorize("${config.prefix}: That player doesn't exist or isn't online.") + UtilitiesOG.trueogColorize("${config!!.prefix}: That player doesn't exist or isn't online.") ) return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/Reply.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/Reply.kt index 1a3e20a..9793a2a 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/Reply.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/Reply.kt @@ -25,7 +25,7 @@ internal class Reply : CommandExecutor { if (args == null || args.isEmpty()) { sender.sendMessage( - UtilitiesOG.trueogColorize("${config.prefix}: You did not provide your message.") + UtilitiesOG.trueogColorize("${config!!.prefix}: You did not provide your message.") ) return true } @@ -33,7 +33,7 @@ internal class Reply : CommandExecutor { val lastMessaged = lastMessagedMap[sender.uniqueId] if (lastMessaged == null) { sender.sendMessage( - UtilitiesOG.trueogColorize("${config.prefix}: You haven't messaged anyone yet.") + UtilitiesOG.trueogColorize("${config!!.prefix}: You haven't messaged anyone yet.") ) return true } @@ -41,7 +41,7 @@ internal class Reply : CommandExecutor { val toPlayer = Bukkit.getPlayer(lastMessaged) if (toPlayer == null) { sender.sendMessage( - UtilitiesOG.trueogColorize("${config.prefix}: That player doesn't exist or isn't online.") + UtilitiesOG.trueogColorize("${config!!.prefix}: That player doesn't exist or isn't online.") ) return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/StaffChat.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/StaffChat.kt index 54843d4..e8a989c 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/StaffChat.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/StaffChat.kt @@ -18,7 +18,7 @@ internal class StaffChat : CommandExecutor { if (!sender.hasPermission("chat-og.staff")) { sender.sendMessage( UtilitiesOG.trueogColorize( - "${config.prefix}: You do not have permission to run this command." + "${config!!.prefix}: You do not have permission to run this command." ) ) return true @@ -28,13 +28,13 @@ internal class StaffChat : CommandExecutor { ChatSystem.inChat[sender.uniqueId] = ChatType.GENERAL_CHAT sender.sendMessage( - UtilitiesOG.trueogColorize("${config.prefix}: You are now talking in normal chat.") + UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in normal chat.") ) return true } ChatSystem.inChat[sender.uniqueId] = ChatType.STAFF_CHAT sender.sendMessage( - UtilitiesOG.trueogColorize("${config.prefix}: You are now talking in staff chat.") + UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in staff chat.") ) return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateMessage.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateMessage.kt index 2825fbf..a384498 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateMessage.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateMessage.kt @@ -57,7 +57,9 @@ internal class TranslateMessage : CommandExecutor { val player: Player = sender if (ChatUtil.getTranslateTimeout(player.uniqueId) != 0L) { - player.sendMessage(UtilitiesOG.trueogColorize("${config.prefix}: You're doing that too fast.")) + player.sendMessage( + UtilitiesOG.trueogColorize("${config!!.prefix}: You're doing that too fast.") + ) return true } @@ -66,7 +68,7 @@ internal class TranslateMessage : CommandExecutor { try { uuid = UUID.fromString(args[0]) } catch (_: IllegalArgumentException) { - player.sendMessage(UtilitiesOG.trueogColorize("${config.prefix}: That is not a valid UUID.")) + player.sendMessage(UtilitiesOG.trueogColorize("${config!!.prefix}: That is not a valid UUID.")) return true } @@ -74,7 +76,7 @@ internal class TranslateMessage : CommandExecutor { try { messageType = args[1].toInt() } catch (_: NumberFormatException) { - player.sendMessage(UtilitiesOG.trueogColorize("${config.prefix}: Invalid message type.")) + player.sendMessage(UtilitiesOG.trueogColorize("${config!!.prefix}: Invalid message type.")) return true } @@ -89,12 +91,16 @@ internal class TranslateMessage : CommandExecutor { } if (sentMessage == null) { - player.sendMessage(UtilitiesOG.trueogColorize("${config.prefix}: Could not find that message.")) + player.sendMessage( + UtilitiesOG.trueogColorize("${config!!.prefix}: Could not find that message.") + ) return true } if (ChatOG.translator == null) { - player.sendMessage(UtilitiesOG.trueogColorize("${config.prefix}: The translator is disabled.")) + player.sendMessage( + UtilitiesOG.trueogColorize("${config!!.prefix}: The translator is disabled.") + ) return true } @@ -103,14 +109,14 @@ internal class TranslateMessage : CommandExecutor { if (language == null) { player.sendMessage( UtilitiesOG.trueogColorize( - "${config.prefix}: Something went wrong while trying to get your preferred language." + "${config!!.prefix}: Something went wrong while trying to get your preferred language." ) ) return true } player.sendMessage( - UtilitiesOG.trueogColorize("${config.prefix}: Translating message (this can take some time)...") + UtilitiesOG.trueogColorize("${config!!.prefix}: Translating message (this can take some time)...") ) val translated = ChatOG.translator!!.translate(sentMessage.message, language) @@ -122,7 +128,7 @@ internal class TranslateMessage : CommandExecutor { if (translated.translatedText == null) { player.sendMessage( - UtilitiesOG.trueogColorize("${config.prefix}: Could not translate that message.") + UtilitiesOG.trueogColorize("${config!!.prefix}: Could not translate that message.") ) return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateSettings.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateSettings.kt index b327b46..e9fed20 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateSettings.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateSettings.kt @@ -74,13 +74,13 @@ internal class TranslateSettings : CommandExecutor { val language = args[0] if (languagesList.indexOf(language) == -1) { - sender.sendMessage(UtilitiesOG.trueogColorize("${config.prefix}: Invalid language.")) + sender.sendMessage(UtilitiesOG.trueogColorize("${config!!.prefix}: Invalid language.")) return true } ChatOG.languageDatabase.setPlayerLanguage(sender.uniqueId, language) sender.sendMessage( - UtilitiesOG.trueogColorize("${config.prefix}: Set language to: $language.") + UtilitiesOG.trueogColorize("${config!!.prefix}: Set language to: $language.") ) return true diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0cf900d..249c297 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,6 +1,11 @@ # ---General--- # MiniMessage-formatted prefix (https://docs.advntr.dev/minimessage/format.html) prefix: [Chat-OG] +blocklistEnabled: true +# Only blocklists with just a list of domains +blocklists: + - https://raw.githubusercontent.com/hagezi/dns-blocklists/main/domains/multi.txt + - https://raw.githubusercontent.com/hagezi/dns-blocklists/main/wildcard/nsfw-onlydomains.txt # ---Redis--- # Redis URL according to https://redis.github.io/lettuce/user-guide/connecting-redis/#uri-syntax -- 2.47.3 From 54f0dd4be98de0a0fc508cb151b1db6bd960fbec Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 22 Jul 2025 23:23:33 +0200 Subject: [PATCH 05/11] Add developer chat and general chat commands --- src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt | 4 ++ .../kotlin/nl/skbotnl/chatog/ChatSystem.kt | 47 ++++++++++++++++++ src/main/kotlin/nl/skbotnl/chatog/Config.kt | 26 ++++++++++ .../kotlin/nl/skbotnl/chatog/DiscordBridge.kt | 45 ++++++++++++++++- src/main/kotlin/nl/skbotnl/chatog/Events.kt | 21 +++++--- .../skbotnl/chatog/commands/DeveloperChat.kt | 49 +++++++++++++++++++ .../nl/skbotnl/chatog/commands/GeneralChat.kt | 41 ++++++++++++++++ .../nl/skbotnl/chatog/commands/PremiumChat.kt | 4 +- .../nl/skbotnl/chatog/commands/StaffChat.kt | 4 +- src/main/resources/config.yml | 7 ++- src/main/resources/plugin.yml | 14 +++++- 11 files changed, 248 insertions(+), 14 deletions(-) create mode 100644 src/main/kotlin/nl/skbotnl/chatog/commands/DeveloperChat.kt create mode 100644 src/main/kotlin/nl/skbotnl/chatog/commands/GeneralChat.kt diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt index 0c4f4ce..2f3f01e 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt @@ -83,10 +83,14 @@ internal class ChatOG : JavaPlugin() { this.getCommand("translatesettings")?.setExecutor(TranslateSettings()) this.getCommand("translatesettings")?.tabCompleter = TranslateSettingsTabCompleter() this.getCommand("chatconfigreload")?.setExecutor(ChatConfigReload()) + this.getCommand("gc")?.setExecutor(GeneralChat()) + this.getCommand("g")?.setExecutor(GeneralChat()) this.getCommand("sc")?.setExecutor(StaffChat()) this.getCommand("s")?.setExecutor(StaffChat()) this.getCommand("pc")?.setExecutor(PremiumChat()) this.getCommand("p")?.setExecutor(PremiumChat()) + this.getCommand("dc")?.setExecutor(DeveloperChat()) + this.getCommand("d")?.setExecutor(DeveloperChat()) this.getCommand("msg")?.setExecutor(PrivateMessage()) this.getCommand("whisper")?.setExecutor(PrivateMessage()) this.getCommand("pm")?.setExecutor(PrivateMessage()) diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt index 82536c0..dcd7fff 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt @@ -22,6 +22,7 @@ internal object ChatSystem { GENERAL_CHAT, STAFF_CHAT, PREMIUM_CHAT, + DEVELOPER_CHAT, } var inChat: MutableMap = HashMap() @@ -117,4 +118,50 @@ internal object ChatSystem { } } } + + fun sendMessageInDeveloperChat(player: Player, text: String) { + var playerPartString = ChatUtil.getPlayerPartString(player) + playerPartString = "DEVELOPER | $playerPartString" + + if (config!!.premiumDiscordEnabled) { + val discordMessageString = ChatUtil.convertEmojis(text) + + ChatOG.scope.launch { + discordBridgeLock.read { + ChatOG.discordBridge?.sendDeveloperMessage(discordMessageString, playerPartString, player.uniqueId) + } + } + } + + val messageComponent = ChatUtil.processText(text, player) + if (messageComponent == null) { + return + } + + val chatComponent = + UtilitiesOG.trueogColorize(legacyToMm("$playerPartString${PlayerAffix.getSuffix(player.uniqueId)}")) + + var textComponent = Component.join(JoinConfiguration.noSeparators(), chatComponent, messageComponent) + textComponent = + textComponent.hoverEvent( + HoverEvent.hoverEvent( + HoverEvent.Action.SHOW_TEXT, + UtilitiesOG.trueogColorize("Click to translate this message"), + ) + ) + + val randomUUID = UUID.randomUUID() + textComponent = + textComponent.clickEvent( + ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, "/translatemessage $randomUUID 1") + ) + + TranslateMessage.chatMessages[randomUUID] = TranslateMessage.SentChatMessage(text, player) + + for (p in Bukkit.getOnlinePlayers()) { + if (p.hasPermission("chat-og.developer")) { + p.sendMessage(textComponent) + } + } + } } diff --git a/src/main/kotlin/nl/skbotnl/chatog/Config.kt b/src/main/kotlin/nl/skbotnl/chatog/Config.kt index fe3f165..8858725 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/Config.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/Config.kt @@ -16,6 +16,7 @@ internal class Config private constructor() { var discordEnabled = false var staffDiscordEnabled = false var premiumDiscordEnabled = false + var developerDiscordEnabled = false var status: String? = null var serverHasStartedMessage: String? = null var serverHasStoppedMessage: String? = null @@ -23,10 +24,12 @@ internal class Config private constructor() { var channelId: String? = null var staffChannelId: String? = null var premiumChannelId: String? = null + var developerChannelId: String? = null var guildId: String? = null var webhook: String? = null var staffWebhook: String? = null var premiumWebhook: String? = null + var developerWebhook: String? = null var listCommandName: String? = null var listCommandText: String? = null var colorCodeRoles = listOf() @@ -121,6 +124,13 @@ internal class Config private constructor() { return null } + try { + config.developerDiscordEnabled = yamlConfig.get("developerDiscordEnabled") as Boolean + } catch (_: Exception) { + ChatOG.plugin.logger.severe("Failed to parse config option \"developerDiscordEnabled\" as a boolean") + return null + } + if (config.discordEnabled) { try { config.status = yamlConfig.get("status") as String @@ -196,6 +206,22 @@ internal class Config private constructor() { } } + if (config.developerDiscordEnabled) { + try { + config.developerChannelId = (yamlConfig.get("developerChannelId") as Long).toString() + } catch (_: Exception) { + ChatOG.plugin.logger.severe("Failed to parse config option \"developerChannelId\" as a long") + return null + } + + try { + config.developerWebhook = yamlConfig.get("developerWebhook") as String + } catch (_: Exception) { + ChatOG.plugin.logger.severe("Failed to parse config option \"developerWebhook\" as a string") + return null + } + } + try { config.webhook = yamlConfig.get("webhook") as String } catch (_: Exception) { diff --git a/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt b/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt index 41aedab..c8828a1 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt @@ -40,6 +40,7 @@ internal class DiscordBridge private constructor() { private lateinit var webhook: WebhookClient private var staffWebhook: WebhookClient? = null private var premiumWebhook: WebhookClient? = null + private var developerWebhook: WebhookClient? = null companion object { fun create(): DiscordBridge? { @@ -72,6 +73,17 @@ internal class DiscordBridge private constructor() { } else if (config!!.premiumDiscordEnabled) { ChatOG.plugin.logger.warning("You have enabled premium Discord but have not set up the premium webhook") } + if (config!!.developerWebhook != null) { + try { + discordBridge.developerWebhook = WebhookClient.withUrl(config!!.developerWebhook!!) + } catch (_: IllegalArgumentException) { + ChatOG.plugin.logger.warning("Config option \"developer\" is invalid") + } + } else if (config!!.premiumDiscordEnabled) { + ChatOG.plugin.logger.warning( + "You have enabled developer Discord but have not set up the developer webhook" + ) + } if (config!!.botToken == null) { ChatOG.plugin.logger.severe("You have enabled Discord but have not set up the bot token") @@ -162,7 +174,8 @@ internal class DiscordBridge private constructor() { if ( it.channel.id != config!!.channelId && (if (config!!.staffDiscordEnabled) it.channel.id != config!!.staffChannelId else true) && - (if (config!!.premiumDiscordEnabled) it.channel.id != config!!.premiumChannelId else true) + (if (config!!.premiumDiscordEnabled) it.channel.id != config!!.premiumChannelId else true) && + (if (config!!.developerDiscordEnabled) it.channel.id != config!!.developerChannelId else true) ) { return@listener } @@ -298,6 +311,18 @@ internal class DiscordBridge private constructor() { ) } + config!!.developerChannelId -> { + val developerComponent = Component.text("DEVELOPER | ").color(NamedTextColor.AQUA) + Component.join( + JoinConfiguration.noSeparators(), + discordComponent, + developerComponent, + replyComponent, + userComponent, + contentComponent, + ) + } + else -> { Component.join( JoinConfiguration.noSeparators(), @@ -436,6 +461,24 @@ internal class DiscordBridge private constructor() { premiumWebhook!!.send(webhookMessage.build()) } + suspend fun sendDeveloperMessage(message: String, name: String, uuid: UUID?) { + if (!config!!.developerDiscordEnabled) return + + if (developerWebhook == null) { + ChatOG.plugin.logger.warning("developerWebhook has not been set or is invalid") + return + } + + val webhookMessage = + WebhookMessageBuilder().apply { + setUsername(UtilitiesOG.stripFormatting(name)) + setContent(UtilitiesOG.stripFormatting(stripGroupMentions((convertMentions(message))))) + if (uuid != null) setAvatarUrl("https://minotar.net/helm/$uuid.png") + } + + developerWebhook!!.send(webhookMessage.build()) + } + fun sendEmbed(message: String, uuid: UUID?, color: Int?) { var iconUrl: String? = null if (uuid != null) { diff --git a/src/main/kotlin/nl/skbotnl/chatog/Events.kt b/src/main/kotlin/nl/skbotnl/chatog/Events.kt index 3087452..6319351 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/Events.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/Events.kt @@ -168,13 +168,20 @@ internal class Events : Listener { val eventMessage = event.message() as TextComponent - if (ChatSystem.inChat[event.player.uniqueId] == ChatType.STAFF_CHAT) { - ChatSystem.sendMessageInStaffChat(event.player, eventMessage.content()) - return - } - if (ChatSystem.inChat[event.player.uniqueId] == ChatType.PREMIUM_CHAT) { - ChatSystem.sendMessageInPremiumChat(event.player, eventMessage.content()) - return + when (ChatSystem.inChat[event.player.uniqueId]) { + ChatType.STAFF_CHAT -> { + ChatSystem.sendMessageInStaffChat(event.player, eventMessage.content()) + return + } + ChatType.PREMIUM_CHAT -> { + ChatSystem.sendMessageInPremiumChat(event.player, eventMessage.content()) + return + } + ChatType.DEVELOPER_CHAT -> { + ChatSystem.sendMessageInDeveloperChat(event.player, eventMessage.content()) + return + } + else -> {} } val discordMessageString = ChatUtil.convertEmojis(eventMessage.content()) diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/DeveloperChat.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/DeveloperChat.kt new file mode 100644 index 0000000..f71756a --- /dev/null +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/DeveloperChat.kt @@ -0,0 +1,49 @@ +package nl.skbotnl.chatog.commands + +import kotlin.collections.set +import net.trueog.utilitiesog.UtilitiesOG +import nl.skbotnl.chatog.ChatOG.Companion.config +import nl.skbotnl.chatog.ChatSystem +import nl.skbotnl.chatog.ChatSystem.ChatType +import org.bukkit.command.Command +import org.bukkit.command.CommandExecutor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +class DeveloperChat : CommandExecutor { + override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array?): Boolean { + if (sender !is Player) { + sender.sendMessage("You can only execute this command as a player.") + return true + } + + if (!sender.hasPermission("chat-og.developer")) { + sender.sendMessage( + UtilitiesOG.trueogColorize( + "${config!!.prefix}: You do not have permission to run this command." + ) + ) + return true + } + + if (args == null || args.isEmpty()) { + if (ChatSystem.inChat[sender.uniqueId] == ChatType.DEVELOPER_CHAT) { + ChatSystem.inChat[sender.uniqueId] = ChatType.GENERAL_CHAT + + sender.sendMessage( + UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in the general chat.") + ) + return true + } + ChatSystem.inChat[sender.uniqueId] = ChatType.DEVELOPER_CHAT + sender.sendMessage( + UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in the developer chat.") + ) + return true + } + + ChatSystem.sendMessageInDeveloperChat(sender, args.joinToString(separator = " ")) + + return true + } +} diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/GeneralChat.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/GeneralChat.kt new file mode 100644 index 0000000..6516af3 --- /dev/null +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/GeneralChat.kt @@ -0,0 +1,41 @@ +package nl.skbotnl.chatog.commands + +import kotlin.collections.set +import net.trueog.utilitiesog.UtilitiesOG +import nl.skbotnl.chatog.ChatOG.Companion.config +import nl.skbotnl.chatog.ChatSystem +import nl.skbotnl.chatog.ChatSystem.ChatType +import org.bukkit.command.Command +import org.bukkit.command.CommandExecutor +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +class GeneralChat : CommandExecutor { + override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array?): Boolean { + if (sender !is Player) { + sender.sendMessage("You can only execute this command as a player.") + return true + } + + if (args == null || args.isEmpty()) { + if (ChatSystem.inChat[sender.uniqueId] != ChatType.GENERAL_CHAT) { + ChatSystem.inChat[sender.uniqueId] = ChatType.GENERAL_CHAT + + sender.sendMessage( + UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in the general chat.") + ) + return true + } + sender.sendMessage( + UtilitiesOG.trueogColorize("${config!!.prefix}: You are already talking in the general chat.") + ) + return true + } + + val originalChat = ChatSystem.inChat[sender.uniqueId] + ChatSystem.inChat[sender.uniqueId] = ChatType.GENERAL_CHAT + sender.chat(args.joinToString(separator = " ")) + if (originalChat != null) ChatSystem.inChat[sender.uniqueId] = originalChat + return true + } +} diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/PremiumChat.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/PremiumChat.kt index 722d75c..3224f40 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/PremiumChat.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/PremiumChat.kt @@ -28,13 +28,13 @@ internal class PremiumChat : CommandExecutor { ChatSystem.inChat[sender.uniqueId] = ChatType.GENERAL_CHAT sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in normal chat.") + UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in the general chat.") ) return true } ChatSystem.inChat[sender.uniqueId] = ChatType.PREMIUM_CHAT sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in premium chat.") + UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in the premium chat.") ) return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/StaffChat.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/StaffChat.kt index e8a989c..632d80c 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/StaffChat.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/StaffChat.kt @@ -15,6 +15,7 @@ internal class StaffChat : CommandExecutor { sender.sendMessage("You can only execute this command as a player.") return true } + if (!sender.hasPermission("chat-og.staff")) { sender.sendMessage( UtilitiesOG.trueogColorize( @@ -23,12 +24,13 @@ internal class StaffChat : CommandExecutor { ) return true } + if (args == null || args.isEmpty()) { if (ChatSystem.inChat[sender.uniqueId] == ChatType.STAFF_CHAT) { ChatSystem.inChat[sender.uniqueId] = ChatType.GENERAL_CHAT sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in normal chat.") + UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in general chat.") ) return true } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 249c297..3efdcdb 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -25,6 +25,7 @@ model: "" discordEnabled: false staffDiscordEnabled: false premiumDiscordEnabled: false +developerDiscordEnabled: false status: Minecraft serverHasStartedMessage: The server has started serverHasStoppedMessage: The server has stopped @@ -33,9 +34,11 @@ guildId: channelId: staffChannelId: premiumChannelId: +developerChannelId: webhook: -staffWebhook: -premiumWebhook: +staffWebhook: +premiumWebhook: +developerWebhook: listCommandName: list # Available placeholders: %onlineplayers%, %maxplayers% listCommandText: "%onlineplayers% player(s) online:" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 75dcbd0..1fbb15b 100755 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -20,6 +20,12 @@ commands: chatconfigreload: description: Reload Chat-OG's config usage: /chatconfigreload + gc: + description: Toggle or talk in general chat + usage: /gc OR /gc + g: + description: Toggle or talk in general chat + usage: /g OR /g sc: description: Toggle or talk in staff chat usage: /sc OR /sc @@ -28,10 +34,16 @@ commands: usage: /s OR /s pc: description: Toggle or talk in premium chat - usage: /p OR /p + usage: /pc OR /pc p: description: Toggle or talk in premium chat usage: /p OR /p + dc: + description: Toggle or talk in developer chat + usage: /dc OR /dc + d: + description: Toggle or talk in developer chat + usage: /d OR /d msg: description: Send a private message to a player usage: /msg -- 2.47.3 From 5a930f876ea8f3b8bbf73c0a7fdc33f4df0f6b5a Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 22 Jul 2025 23:58:59 +0200 Subject: [PATCH 06/11] Implement color code roles --- src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt | 32 ++++++++++++++++--- src/main/kotlin/nl/skbotnl/chatog/Config.kt | 10 +++++- .../kotlin/nl/skbotnl/chatog/DiscordBridge.kt | 17 ++++++++-- src/main/resources/config.yml | 1 + 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt index 1b7a581..d031fe0 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt @@ -139,7 +139,11 @@ internal object ChatUtil { private val urlRegex = Regex("(.*?)((?:https?://)?[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}(?:/?[a-zA-Z]*)+)(.*)") - val noColorMm = MiniMessage.builder().editTags { b -> b.tag("a", ChatUtil::createA) }.build() + val noColorMm = + MiniMessage.builder() + .tags(TagResolver.builder().build()) + .editTags { b -> b.tag("a", ChatUtil::createA) } + .build() val colorMm = MiniMessage.builder() @@ -172,11 +176,11 @@ internal object ChatUtil { ) } - fun processText(text: String, player: Player) = processText(text, player, null) + fun processText(text: String, player: Player) = processText(text, player, null, false) - fun processText(text: String, username: String) = processText(text, null, username) + fun processText(text: String, username: String, color: Boolean) = processText(text, null, username, color) - private fun processText(text: String, player: Player?, username: String?): Component? { + private fun processText(text: String, player: Player?, username: String?, color: Boolean): Component? { val words: MutableList = mutableListOf() legacyToMm(text).split(" ").forEach { word -> @@ -215,9 +219,16 @@ internal object ChatUtil { } return if (player?.hasPermission("chat-og.color") == true) { + println("A") colorMm.deserialize(words.joinToString(" ")) } else { - noColorMm.deserialize(words.joinToString(" ")) + if (color) { + println("B") + colorMm.deserialize(words.joinToString(" ")) + } else { + println("C") + noColorMm.deserialize(words.joinToString(" ")) + } } } @@ -258,4 +269,15 @@ internal object ChatUtil { return tempText } + + fun recolorComponent(component: Component, color: TextColor): Component { + var newComponent = component + if (component.color() == null) { + newComponent = component.color(color) + } + + val children = newComponent.children().map { recolorComponent(it, color) } + newComponent.children(children) + return newComponent + } } diff --git a/src/main/kotlin/nl/skbotnl/chatog/Config.kt b/src/main/kotlin/nl/skbotnl/chatog/Config.kt index 8858725..2a11f1e 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/Config.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/Config.kt @@ -32,6 +32,7 @@ internal class Config private constructor() { var developerWebhook: String? = null var listCommandName: String? = null var listCommandText: String? = null + var useColorCodeRoles = false var colorCodeRoles = listOf() var roles = setOf() var roleMessageColor: MutableMap = mutableMapOf() @@ -58,7 +59,7 @@ internal class Config private constructor() { try { config.blocklistEnabled = yamlConfig.get("blocklistEnabled") as Boolean } catch (_: Exception) { - ChatOG.plugin.logger.severe("Failed to parse config option \"blocklistEnabled\" as a string") + ChatOG.plugin.logger.severe("Failed to parse config option \"blocklistEnabled\" as a boolean") return null } @@ -243,6 +244,13 @@ internal class Config private constructor() { return null } + try { + config.useColorCodeRoles = yamlConfig.get("useColorCodeRoles") as Boolean + } catch (_: Exception) { + ChatOG.plugin.logger.severe("Failed to parse config option \"useColorCodeRoles\" as a boolean") + return null + } + config.colorCodeRoles = yamlConfig.getStringList("colorCodeRoles") config.roles = yamlConfig.getConfigurationSection("roles")?.getKeys(false) ?: setOf() diff --git a/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt b/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt index c8828a1..609f57b 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt @@ -30,6 +30,7 @@ import net.kyori.adventure.text.format.TextColor import net.trueog.utilitiesog.UtilitiesOG import nl.skbotnl.chatog.ChatOG.Companion.config import nl.skbotnl.chatog.ChatUtil.convertMentions +import nl.skbotnl.chatog.ChatUtil.recolorComponent import nl.skbotnl.chatog.ChatUtil.stripGroupMentions import nl.skbotnl.chatog.commands.TranslateMessage import org.bukkit.Bukkit @@ -257,13 +258,23 @@ internal class DiscordBridge private constructor() { } } + val useColor = + if (config!!.useColorCodeRoles) { + roles.any { role -> role.id in config!!.colorCodeRoles } + } else { + true + } + if (message.contentDisplay != "") { messageComponents += - ChatUtil.processText( + recolorComponent( + ChatUtil.processText( EmojiConverter.replaceEmojisWithNames(message.contentDisplay), "@${user.name}", - ) - ?.color(messageColor) ?: return@listener + useColor, + ) ?: return@listener, + messageColor, + ) } val contentComponent = diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3efdcdb..6e0cfcb 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -43,6 +43,7 @@ listCommandName: list # Available placeholders: %onlineplayers%, %maxplayers% listCommandText: "%onlineplayers% player(s) online:" +useColorCodeRoles: false # Configure which roles can use color codes with Discord -> Minecraft # For example: # -- 2.47.3 From 55cff521e80c7ff932da0f94150387304ed2faf2 Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 23 Jul 2025 21:22:33 +0200 Subject: [PATCH 07/11] Improve config --- .../nl/skbotnl/chatog/BlocklistManager.kt | 2 +- src/main/kotlin/nl/skbotnl/chatog/ChatAPI.kt | 18 ++-- src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt | 44 +++++----- .../kotlin/nl/skbotnl/chatog/ChatSystem.kt | 6 +- src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt | 8 +- .../kotlin/nl/skbotnl/chatog/DiscordBridge.kt | 87 +++++++++---------- src/main/kotlin/nl/skbotnl/chatog/Events.kt | 12 +-- .../nl/skbotnl/chatog/LanguageDatabase.kt | 2 +- src/main/kotlin/nl/skbotnl/chatog/OpenAI.kt | 8 +- .../chatog/commands/ChatConfigReload.kt | 16 ++-- .../skbotnl/chatog/commands/DeveloperChat.kt | 6 +- .../nl/skbotnl/chatog/commands/GeneralChat.kt | 4 +- .../nl/skbotnl/chatog/commands/PremiumChat.kt | 6 +- .../skbotnl/chatog/commands/PrivateMessage.kt | 6 +- .../nl/skbotnl/chatog/commands/Reply.kt | 6 +- .../nl/skbotnl/chatog/commands/StaffChat.kt | 6 +- .../chatog/commands/TranslateMessage.kt | 22 ++--- .../chatog/commands/TranslateSettings.kt | 4 +- 18 files changed, 129 insertions(+), 134 deletions(-) diff --git a/src/main/kotlin/nl/skbotnl/chatog/BlocklistManager.kt b/src/main/kotlin/nl/skbotnl/chatog/BlocklistManager.kt index cf49909..ba9aa75 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/BlocklistManager.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/BlocklistManager.kt @@ -24,7 +24,7 @@ class BlocklistManager { private fun refresh() { blockList.clear() - ChatOG.config!!.blocklists.forEach { blocklist -> + ChatOG.config.blocklists.forEach { blocklist -> URI(blocklist).toURL().openStream().use { input -> input.bufferedReader().use { bufferedReader -> synchronized(lock) { bufferedReader.lines().forEach { if (!it.startsWith("#")) blockList.add(it) } } diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatAPI.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatAPI.kt index 06c9014..f9fb2c5 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatAPI.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatAPI.kt @@ -10,22 +10,22 @@ import org.bukkit.entity.Player class ChatAPI { @Suppress("unused") fun isDiscordEnabled(): Boolean { - return ChatOG.config!!.discordEnabled + return ChatOG.config.discordEnabled } @Suppress("unused") fun isStaffDiscordEnabled(): Boolean { - return ChatOG.config!!.staffDiscordEnabled + return ChatOG.config.staffDiscordEnabled } @Suppress("unused") fun isPremiumDiscordEnabled(): Boolean { - return ChatOG.config!!.premiumDiscordEnabled + return ChatOG.config.premiumDiscordEnabled } @Suppress("unused") fun sendMessageWithBot(message: String) { - if (!ChatOG.config!!.discordEnabled) return + if (!ChatOG.config.discordEnabled) return scope.launch { discordBridgeLock.read { val discordBridge = ChatOG.discordBridge @@ -37,7 +37,7 @@ class ChatAPI { @Suppress("unused") fun sendMessage(message: String, player: Player) { - if (!ChatOG.config!!.discordEnabled) return + if (!ChatOG.config.discordEnabled) return discordBridgeLock.read { val discordBridge = ChatOG.discordBridge scope.launch { discordBridge!!.sendMessage(message, player) } @@ -47,7 +47,7 @@ class ChatAPI { @Suppress("unused") fun sendMessage(message: String, name: String, uuid: UUID?) { - if (!ChatOG.config!!.discordEnabled) return + if (!ChatOG.config.discordEnabled) return discordBridgeLock.read { val discordBridge = ChatOG.discordBridge scope.launch { discordBridge!!.sendMessage(message, name, uuid) } @@ -57,7 +57,7 @@ class ChatAPI { @Suppress("unused") fun sendStaffMessage(message: String, name: String, uuid: UUID?) { - if (!ChatOG.config!!.discordEnabled) return + if (!ChatOG.config.discordEnabled) return discordBridgeLock.read { val discordBridge = ChatOG.discordBridge scope.launch { discordBridge!!.sendStaffMessage(message, name, uuid) } @@ -67,7 +67,7 @@ class ChatAPI { @Suppress("unused") fun sendPremiumMessage(message: String, name: String, uuid: UUID?) { - if (!ChatOG.config!!.discordEnabled) return + if (!ChatOG.config.discordEnabled) return discordBridgeLock.read { val discordBridge = ChatOG.discordBridge scope.launch { discordBridge!!.sendPremiumMessage(message, name, uuid) } @@ -77,7 +77,7 @@ class ChatAPI { @Suppress("unused") fun sendEmbed(message: String, uuid: UUID?, color: Int?) { - if (!ChatOG.config!!.discordEnabled) return + if (!ChatOG.config.discordEnabled) return discordBridgeLock.read { val discordBridge = ChatOG.discordBridge scope.launch { discordBridge!!.sendEmbed(message, uuid, color) } diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt index 2f3f01e..d32b980 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt @@ -18,7 +18,7 @@ internal class ChatOG : JavaPlugin() { val scope = CoroutineScope(Dispatchers.Default + SupervisorJob()) lateinit var plugin: JavaPlugin - var config: Config? = null + lateinit var config: Config var blocklistManager: BlocklistManager? = null lateinit var luckPerms: LuckPerms lateinit var languageDatabase: LanguageDatabase @@ -27,6 +27,8 @@ internal class ChatOG : JavaPlugin() { val discordBridgeLock = ReentrantReadWriteLock() var essentials = Bukkit.getServer().pluginManager.getPlugin("Essentials") as Essentials var lastMessagedMap: MutableMap = HashMap() + + fun isConfigInitialized() = ::config.isInitialized } @OptIn(DelicateCoroutinesApi::class) @@ -40,18 +42,18 @@ internal class ChatOG : JavaPlugin() { return } - if (Companion.config!!.blocklistEnabled) { + if (Companion.config.blocklistEnabled) { blocklistManager = BlocklistManager() } translator = - if (Companion.config!!.openAIEnabled) { - if (Companion.config!!.openAIBaseUrl == null) { + if (Companion.config.openAIEnabled) { + if (Companion.config.openAIBaseUrl == null) { this.logger.warning( "You have enabled OpenAI translation but have not set up the base url, not enabling the translator" ) null - } else if (Companion.config!!.openAIApiKey == null) { + } else if (Companion.config.openAIApiKey == null) { this.logger.warning( "You have enabled OpenAI translation but have not set up the api key, not enabling the translator" ) @@ -97,7 +99,7 @@ internal class ChatOG : JavaPlugin() { this.getCommand("reply")?.setExecutor(Reply()) this.getCommand("r")?.setExecutor(Reply()) - if (Companion.config!!.discordEnabled) { + if (Companion.config.discordEnabled) { scope.launch { discordBridgeLock.write { discordBridge = DiscordBridge.create() } } } @@ -106,20 +108,22 @@ internal class ChatOG : JavaPlugin() { } override fun onDisable() { - if (Companion.config?.discordEnabled == true) { - discordBridgeLock.read { - val discordBridge = discordBridge - val serverHasStoppedMessage = - if (Companion.config!!.serverHasStoppedMessage == null) { - this.logger.warning( - "You have enabled Discord but have not set up the server has stopped message, using the default one instead" - ) - "The server has stopped" - } else { - Companion.config!!.serverHasStoppedMessage!! - } - discordBridge!!.sendMessageWithBot(serverHasStoppedMessage) - discordBridge.shutdownNow() + if (isConfigInitialized()) { + if (Companion.config.discordEnabled) { + discordBridgeLock.read { + val discordBridge = discordBridge + val serverHasStoppedMessage = + if (Companion.config.serverHasStoppedMessage == null) { + this.logger.warning( + "You have enabled Discord but have not set up the server has stopped message, using the default one instead" + ) + "The server has stopped" + } else { + Companion.config.serverHasStoppedMessage!! + } + discordBridge!!.sendMessageWithBot(serverHasStoppedMessage) + discordBridge.shutdownNow() + } } } diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt index dcd7fff..9ad9b3e 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatSystem.kt @@ -31,7 +31,7 @@ internal object ChatSystem { var playerPartString = ChatUtil.getPlayerPartString(player) playerPartString = "&cSTAFF | $playerPartString" - if (config!!.staffDiscordEnabled) { + if (config.staffDiscordEnabled) { val discordMessageString = ChatUtil.convertEmojis(text) ChatOG.scope.launch { @@ -77,7 +77,7 @@ internal object ChatSystem { var playerPartString = ChatUtil.getPlayerPartString(player) playerPartString = "&aPREMIUM | $playerPartString" - if (config!!.premiumDiscordEnabled) { + if (config.premiumDiscordEnabled) { val discordMessageString = ChatUtil.convertEmojis(text) ChatOG.scope.launch { @@ -123,7 +123,7 @@ internal object ChatSystem { var playerPartString = ChatUtil.getPlayerPartString(player) playerPartString = "DEVELOPER | $playerPartString" - if (config!!.premiumDiscordEnabled) { + if (config.premiumDiscordEnabled) { val discordMessageString = ChatUtil.convertEmojis(text) ChatOG.scope.launch { diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt index d031fe0..0f5a122 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt @@ -117,7 +117,7 @@ internal object ChatUtil { private val getHandle = Regex("@([a-z0-9_.]{2,32})") suspend fun convertMentions(text: String): String { - val guild = discordBridgeLock.read { ChatOG.discordBridge?.getGuildById(config!!.guildId!!) } + val guild = discordBridgeLock.read { ChatOG.discordBridge?.getGuildById(config.guildId!!) } if (guild == null) { ChatOG.plugin.logger.warning("Guild was null") return text @@ -191,14 +191,14 @@ internal object ChatUtil { if (blocklistManager?.checkUrl(link) == true) { player?.sendMessage( UtilitiesOG.trueogColorize( - "${config!!.prefix}: WARNING: You are not allowed to post links like that here." + "${config.prefix}: WARNING: You are not allowed to post links like that here." ) ) for (onlinePlayer in Bukkit.getOnlinePlayers()) { if (onlinePlayer.hasPermission("group.moderator")) { onlinePlayer.sendMessage( UtilitiesOG.trueogColorize( - "${config!!.prefix}: ${player?.name ?: username} has posted a disallowed link: ${ + "${config.prefix}: ${player?.name ?: username} has posted a disallowed link: ${ word.replace( ".", "[dot]", @@ -237,7 +237,7 @@ internal object ChatUtil { fun convertEmojis(text: String): String { var discordMessageString = text - val guildEmojis = discordBridgeLock.read { ChatOG.discordBridge?.getGuildById(config!!.guildId!!)?.emojis } + val guildEmojis = discordBridgeLock.read { ChatOG.discordBridge?.getGuildById(config.guildId!!)?.emojis } if (guildEmojis == null) { ChatOG.plugin.logger.warning("Guild emojis was null") } diff --git a/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt b/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt index 609f57b..d330cef 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt @@ -46,9 +46,9 @@ internal class DiscordBridge private constructor() { companion object { fun create(): DiscordBridge? { val discordBridge = DiscordBridge() - if (config!!.webhook != null) { + if (config.webhook != null) { try { - discordBridge.webhook = WebhookClient.withUrl(config!!.webhook!!) + discordBridge.webhook = WebhookClient.withUrl(config.webhook!!) } catch (_: IllegalArgumentException) { ChatOG.plugin.logger.warning("Config option \"webhook\" is invalid") } @@ -56,98 +56,98 @@ internal class DiscordBridge private constructor() { ChatOG.plugin.logger.severe("You have enabled Discord but have not set up the webhook") return null } - if (config!!.staffWebhook != null) { + if (config.staffWebhook != null) { try { - discordBridge.staffWebhook = WebhookClient.withUrl(config!!.staffWebhook!!) + discordBridge.staffWebhook = WebhookClient.withUrl(config.staffWebhook!!) } catch (_: IllegalArgumentException) { ChatOG.plugin.logger.warning("Config option \"staffWebhook\" is invalid") } - } else if (config!!.staffDiscordEnabled) { + } else if (config.staffDiscordEnabled) { ChatOG.plugin.logger.warning("You have enabled staff Discord but have not set up the staff webhook") } - if (config!!.premiumWebhook != null) { + if (config.premiumWebhook != null) { try { - discordBridge.premiumWebhook = WebhookClient.withUrl(config!!.premiumWebhook!!) + discordBridge.premiumWebhook = WebhookClient.withUrl(config.premiumWebhook!!) } catch (_: IllegalArgumentException) { ChatOG.plugin.logger.warning("Config option \"premiumWebhook\" is invalid") } - } else if (config!!.premiumDiscordEnabled) { + } else if (config.premiumDiscordEnabled) { ChatOG.plugin.logger.warning("You have enabled premium Discord but have not set up the premium webhook") } - if (config!!.developerWebhook != null) { + if (config.developerWebhook != null) { try { - discordBridge.developerWebhook = WebhookClient.withUrl(config!!.developerWebhook!!) + discordBridge.developerWebhook = WebhookClient.withUrl(config.developerWebhook!!) } catch (_: IllegalArgumentException) { ChatOG.plugin.logger.warning("Config option \"developer\" is invalid") } - } else if (config!!.premiumDiscordEnabled) { + } else if (config.premiumDiscordEnabled) { ChatOG.plugin.logger.warning( "You have enabled developer Discord but have not set up the developer webhook" ) } - if (config!!.botToken == null) { + if (config.botToken == null) { ChatOG.plugin.logger.severe("You have enabled Discord but have not set up the bot token") return null } discordBridge.jda = - light(config!!.botToken!!, enableCoroutines = true) { + light(config.botToken!!, enableCoroutines = true) { intents += listOf(GatewayIntent.GUILD_MEMBERS, GatewayIntent.MESSAGE_CONTENT) cache += listOf(CacheFlag.EMOJI) setMemberCachePolicy(MemberCachePolicy.ALL) } val status = - if (config!!.status == null) { + if (config.status == null) { ChatOG.plugin.logger.warning( "You have enabled Discord but have not set up the status, using the default one instead" ) "Minecraft" } else { - config!!.status!! + config.status!! } discordBridge.jda.presence.setPresence(Activity.playing(status), false) val serverHasStartedMessage = - if (config!!.serverHasStartedMessage == null) { + if (config.serverHasStartedMessage == null) { ChatOG.plugin.logger.warning( "You have enabled Discord but have not set up the server has started message, using the default one instead" ) "The server has started" } else { - config!!.serverHasStartedMessage!! + config.serverHasStartedMessage!! } - if (config!!.guildId == null) { + if (config.guildId == null) { ChatOG.plugin.logger.severe("You have enabled Discord but have not set up the guild ID") return null } discordBridge.jda.listener { discordBridge.sendMessageWithBot(serverHasStartedMessage) - val guild = discordBridge.jda.getGuildById(config!!.guildId!!) + val guild = discordBridge.jda.getGuildById(config.guildId!!) if (guild == null) { ChatOG.plugin.logger.severe("Guild was null") return@listener } - if (config!!.listCommandName == null) { + if (config.listCommandName == null) { ChatOG.plugin.logger.warning( "You have enabled Discord but have not set up the list command name, the command will not be created" ) return@listener } - if (config!!.listCommandText == null) { + if (config.listCommandText == null) { ChatOG.plugin.logger.warning( "You have enabled Discord but have not set up the list command text, the command will not be created" ) } - guild.upsertCommand(config!!.listCommandName!!, "List all online players.").queue() + guild.upsertCommand(config.listCommandName!!, "List all online players.").queue() } discordBridge.jda.listener { - if (it.name == config!!.listCommandName) { + if (it.name == config.listCommandName) { it.deferReply().queue() try { if (Bukkit.getOnlinePlayers().isEmpty()) { @@ -157,7 +157,7 @@ internal class DiscordBridge private constructor() { it.hook .sendMessage( "${ - config!!.listCommandText!! + config.listCommandText!! .replace("%onlineplayers%", Bukkit.getOnlinePlayers().count().toString()) .replace("%maxplayers%", Bukkit.getMaxPlayers().toString()) }\n${ @@ -173,10 +173,10 @@ internal class DiscordBridge private constructor() { discordBridge.jda.listener { if ( - it.channel.id != config!!.channelId && - (if (config!!.staffDiscordEnabled) it.channel.id != config!!.staffChannelId else true) && - (if (config!!.premiumDiscordEnabled) it.channel.id != config!!.premiumChannelId else true) && - (if (config!!.developerDiscordEnabled) it.channel.id != config!!.developerChannelId else true) + it.channel.id != config.channelId && + (if (config.staffDiscordEnabled) it.channel.id != config.staffChannelId else true) && + (if (config.premiumDiscordEnabled) it.channel.id != config.premiumChannelId else true) && + (if (config.developerDiscordEnabled) it.channel.id != config.developerChannelId else true) ) { return@listener } @@ -209,19 +209,18 @@ internal class DiscordBridge private constructor() { } val messageColor = - if (config!!.roles.isEmpty()) { + if (config.roles.isEmpty()) { NamedTextColor.GRAY } else { val roleId = message.guild .getRoleById( - config!! - .roles + config.roles .filter { role -> topRole!!.id == message.guild.getRoleById(role)?.id }[0] ) ?.id if (roleId != null) { - val roleColor = config!!.roleMessageColor[roleId] + val roleColor = config.roleMessageColor[roleId] if (roleColor is Config.RGBColor) { TextColor.color(roleColor.r, roleColor.g, roleColor.b) @@ -259,8 +258,8 @@ internal class DiscordBridge private constructor() { } val useColor = - if (config!!.useColorCodeRoles) { - roles.any { role -> role.id in config!!.colorCodeRoles } + if (config.useColorCodeRoles) { + roles.any { role -> role.id in config.colorCodeRoles } } else { true } @@ -298,7 +297,7 @@ internal class DiscordBridge private constructor() { var messageComponent = when (it.channel.id) { - config!!.staffChannelId -> { + config.staffChannelId -> { val staffComponent = Component.text("STAFF | ").color(NamedTextColor.RED) Component.join( JoinConfiguration.noSeparators(), @@ -310,7 +309,7 @@ internal class DiscordBridge private constructor() { ) } - config!!.premiumChannelId -> { + config.premiumChannelId -> { val premiumComponent = Component.text("PREMIUM | ").color(NamedTextColor.GREEN) Component.join( JoinConfiguration.noSeparators(), @@ -322,7 +321,7 @@ internal class DiscordBridge private constructor() { ) } - config!!.developerChannelId -> { + config.developerChannelId -> { val developerComponent = Component.text("DEVELOPER | ").color(NamedTextColor.AQUA) Component.join( JoinConfiguration.noSeparators(), @@ -360,7 +359,7 @@ internal class DiscordBridge private constructor() { ) when (it.channel.id) { - config!!.staffChannelId -> { + config.staffChannelId -> { for (p in Bukkit.getOnlinePlayers()) { if (p.hasPermission("chat-og.staff")) { p.sendMessage(messageComponent) @@ -368,7 +367,7 @@ internal class DiscordBridge private constructor() { } } - config!!.premiumChannelId -> { + config.premiumChannelId -> { for (p in Bukkit.getOnlinePlayers()) { if (p.hasPermission("chat-og.premium")) { p.sendMessage(messageComponent) @@ -404,9 +403,9 @@ internal class DiscordBridge private constructor() { } fun sendMessageWithBot(message: String) { - if (config!!.channelId == null) return + if (config.channelId == null) return - val channel = jda.getChannel(config!!.channelId!!) + val channel = jda.getChannel(config.channelId!!) if (channel == null) { ChatOG.plugin.logger.warning("channelId has not been set or is invalid") return @@ -437,7 +436,7 @@ internal class DiscordBridge private constructor() { } suspend fun sendStaffMessage(message: String, name: String, uuid: UUID?) { - if (!config!!.staffDiscordEnabled) return + if (!config.staffDiscordEnabled) return if (staffWebhook == null) { ChatOG.plugin.logger.warning("staffWebhook has not been set or is invalid") @@ -455,7 +454,7 @@ internal class DiscordBridge private constructor() { } suspend fun sendPremiumMessage(message: String, name: String, uuid: UUID?) { - if (!config!!.premiumDiscordEnabled) return + if (!config.premiumDiscordEnabled) return if (premiumWebhook == null) { ChatOG.plugin.logger.warning("premiumWebhook has not been set or is invalid") @@ -473,7 +472,7 @@ internal class DiscordBridge private constructor() { } suspend fun sendDeveloperMessage(message: String, name: String, uuid: UUID?) { - if (!config!!.developerDiscordEnabled) return + if (!config.developerDiscordEnabled) return if (developerWebhook == null) { ChatOG.plugin.logger.warning("developerWebhook has not been set or is invalid") diff --git a/src/main/kotlin/nl/skbotnl/chatog/Events.kt b/src/main/kotlin/nl/skbotnl/chatog/Events.kt index 6319351..863be70 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/Events.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/Events.kt @@ -35,7 +35,7 @@ import xyz.jpenilla.announcerplus.listener.JoinQuitListener internal class Events : Listener { @EventHandler fun onJoin(event: PlayerJoinEvent) { - if (!config!!.discordEnabled) { + if (!config.discordEnabled) { return } if (ChatOG.essentials.getUser(event.player).isVanished && event.joinMessage() !is TextComponent) { @@ -59,7 +59,7 @@ internal class Events : Listener { @EventHandler fun onQuit(event: PlayerQuitEvent) { - if (!config!!.discordEnabled) { + if (!config.discordEnabled) { return } if (ChatOG.essentials.getUser(event.player).isVanished) { @@ -83,7 +83,7 @@ internal class Events : Listener { @EventHandler fun onKick(event: PlayerKickEvent) { - if (!config!!.discordEnabled) { + if (!config.discordEnabled) { return } if (ChatOG.essentials.getUser(event.player).isVanished) { @@ -109,7 +109,7 @@ internal class Events : Listener { @EventHandler fun onAdvancement(event: PlayerAdvancementDoneEvent) { - if (!config!!.discordEnabled) { + if (!config.discordEnabled) { return } if (ChatOG.essentials.getUser(event.player).isVanished) { @@ -144,7 +144,7 @@ internal class Events : Listener { @EventHandler fun onBroadcast(event: BroadcastMessageEvent) { - if (!config!!.discordEnabled) { + if (!config.discordEnabled) { return } if (event.message() !is TextComponent) { @@ -221,7 +221,7 @@ internal class Events : Listener { @EventHandler fun onDeath(event: PlayerDeathEvent) { - if (!config!!.discordEnabled) { + if (!config.discordEnabled) { return } if (ChatOG.essentials.getUser(event.player).isVanished) { diff --git a/src/main/kotlin/nl/skbotnl/chatog/LanguageDatabase.kt b/src/main/kotlin/nl/skbotnl/chatog/LanguageDatabase.kt index cc53fae..6d3dafb 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/LanguageDatabase.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/LanguageDatabase.kt @@ -6,7 +6,7 @@ import java.util.* import nl.skbotnl.chatog.ChatOG.Companion.config internal class LanguageDatabase { - private val redisClient: RedisClient = RedisClient.create(config!!.redisUrl) + private val redisClient: RedisClient = RedisClient.create(config.redisUrl) /** @return True if failed */ fun testConnection(): Boolean { diff --git a/src/main/kotlin/nl/skbotnl/chatog/OpenAI.kt b/src/main/kotlin/nl/skbotnl/chatog/OpenAI.kt index 899240e..358b2a0 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/OpenAI.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/OpenAI.kt @@ -31,7 +31,7 @@ internal class OpenAI { fun translate(text: String, language: String): Translated { val openAICompletion = CompletionReq( - model = config!!.openAIModel ?: "", + model = config.openAIModel ?: "", messages = listOf( Message( @@ -44,8 +44,8 @@ internal class OpenAI { val request: Request = Request.Builder() - .url(config!!.openAIBaseUrl + "/v1/chat/completions") - .header("Authorization", "Bearer ${config!!.openAIApiKey}") + .url(config.openAIBaseUrl + "/v1/chat/completions") + .header("Authorization", "Bearer ${config.openAIApiKey}") .post(gson.toJson(openAICompletion).toRequestBody("application/json".toMediaType())) .build() @@ -61,7 +61,7 @@ internal class OpenAI { null, null, UtilitiesOG.trueogColorize( - "${config!!.prefix}: Something went wrong while translating that message." + "${config.prefix}: Something went wrong while translating that message." ), ) } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/ChatConfigReload.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/ChatConfigReload.kt index 246713b..bb936d5 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/ChatConfigReload.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/ChatConfigReload.kt @@ -33,18 +33,18 @@ internal class ChatConfigReload : CommandExecutor { return true } - if (config!!.blocklistEnabled) { + if (config.blocklistEnabled) { blocklistManager = BlocklistManager() } translator = - if (config!!.openAIEnabled) { - if (config!!.openAIBaseUrl == null) { + if (config.openAIEnabled) { + if (config.openAIBaseUrl == null) { ChatOG.plugin.logger.warning( "You have enabled OpenAI translation but have not set up the base url, not enabling the translator" ) null - } else if (config!!.openAIApiKey == null) { + } else if (config.openAIApiKey == null) { ChatOG.plugin.logger.warning( "You have enabled OpenAI translation but have not set up the api key, not enabling the translator" ) @@ -61,7 +61,7 @@ internal class ChatConfigReload : CommandExecutor { return true } - if (config!!.discordEnabled) { + if (config.discordEnabled) { scope.launch { discordBridgeLock.write { val discordBridge = ChatOG.discordBridge @@ -71,15 +71,13 @@ internal class ChatConfigReload : CommandExecutor { } ChatOG.discordBridge = DiscordBridge.create() sender.sendMessage( - UtilitiesOG.trueogColorize( - "${config!!.prefix}: Successfully reloaded the config." - ) + UtilitiesOG.trueogColorize("${config.prefix}: Successfully reloaded the config.") ) } } } else { sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: Successfully reloaded the config.") + UtilitiesOG.trueogColorize("${config.prefix}: Successfully reloaded the config.") ) } return true diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/DeveloperChat.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/DeveloperChat.kt index f71756a..6e3106f 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/DeveloperChat.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/DeveloperChat.kt @@ -20,7 +20,7 @@ class DeveloperChat : CommandExecutor { if (!sender.hasPermission("chat-og.developer")) { sender.sendMessage( UtilitiesOG.trueogColorize( - "${config!!.prefix}: You do not have permission to run this command." + "${config.prefix}: You do not have permission to run this command." ) ) return true @@ -31,13 +31,13 @@ class DeveloperChat : CommandExecutor { ChatSystem.inChat[sender.uniqueId] = ChatType.GENERAL_CHAT sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in the general chat.") + UtilitiesOG.trueogColorize("${config.prefix}: You are now talking in the general chat.") ) return true } ChatSystem.inChat[sender.uniqueId] = ChatType.DEVELOPER_CHAT sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in the developer chat.") + UtilitiesOG.trueogColorize("${config.prefix}: You are now talking in the developer chat.") ) return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/GeneralChat.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/GeneralChat.kt index 6516af3..cba5b2a 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/GeneralChat.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/GeneralChat.kt @@ -22,12 +22,12 @@ class GeneralChat : CommandExecutor { ChatSystem.inChat[sender.uniqueId] = ChatType.GENERAL_CHAT sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in the general chat.") + UtilitiesOG.trueogColorize("${config.prefix}: You are now talking in the general chat.") ) return true } sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: You are already talking in the general chat.") + UtilitiesOG.trueogColorize("${config.prefix}: You are already talking in the general chat.") ) return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/PremiumChat.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/PremiumChat.kt index 3224f40..8212f15 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/PremiumChat.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/PremiumChat.kt @@ -18,7 +18,7 @@ internal class PremiumChat : CommandExecutor { if (!sender.hasPermission("chat-og.premium")) { sender.sendMessage( UtilitiesOG.trueogColorize( - "${config!!.prefix}: You do not have permission to run this command." + "${config.prefix}: You do not have permission to run this command." ) ) return true @@ -28,13 +28,13 @@ internal class PremiumChat : CommandExecutor { ChatSystem.inChat[sender.uniqueId] = ChatType.GENERAL_CHAT sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in the general chat.") + UtilitiesOG.trueogColorize("${config.prefix}: You are now talking in the general chat.") ) return true } ChatSystem.inChat[sender.uniqueId] = ChatType.PREMIUM_CHAT sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in the premium chat.") + UtilitiesOG.trueogColorize("${config.prefix}: You are now talking in the premium chat.") ) return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/PrivateMessage.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/PrivateMessage.kt index a7f7baf..110e0ae 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/PrivateMessage.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/PrivateMessage.kt @@ -26,7 +26,7 @@ internal class PrivateMessage : CommandExecutor { if (args == null || args.isEmpty()) { sender.sendMessage( UtilitiesOG.trueogColorize( - "${config!!.prefix}: You did not provide the player that you want to send a message to and your message." + "${config.prefix}: You did not provide the player that you want to send a message to and your message." ) ) return true @@ -34,7 +34,7 @@ internal class PrivateMessage : CommandExecutor { if (args.size < 2) { sender.sendMessage( UtilitiesOG.trueogColorize( - "${config!!.prefix}: Please provide the player that you want to send a message to and your message." + "${config.prefix}: Please provide the player that you want to send a message to and your message." ) ) return true @@ -45,7 +45,7 @@ internal class PrivateMessage : CommandExecutor { val toPlayer = Bukkit.getPlayer(playerName) if (toPlayer == null) { sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: That player doesn't exist or isn't online.") + UtilitiesOG.trueogColorize("${config.prefix}: That player doesn't exist or isn't online.") ) return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/Reply.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/Reply.kt index 9793a2a..1a3e20a 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/Reply.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/Reply.kt @@ -25,7 +25,7 @@ internal class Reply : CommandExecutor { if (args == null || args.isEmpty()) { sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: You did not provide your message.") + UtilitiesOG.trueogColorize("${config.prefix}: You did not provide your message.") ) return true } @@ -33,7 +33,7 @@ internal class Reply : CommandExecutor { val lastMessaged = lastMessagedMap[sender.uniqueId] if (lastMessaged == null) { sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: You haven't messaged anyone yet.") + UtilitiesOG.trueogColorize("${config.prefix}: You haven't messaged anyone yet.") ) return true } @@ -41,7 +41,7 @@ internal class Reply : CommandExecutor { val toPlayer = Bukkit.getPlayer(lastMessaged) if (toPlayer == null) { sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: That player doesn't exist or isn't online.") + UtilitiesOG.trueogColorize("${config.prefix}: That player doesn't exist or isn't online.") ) return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/StaffChat.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/StaffChat.kt index 632d80c..d108812 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/StaffChat.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/StaffChat.kt @@ -19,7 +19,7 @@ internal class StaffChat : CommandExecutor { if (!sender.hasPermission("chat-og.staff")) { sender.sendMessage( UtilitiesOG.trueogColorize( - "${config!!.prefix}: You do not have permission to run this command." + "${config.prefix}: You do not have permission to run this command." ) ) return true @@ -30,13 +30,13 @@ internal class StaffChat : CommandExecutor { ChatSystem.inChat[sender.uniqueId] = ChatType.GENERAL_CHAT sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in general chat.") + UtilitiesOG.trueogColorize("${config.prefix}: You are now talking in general chat.") ) return true } ChatSystem.inChat[sender.uniqueId] = ChatType.STAFF_CHAT sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: You are now talking in staff chat.") + UtilitiesOG.trueogColorize("${config.prefix}: You are now talking in staff chat.") ) return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateMessage.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateMessage.kt index a384498..2825fbf 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateMessage.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateMessage.kt @@ -57,9 +57,7 @@ internal class TranslateMessage : CommandExecutor { val player: Player = sender if (ChatUtil.getTranslateTimeout(player.uniqueId) != 0L) { - player.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: You're doing that too fast.") - ) + player.sendMessage(UtilitiesOG.trueogColorize("${config.prefix}: You're doing that too fast.")) return true } @@ -68,7 +66,7 @@ internal class TranslateMessage : CommandExecutor { try { uuid = UUID.fromString(args[0]) } catch (_: IllegalArgumentException) { - player.sendMessage(UtilitiesOG.trueogColorize("${config!!.prefix}: That is not a valid UUID.")) + player.sendMessage(UtilitiesOG.trueogColorize("${config.prefix}: That is not a valid UUID.")) return true } @@ -76,7 +74,7 @@ internal class TranslateMessage : CommandExecutor { try { messageType = args[1].toInt() } catch (_: NumberFormatException) { - player.sendMessage(UtilitiesOG.trueogColorize("${config!!.prefix}: Invalid message type.")) + player.sendMessage(UtilitiesOG.trueogColorize("${config.prefix}: Invalid message type.")) return true } @@ -91,16 +89,12 @@ internal class TranslateMessage : CommandExecutor { } if (sentMessage == null) { - player.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: Could not find that message.") - ) + player.sendMessage(UtilitiesOG.trueogColorize("${config.prefix}: Could not find that message.")) return true } if (ChatOG.translator == null) { - player.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: The translator is disabled.") - ) + player.sendMessage(UtilitiesOG.trueogColorize("${config.prefix}: The translator is disabled.")) return true } @@ -109,14 +103,14 @@ internal class TranslateMessage : CommandExecutor { if (language == null) { player.sendMessage( UtilitiesOG.trueogColorize( - "${config!!.prefix}: Something went wrong while trying to get your preferred language." + "${config.prefix}: Something went wrong while trying to get your preferred language." ) ) return true } player.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: Translating message (this can take some time)...") + UtilitiesOG.trueogColorize("${config.prefix}: Translating message (this can take some time)...") ) val translated = ChatOG.translator!!.translate(sentMessage.message, language) @@ -128,7 +122,7 @@ internal class TranslateMessage : CommandExecutor { if (translated.translatedText == null) { player.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: Could not translate that message.") + UtilitiesOG.trueogColorize("${config.prefix}: Could not translate that message.") ) return true } diff --git a/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateSettings.kt b/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateSettings.kt index e9fed20..b327b46 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateSettings.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/commands/TranslateSettings.kt @@ -74,13 +74,13 @@ internal class TranslateSettings : CommandExecutor { val language = args[0] if (languagesList.indexOf(language) == -1) { - sender.sendMessage(UtilitiesOG.trueogColorize("${config!!.prefix}: Invalid language.")) + sender.sendMessage(UtilitiesOG.trueogColorize("${config.prefix}: Invalid language.")) return true } ChatOG.languageDatabase.setPlayerLanguage(sender.uniqueId, language) sender.sendMessage( - UtilitiesOG.trueogColorize("${config!!.prefix}: Set language to: $language.") + UtilitiesOG.trueogColorize("${config.prefix}: Set language to: $language.") ) return true -- 2.47.3 From 08897bd2fe4318b1105695c390a4082e5f23ec66 Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 23 Jul 2025 22:10:58 +0200 Subject: [PATCH 08/11] Fix NPE --- src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt | 32 +++++++++------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt index d32b980..b52aecb 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt @@ -27,8 +27,6 @@ internal class ChatOG : JavaPlugin() { val discordBridgeLock = ReentrantReadWriteLock() var essentials = Bukkit.getServer().pluginManager.getPlugin("Essentials") as Essentials var lastMessagedMap: MutableMap = HashMap() - - fun isConfigInitialized() = ::config.isInitialized } @OptIn(DelicateCoroutinesApi::class) @@ -108,22 +106,20 @@ internal class ChatOG : JavaPlugin() { } override fun onDisable() { - if (isConfigInitialized()) { - if (Companion.config.discordEnabled) { - discordBridgeLock.read { - val discordBridge = discordBridge - val serverHasStoppedMessage = - if (Companion.config.serverHasStoppedMessage == null) { - this.logger.warning( - "You have enabled Discord but have not set up the server has stopped message, using the default one instead" - ) - "The server has stopped" - } else { - Companion.config.serverHasStoppedMessage!! - } - discordBridge!!.sendMessageWithBot(serverHasStoppedMessage) - discordBridge.shutdownNow() - } + if (discordBridge != null) { + discordBridgeLock.read { + val discordBridge = discordBridge + val serverHasStoppedMessage = + if (Companion.config.serverHasStoppedMessage == null) { + this.logger.warning( + "You have enabled Discord but have not set up the server has stopped message, using the default one instead" + ) + "The server has stopped" + } else { + Companion.config.serverHasStoppedMessage!! + } + discordBridge!!.sendMessageWithBot(serverHasStoppedMessage) + discordBridge.shutdownNow() } } -- 2.47.3 From e771e4799aee3f4a3ba7ddfa27c26c065cfa3fa0 Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 23 Jul 2025 22:14:13 +0200 Subject: [PATCH 09/11] Totally didn't forget to remove this --- src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt index 0f5a122..6d3538d 100644 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatUtil.kt @@ -219,14 +219,11 @@ internal object ChatUtil { } return if (player?.hasPermission("chat-og.color") == true) { - println("A") colorMm.deserialize(words.joinToString(" ")) } else { if (color) { - println("B") colorMm.deserialize(words.joinToString(" ")) } else { - println("C") noColorMm.deserialize(words.joinToString(" ")) } } -- 2.47.3 From 4f2d6eaa73fd65ddc734ed0ccad658d46372f210 Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 23 Jul 2025 22:19:31 +0200 Subject: [PATCH 10/11] Actually shut down Redis --- src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt | 6 ++++++ src/main/kotlin/nl/skbotnl/chatog/LanguageDatabase.kt | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt b/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt index b52aecb..d3262db 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/ChatOG.kt @@ -27,6 +27,8 @@ internal class ChatOG : JavaPlugin() { val discordBridgeLock = ReentrantReadWriteLock() var essentials = Bukkit.getServer().pluginManager.getPlugin("Essentials") as Essentials var lastMessagedMap: MutableMap = HashMap() + + fun isLanguageDatabaseInitialized() = ::languageDatabase.isInitialized } @OptIn(DelicateCoroutinesApi::class) @@ -123,6 +125,10 @@ internal class ChatOG : JavaPlugin() { } } + if (isLanguageDatabaseInitialized()) { + languageDatabase.shutdown() + } + scope.cancel() runBlocking { scope.coroutineContext[Job]?.join() } diff --git a/src/main/kotlin/nl/skbotnl/chatog/LanguageDatabase.kt b/src/main/kotlin/nl/skbotnl/chatog/LanguageDatabase.kt index 6d3dafb..edcaa57 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/LanguageDatabase.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/LanguageDatabase.kt @@ -33,4 +33,8 @@ internal class LanguageDatabase { commands.set("chatog:language:$uuid", language) connection.close() } + + fun shutdown() { + redisClient.shutdown() + } } -- 2.47.3 From b867776627f210819245f1e9638c8a7ba8ee0ca4 Mon Sep 17 00:00:00 2001 From: Sven Date: Wed, 23 Jul 2025 22:21:55 +0200 Subject: [PATCH 11/11] Configurable Discord suffixes --- src/main/kotlin/nl/skbotnl/chatog/Config.kt | 132 +++++++++++------- .../kotlin/nl/skbotnl/chatog/DiscordBridge.kt | 28 ++-- src/main/resources/config.yml | 9 +- 3 files changed, 106 insertions(+), 63 deletions(-) diff --git a/src/main/kotlin/nl/skbotnl/chatog/Config.kt b/src/main/kotlin/nl/skbotnl/chatog/Config.kt index 2a11f1e..3449104 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/Config.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/Config.kt @@ -36,6 +36,8 @@ internal class Config private constructor() { var colorCodeRoles = listOf() var roles = setOf() var roleMessageColor: MutableMap = mutableMapOf() + var rolesWithSuffixes = setOf() + var roleSuffix: MutableMap = mutableMapOf() data class RGBColor(val r: Int, val g: Int, val b: Int) @@ -254,66 +256,92 @@ internal class Config private constructor() { config.colorCodeRoles = yamlConfig.getStringList("colorCodeRoles") config.roles = yamlConfig.getConfigurationSection("roles")?.getKeys(false) ?: setOf() + config.rolesWithSuffixes = yamlConfig.getConfigurationSection("roleSuffixes")?.getKeys(false) ?: setOf() } - if (config.roles.isEmpty()) { - config.roleMessageColor = mutableMapOf() - return config - } + if (config.roles.isNotEmpty()) { + val messageColors = + mapOf( + Pair("BLACK", NamedTextColor.BLACK), + Pair("DARK_BLUE", NamedTextColor.DARK_BLUE), + Pair("DARK_GREEN", NamedTextColor.DARK_GREEN), + Pair("DARK_AQUA", NamedTextColor.DARK_AQUA), + Pair("DARK_RED", NamedTextColor.DARK_RED), + Pair("DARK_PURPLE", NamedTextColor.DARK_PURPLE), + Pair("GOLD", NamedTextColor.GOLD), + Pair("GRAY", NamedTextColor.GRAY), + Pair("DARK_GRAY", NamedTextColor.DARK_GRAY), + Pair("BLUE", NamedTextColor.BLUE), + Pair("GREEN", NamedTextColor.GREEN), + Pair("AQUA", NamedTextColor.AQUA), + Pair("RED", NamedTextColor.RED), + Pair("LIGHT_PURPLE", NamedTextColor.LIGHT_PURPLE), + Pair("YELLOW", NamedTextColor.YELLOW), + Pair("WHITE", NamedTextColor.WHITE), + ) + config.roles.forEach { + val messageColorList = yamlConfig.getStringList("roles.$it.message_color") + config.roleMessageColor[it] = + if (messageColorList.isEmpty()) { + try { + yamlConfig.get("roles.$it.message_color") as String + } catch (_: Exception) { + ChatOG.plugin.logger.warning( + "Failed to parse config option \"role.$it.message_color\" as a string" + ) + return@forEach + } - val messageColors = - mapOf( - Pair("BLACK", NamedTextColor.BLACK), - Pair("DARK_BLUE", NamedTextColor.DARK_BLUE), - Pair("DARK_GREEN", NamedTextColor.DARK_GREEN), - Pair("DARK_AQUA", NamedTextColor.DARK_AQUA), - Pair("DARK_RED", NamedTextColor.DARK_RED), - Pair("DARK_PURPLE", NamedTextColor.DARK_PURPLE), - Pair("GOLD", NamedTextColor.GOLD), - Pair("GRAY", NamedTextColor.GRAY), - Pair("DARK_GRAY", NamedTextColor.DARK_GRAY), - Pair("BLUE", NamedTextColor.BLUE), - Pair("GREEN", NamedTextColor.GREEN), - Pair("AQUA", NamedTextColor.AQUA), - Pair("RED", NamedTextColor.RED), - Pair("LIGHT_PURPLE", NamedTextColor.LIGHT_PURPLE), - Pair("YELLOW", NamedTextColor.YELLOW), - Pair("WHITE", NamedTextColor.WHITE), - ) - config.roles.forEach { - val messageColorList = yamlConfig.getStringList("roles.$it.message_color") - config.roleMessageColor[it] = - if (messageColorList.isEmpty()) { - try { - yamlConfig.get("roles.$it.message_color") as String - } catch (_: Exception) { - return@forEach + if (!messageColors.contains(messageColorList[0].uppercase())) { + ChatOG.plugin.logger.severe( + "The message color for \"$it\" (\"${messageColorList[0]}\") is invalid." + ) + return@forEach + } + + messageColors[messageColorList[0].uppercase()]!! + } else { + if (messageColorList.size != 3) { + ChatOG.plugin.logger.severe( + "The message color for \"$it\" is not a color or an RGB value." + ) + return@forEach + } + + messageColorList.forEach colorForEach@{ colorInList -> + try { + colorInList.toUByte() + } catch (_: Exception) { + ChatOG.plugin.logger.severe("The RGB value for \"$it\" is invalid.") + return@forEach + } + } + RGBColor( + messageColorList[0].toInt(), + messageColorList[1].toInt(), + messageColorList[2].toInt(), + ) } + } + } else { + config.roleMessageColor = mutableMapOf() + } - if (!messageColors.contains(messageColorList[0].uppercase())) { - ChatOG.plugin.logger.severe( - "The message color for \"$it\" (\"${messageColorList[0]}\") is invalid." + if (config.rolesWithSuffixes.isNotEmpty()) { + config.rolesWithSuffixes.forEach { + val suffixList = + try { + yamlConfig.get("roleSuffixes.$it.suffix") as String + } catch (_: Exception) { + ChatOG.plugin.logger.warning( + "Failed to parse config option \"roleSuffixes.$it.suffix\" as a string" ) return@forEach } - - messageColors[messageColorList[0].uppercase()]!! - } else { - if (messageColorList.size != 3) { - ChatOG.plugin.logger.severe("The message color for \"$it\" is not a color or an RGB value.") - return@forEach - } - - messageColorList.forEach colorForEach@{ colorInList -> - try { - colorInList.toUByte() - } catch (_: Exception) { - ChatOG.plugin.logger.severe("The RGB value for \"$it\" is invalid.") - return@forEach - } - } - RGBColor(messageColorList[0].toInt(), messageColorList[1].toInt(), messageColorList[2].toInt()) - } + config.roleSuffix[it] = suffixList + } + } else { + config.roleSuffix = mutableMapOf() } return config diff --git a/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt b/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt index d330cef..0dc73f9 100755 --- a/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt +++ b/src/main/kotlin/nl/skbotnl/chatog/DiscordBridge.kt @@ -199,6 +199,7 @@ internal class DiscordBridge private constructor() { val roles = member.roles val topRole = roles.maxByOrNull { role -> role.positionRaw } + val sortedRoles = member.roles.sortedByDescending { role -> role.positionRaw } val discordComponent = Component.text("Discord: ").color(TextColor.color(88, 101, 242)) val userComponent: TextComponent = @@ -212,13 +213,7 @@ internal class DiscordBridge private constructor() { if (config.roles.isEmpty()) { NamedTextColor.GRAY } else { - val roleId = - message.guild - .getRoleById( - config.roles - .filter { role -> topRole!!.id == message.guild.getRoleById(role)?.id }[0] - ) - ?.id + val roleId = sortedRoles.first { role -> role.id in config.roles }?.id if (roleId != null) { val roleColor = config.roleMessageColor[roleId] @@ -230,7 +225,19 @@ internal class DiscordBridge private constructor() { } else NamedTextColor.GRAY } - val messageComponents = mutableListOf(Component.text(">")) + val suffix = + if (config.rolesWithSuffixes.isEmpty()) { + ">" + } else { + val roleId = sortedRoles.first { role -> role.id in config.rolesWithSuffixes }?.id + if (roleId != null) { + config.roleSuffix[roleId]!! + } else { + ">" + } + } + + val messageComponents = mutableListOf(UtilitiesOG.trueogColorize(suffix)) val attachmentComponents = mutableListOf() @@ -279,7 +286,8 @@ internal class DiscordBridge private constructor() { val contentComponent = Component.join( JoinConfiguration.separator(Component.text(" ")), - messageComponents + attachmentComponents, + Component.join(JoinConfiguration.noSeparators(), messageComponents), + Component.join(JoinConfiguration.noSeparators(), attachmentComponents), ) var replyComponent = Component.text("") @@ -387,7 +395,7 @@ internal class DiscordBridge private constructor() { message.contentDisplay, member.effectiveName, Component.join(JoinConfiguration.noSeparators(), discordComponent, userComponent), - Component.text("> "), + Component.text("$suffix "), ) } return discordBridge diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6e0cfcb..58e3343 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -56,10 +56,17 @@ useColorCodeRoles: false # 1234567891234567890: # message_color: RED # -# message_color can be one of these: BLACK, DARK_BLUE, DARK_GREEN, DARK_AQUA, DARK_RED, DARK_PURPLE, GOLD, GRAY, DARK_GRAY, BLUE, GREEN, AQUA, RED, LIGHT_PURPLE, YELLOW, WHITE +# message_color can be one of the following: BLACK, DARK_BLUE, DARK_GREEN, DARK_AQUA, DARK_RED, DARK_PURPLE, GOLD, GRAY, DARK_GRAY, BLUE, GREEN, AQUA, RED, LIGHT_PURPLE, YELLOW, WHITE # # You can also use RGB for the color: # # roles: # 1234567891234567890: # message_color: [255, 255, 255] + +# Configure the suffix for roles (has to include the space). color codes are allowed. +# For example: + +# roleSuffixes: +# 1234567891234567890: +# suffix: ": " \ No newline at end of file -- 2.47.3