Skip to content

Commit

Permalink
object
Browse files Browse the repository at this point in the history
  • Loading branch information
powercasgamer committed Dec 2, 2023
1 parent 0dc09c3 commit ea03d8e
Showing 1 changed file with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,30 @@ import org.spongepowered.configurate.yaml.YamlConfigurationLoader
import java.nio.file.Path
import kotlin.io.path.exists

class ConfigManager {
object ConfigManager {

companion object {

fun loadConfig(path: Path): Config {
val configLoader = YamlConfigurationLoader.builder()
.path(path)
.nodeStyle(NodeStyle.BLOCK)
.indent(2)
.defaultOptions { options ->
options.shouldCopyDefaults(true)
options.serializers { builder ->
builder.registerAnnotatedObjects(objectMapperFactory())
}
fun loadConfig(path: Path): Config {
val configLoader = YamlConfigurationLoader.builder()
.path(path)
.nodeStyle(NodeStyle.BLOCK)
.indent(2)
.defaultOptions { options ->
options.shouldCopyDefaults(true)
options.serializers { builder ->
builder.registerAnnotatedObjects(objectMapperFactory())
}
.build()
var configNode = configLoader.load()
var config = requireNotNull(configNode.get<Config>()) {
"Could not read configuration"
}

if (!path.exists()) {
configNode.set(config) // update the backing node to add defaults
configLoader.save(configNode)
}
.build()
var configNode = configLoader.load()
var config = requireNotNull(configNode.get<Config>()) {
"Could not read configuration"
}

return config
if (!path.exists()) {
configNode.set(config) // update the backing node to add defaults
configLoader.save(configNode)
}

return config
}
}

0 comments on commit ea03d8e

Please sign in to comment.