From ef8172b68b21ac7d1beff0c3e1ed0152319f0e87 Mon Sep 17 00:00:00 2001 From: way-zer Date: Sun, 4 Aug 2024 14:44:03 +0800 Subject: [PATCH] fix init in server. --- .../cf/wayzer/contentsTweaker/CTNode.kt | 2 +- .../wayzer/contentsTweaker/ContentsTweaker.kt | 1 + .../cf/wayzer/contentsTweaker/ModMain.kt | 20 ++++++++++--------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/cf/wayzer/contentsTweaker/CTNode.kt b/src/main/kotlin/cf/wayzer/contentsTweaker/CTNode.kt index 5514d3c..fa30683 100644 --- a/src/main/kotlin/cf/wayzer/contentsTweaker/CTNode.kt +++ b/src/main/kotlin/cf/wayzer/contentsTweaker/CTNode.kt @@ -162,7 +162,7 @@ class CTNode private constructor() : ExtendableClass() { } val resetHandlers = mutableSetOf() - private val afterHandlers = mutableSetOf() + internal val afterHandlers = mutableSetOf() fun modified(modifiable: Modifiable<*>) { resetHandlers.add(modifiable) diff --git a/src/main/kotlin/cf/wayzer/contentsTweaker/ContentsTweaker.kt b/src/main/kotlin/cf/wayzer/contentsTweaker/ContentsTweaker.kt index 14f2d25..3bcc05f 100644 --- a/src/main/kotlin/cf/wayzer/contentsTweaker/ContentsTweaker.kt +++ b/src/main/kotlin/cf/wayzer/contentsTweaker/ContentsTweaker.kt @@ -34,6 +34,7 @@ object ContentsTweaker { ) fun afterHandle() { + if (CTNode.PatchHandler.afterHandlers.isEmpty()) return val time = measureTimeMillis { CTNode.PatchHandler.doAfterHandle() } diff --git a/src/main/kotlin/cf/wayzer/contentsTweaker/ModMain.kt b/src/main/kotlin/cf/wayzer/contentsTweaker/ModMain.kt index 44abf71..9d47814 100644 --- a/src/main/kotlin/cf/wayzer/contentsTweaker/ModMain.kt +++ b/src/main/kotlin/cf/wayzer/contentsTweaker/ModMain.kt @@ -33,15 +33,17 @@ class ModMain : Mod() { } ContentsTweaker.afterHandle() } - Vars.netClient.addPacketHandler("ContentsLoader|newPatch") { - val (name, content) = it.split('\n', limit = 2) - ContentsTweaker.loadPatch(name, content) - } - //TODO: Deprecated - Vars.netClient.addPacketHandler("ContentsLoader|loadPatch") { name -> - val patch = Vars.state.map.tags.get("CT@$name") - ?: return@addPacketHandler Call.serverPacketReliable("ContentsLoader|requestPatch", name) - ContentsTweaker.loadPatch(name, patch) + if (Vars.netClient != null) { + Vars.netClient.addPacketHandler("ContentsLoader|newPatch") { + val (name, content) = it.split('\n', limit = 2) + ContentsTweaker.loadPatch(name, content) + } + //TODO: Deprecated + Vars.netClient.addPacketHandler("ContentsLoader|loadPatch") { name -> + val patch = Vars.state.map.tags.get("CT@$name") + ?: return@addPacketHandler Call.serverPacketReliable("ContentsLoader|requestPatch", name) + ContentsTweaker.loadPatch(name, patch) + } } Vars.mods.scripts.scope.apply { put("CT", this, ContentsTweaker)