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)