Skip to content

Commit

Permalink
[6.2.0][dev] 调整 ProtocolHandler 自动接管逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
Bkm016 committed Sep 28, 2024
1 parent 74160c7 commit 3fb2bbd
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.bukkit.event.server.PluginDisableEvent
import org.bukkit.event.server.PluginEnableEvent
import taboolib.common.*
import taboolib.common.event.InternalEventBus
import taboolib.common.io.isDebugMode
import taboolib.common.platform.Awake
import taboolib.common.platform.Platform
import taboolib.common.platform.PlatformSide
Expand Down Expand Up @@ -145,9 +146,10 @@ object ProtocolHandler : OpenListener {
// 注销数据包监听器
instance?.close()
// 通知其他插件立刻接管
containers.firstOrNull()?.call(PACKET_LISTENER_EJECT, arrayOf())
// 提示新的接管者
debug("LightInjector closed, current packet listener is taken over by ${Exchanges.get<String>(PACKET_LISTENER)}.")
val next = containers.firstOrNull { it.name != pluginId }
if (next != null && next.call(PACKET_LISTENER_EJECT, arrayOf()).isSuccessful) {
debug("LightInjector closed, current packet listener is taken over by ${next.name}.")
}
}
}

Expand Down Expand Up @@ -202,8 +204,12 @@ object ProtocolHandler : OpenListener {
}
// 数据包监听器注销
PACKET_LISTENER_EJECT -> {
injectPacketListener()
return OpenResult.successful()
try {
injectPacketListener()
return OpenResult.successful()
} catch (ex: Throwable) {
if (isDebugMode) ex.printStackTrace()
}
}
}
return OpenResult.failed()
Expand Down

0 comments on commit 3fb2bbd

Please sign in to comment.