Skip to content

Commit

Permalink
fix: discord to mc not correctly showing
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Feb 21, 2024
1 parent 6e52874 commit 4e5dc6e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChattyContext>()
interface ChattyContext {
val plugin: ChattyPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))
}
}
Expand All @@ -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)
Expand Down

0 comments on commit 4e5dc6e

Please sign in to comment.