Skip to content

Commit

Permalink
cleanup: Remove ConfigBased from PaperEngineModule and use idofront D…
Browse files Browse the repository at this point in the history
…I for logger
  • Loading branch information
0ffz committed Mar 16, 2024
1 parent 66c11ac commit 3ec271e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package com.mineinabyss.geary.papermc

import com.mineinabyss.idofront.config.config
import com.mineinabyss.idofront.messaging.ComponentLogger
import com.mineinabyss.idofront.messaging.injectLogger
import com.mineinabyss.idofront.messaging.observeLogger
import com.mineinabyss.idofront.plugin.dataPath
import org.bukkit.plugin.java.JavaPlugin

class GearyProductionPaperConfigModule(
override val plugin: JavaPlugin,
) : GearyPaperConfigModule {
override val configHolder = config("config", plugin.dataFolder.toPath(), GearyPaperConfig())
override val configHolder = config(
"config", plugin.dataPath, GearyPaperConfig(),
onLoad = {
plugin.injectLogger(ComponentLogger.forPlugin(plugin, minSeverity = it.logLevel))
}
)

override val config: GearyPaperConfig by configHolder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,17 @@ import com.mineinabyss.geary.engine.archetypes.operations.ArchetypeReadOperation
import com.mineinabyss.geary.modules.ArchetypeEngineModule
import com.mineinabyss.geary.modules.GearyModuleProvider
import com.mineinabyss.geary.papermc.Catching.Companion.asyncCheck
import com.mineinabyss.geary.papermc.GearyPaperConfig
import com.mineinabyss.geary.papermc.GearyPlugin
import com.mineinabyss.geary.papermc.gearyPaper
import com.mineinabyss.idofront.di.DI
import com.mineinabyss.idofront.messaging.ComponentLogger
import com.mineinabyss.idofront.messaging.injectLogger
import com.mineinabyss.idofront.messaging.observeLogger
import com.mineinabyss.idofront.time.ticks

class ConfigBased(
config: GearyPaperConfig,
plugin: GearyPlugin,
) {
val logger = ComponentLogger.forPlugin(plugin, minSeverity = config.logLevel)
}

class PaperEngineModule(
val plugin: GearyPlugin
) : ArchetypeEngineModule(tickDuration = 1.ticks) {
private var configBased = updateToMatch(gearyPaper.config)

override val engine: ArchetypeEngine = PaperMCEngine()
override val logger get() = configBased.logger
override val logger by plugin.observeLogger()

override val entityProvider: EntityByArchetypeProvider
get() {
Expand Down Expand Up @@ -64,13 +53,6 @@ class PaperEngineModule(
return super.archetypeProvider
}

fun updateToMatch(config: GearyPaperConfig): ConfigBased {
val configBased = ConfigBased(config, plugin)
this.configBased = configBased
plugin.injectLogger(logger)
return configBased
}

companion object : GearyModuleProvider<PaperEngineModule> {
override fun start(module: PaperEngineModule) {
DI.add<PaperEngineModule>(module)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.mineinabyss.geary.papermc.plugin.commands

import com.mineinabyss.geary.papermc.gearyPaper
import com.mineinabyss.geary.papermc.plugin.PaperEngineModule
import com.mineinabyss.geary.prefabs.prefabs
import com.mineinabyss.idofront.commands.Command
import com.mineinabyss.idofront.di.DI

private val prefabLoader get() = prefabs.loader

fun Command.reload() {
"reload" {
action {
gearyPaper.configHolder.reload()
DI.get<PaperEngineModule>().updateToMatch(gearyPaper.config)
prefabLoader.loadOrUpdatePrefabs()
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kotlin.code.style=official
group=com.mineinabyss
version=0.29
idofrontVersion=0.23.0-dev.7
idofrontVersion=0.23.0-dev.10
gearyVersion=0.26.0-dev.3

0 comments on commit 3ec271e

Please sign in to comment.