From 4e5dc6eca03e97dd0b1afe3c4eda22403f89ca58 Mon Sep 17 00:00:00 2001 From: Boy Date: Wed, 21 Feb 2024 11:37:33 +0100 Subject: [PATCH] fix: discord to mc not correctly showing --- .../main/kotlin/com/mineinabyss/chatty/ChattyContext.kt | 1 + .../mineinabyss/chatty/listeners/ChattyProxyListener.kt | 4 +++- .../src/main/kotlin/com/mineinabyss/chatty/ChattyPlugin.kt | 7 +++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyContext.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyContext.kt index bfe9c34..7d38e1d 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyContext.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyContext.kt @@ -7,6 +7,7 @@ import com.mineinabyss.idofront.di.DI import org.bukkit.Bukkit const val chattyProxyChannel = "chatty:proxy" +const val discordSrvChannel = "chatty:discordsrv" val chatty by DI.observe() interface ChattyContext { val plugin: ChattyPlugin diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChattyProxyListener.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChattyProxyListener.kt index eb50e4b..4160f3b 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChattyProxyListener.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChattyProxyListener.kt @@ -5,9 +5,11 @@ import com.mineinabyss.chatty.chatty import com.mineinabyss.chatty.chattyProxyChannel import com.mineinabyss.chatty.components.ChannelData import com.mineinabyss.chatty.components.ChannelType +import com.mineinabyss.chatty.discordSrvChannel import com.mineinabyss.chatty.helpers.gson import com.mineinabyss.chatty.helpers.toPlayer import com.mineinabyss.geary.papermc.tracking.entities.toGeary +import com.mineinabyss.idofront.plugin.Plugins import com.mineinabyss.idofront.textcomponents.serialize import github.scarsz.discordsrv.Debug import github.scarsz.discordsrv.DiscordSRV @@ -25,7 +27,7 @@ import org.bukkit.plugin.messaging.PluginMessageListener class ChattyProxyListener : PluginMessageListener { override fun onPluginMessageReceived(ch: String, player: Player, byteArray: ByteArray) { - if (ch != chattyProxyChannel) return + if (ch != chattyProxyChannel && ch == discordSrvChannel && Plugins.isEnabled("DiscordSRV")) return val decoded = gson.deserialize(byteArray.decodeToString()) val senderName = (decoded.children()[0] as? TextComponent)?.content() ?: return val channelId = (decoded.children()[1] as? TextComponent)?.content() ?: return diff --git a/chatty-velocity/src/main/kotlin/com/mineinabyss/chatty/ChattyPlugin.kt b/chatty-velocity/src/main/kotlin/com/mineinabyss/chatty/ChattyPlugin.kt index f63b201..350a148 100644 --- a/chatty-velocity/src/main/kotlin/com/mineinabyss/chatty/ChattyPlugin.kt +++ b/chatty-velocity/src/main/kotlin/com/mineinabyss/chatty/ChattyPlugin.kt @@ -12,6 +12,9 @@ import com.velocitypowered.api.proxy.ProxyServer import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier import org.slf4j.Logger +val chattyChannel: MinecraftChannelIdentifier = MinecraftChannelIdentifier.create("chatty", "proxy") +val discordChannel: MinecraftChannelIdentifier = MinecraftChannelIdentifier.create("chatty", "discordsrv") + @Plugin(id = "chatty", name = "chatty", version = "0.3") class ChattyPlugin @Inject constructor( private val server: ProxyServer, @@ -25,9 +28,9 @@ class ChattyPlugin @Inject constructor( @Subscribe(order = PostOrder.FIRST) fun onInit(e: ProxyInitializeEvent) { - val chattyChannel = MinecraftChannelIdentifier.create("chatty", "proxy") logger.info("The Kotlin Language Adapter is initialized!") server.channelRegistrar.register(chattyChannel) + server.channelRegistrar.register(discordChannel) eventManager.register(this, ChattyProxyListener(server, logger)) } } @@ -45,7 +48,7 @@ class ChattyProxyListener @Inject constructor( @Subscribe(order = PostOrder.NORMAL) fun PluginMessageEvent.onPluginMessage() { - if (identifier != MinecraftChannelIdentifier.create("chatty", "proxy")) return + if (identifier != chattyChannel && identifier != discordChannel) return //Hacky way of knowing what the old server was, prob a better way lol server.allServers.filter { (it.serverInfo.name !in this.source.toString()) }.forEach { it.sendPluginMessage(identifier, this.data)