Fix crash (#45)

This commit is contained in:
mllfjn authored and GitHub committed 2026-07-04 16:57:40 +02:00
1 parent 8fb51bc8ea
commit 5c8137489f
2 files changed
+16 -7

No files matched your search

@@ -7,6 +7,7 @@ import cpw.mods.fml.common.Mod
import cpw.mods.fml.common.SidedProxy
import cpw.mods.fml.common.event.FMLPostInitializationEvent
import cpw.mods.fml.common.event.FMLPreInitializationEvent
import cpw.mods.fml.common.event.FMLServerStartingEvent
import cpw.mods.fml.common.event.FMLServerStoppedEvent
import cpw.mods.fml.common.registry.GameRegistry
import net.minecraftforge.common.config.Configuration
@@ -37,6 +38,11 @@ object BetterP2P {
proxy.postInit()
}
@Mod.EventHandler
fun onServerStarting(event: FMLServerStartingEvent) {
ModNetwork.start()
}
@Mod.EventHandler
fun onServerStopped(event: FMLServerStoppedEvent) {
ModNetwork.stop()
@@ -44,13 +44,6 @@ object ModNetwork {
channel.registerMessage(ServerRefreshP2PListHandler::class.java, C2SRefreshP2PList::class.java, id++, Side.SERVER)
channel.registerMessage(ServerUnlinkP2PHandler::class.java, C2SUnlinkP2P::class.java, id++, Side.SERVER)
channel.registerMessage(ServerTypeChangeHandler::class.java, C2STypeChange::class.java, id, Side.SERVER)
networkWorker = ScheduledThreadPoolExecutor(1, ThreadFactory {
val th = Thread(it)
th.name = "BetterP2P-NetworkWorker"
th.isDaemon = true
th.priority = Thread.MIN_PRIORITY
th
})
}
/**
@@ -115,6 +108,16 @@ object ModNetwork {
playerState.remove(player.uniqueID)
}
fun start() {
networkWorker = ScheduledThreadPoolExecutor(1, ThreadFactory {
val th = Thread(it)
th.name = "BetterP2P-NetworkWorker"
th.isDaemon = true
th.priority = Thread.MIN_PRIORITY
th
})
}
fun stop() {
networkWorker.shutdown()
}