sync
This commit is contained in:
parent
5681164469
commit
58e22417d8
|
|
@ -7,12 +7,16 @@ import cc.maxmc.msm.common.utils.awaiting
|
|||
import io.netty.channel.ChannelHandler.Sharable
|
||||
import io.netty.channel.ChannelHandlerContext
|
||||
import io.netty.channel.SimpleChannelInboundHandler
|
||||
import kotlin.coroutines.resume
|
||||
|
||||
@Sharable
|
||||
object ClusterPacketHandler : SimpleChannelInboundHandler<BungeePacket>() {
|
||||
override fun channelRead0(ctx: ChannelHandlerContext, msg: BungeePacket) {
|
||||
awaiting.filter { it.first == msg::class.java }
|
||||
.
|
||||
.filter { it.second(ctx.channel(), msg) }
|
||||
.forEach {
|
||||
it.third.resume(msg)
|
||||
}
|
||||
PacketReceiveEvent(ctx.channel(), msg).callEvent()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,10 +13,12 @@ val pluginScope = CoroutineScope(SupervisorJob() + CoroutineExceptionHandler { _
|
|||
except.printStackTrace()
|
||||
})
|
||||
|
||||
val awaiting = ArrayList<Triple<Class<out BungeePacket>, (BungeePacket) -> Boolean, Continuation<BungeePacket>>>()
|
||||
val awaiting =
|
||||
ArrayList<Triple<Class<out BungeePacket>, (Channel, BungeePacket) -> Boolean, Continuation<BungeePacket>>>()
|
||||
|
||||
suspend inline fun <T : BungeePacket> awaitPacket(packetClass: Class<T>, noinline filter: (Channel, T) -> Boolean) =
|
||||
suspendCoroutine<T> {
|
||||
val triple = Triple(packetClass, filter, it)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
awaiting.add(triple as Triple<Class<out BungeePacket>, (BungeePacket) -> Boolean, Continuation<BungeePacket>>)
|
||||
awaiting.add(triple as Triple<Class<out BungeePacket>, (Channel, BungeePacket) -> Boolean, Continuation<BungeePacket>>)
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ object ChildManager {
|
|||
}
|
||||
val child = ChildBungee(channel, packet.portRange)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue