Skip to content

Commit

Permalink
exec module enable() after world join, if not called yet
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Dec 26, 2023
1 parent c52e6d8 commit 5e19cb1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/kotlin/net/ccbluex/liquidbounce/features/module/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import net.ccbluex.liquidbounce.config.Configurable
import net.ccbluex.liquidbounce.config.util.Exclude
import net.ccbluex.liquidbounce.event.EventManager
import net.ccbluex.liquidbounce.event.Listenable
import net.ccbluex.liquidbounce.event.events.NotificationEvent
import net.ccbluex.liquidbounce.event.events.RefreshArrayListEvent
import net.ccbluex.liquidbounce.event.events.ToggleModuleEvent
import net.ccbluex.liquidbounce.event.events.WorldDisconnectEvent
import net.ccbluex.liquidbounce.event.events.*
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.utils.client.*
import net.minecraft.client.MinecraftClient
Expand Down Expand Up @@ -60,13 +57,17 @@ open class Module(
}
}.notAnOption()

private var calledSinceStartup = false

// Module options
var enabled by valueEnabled.listen { new ->
runCatching {
if (!inGame) {
return@runCatching
}

calledSinceStartup = true

// Call enable or disable function
if (new) {
enable()
Expand Down Expand Up @@ -162,6 +163,12 @@ open class Module(
}
}

val onWorldChange = handler<WorldChangeEvent>(ignoreCondition = true) {
if (enabled && !calledSinceStartup && it.world != null) {
calledSinceStartup = true
enable()
}
}

protected fun choices(name: String, active: Choice, choices: Array<Choice>) =
choices(this, name, active, choices)
Expand Down

0 comments on commit 5e19cb1

Please sign in to comment.