refactor config loading and reloading more
This commit is contained in:
parent
0b5abf8a1e
commit
7c60477f53
|
@ -6,6 +6,7 @@ import matterlink.bridge.command.BridgeCommandRegistry
|
||||||
import matterlink.bridge.command.HelpCommand
|
import matterlink.bridge.command.HelpCommand
|
||||||
import matterlink.bridge.command.PlayerListCommand
|
import matterlink.bridge.command.PlayerListCommand
|
||||||
import matterlink.command.CommandMatterlink
|
import matterlink.command.CommandMatterlink
|
||||||
|
import matterlink.config.cfg
|
||||||
import net.minecraft.util.text.TextComponentString
|
import net.minecraft.util.text.TextComponentString
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler
|
import net.minecraftforge.fml.common.FMLCommonHandler
|
||||||
import net.minecraftforge.fml.common.Mod
|
import net.minecraftforge.fml.common.Mod
|
||||||
|
@ -37,7 +38,7 @@ object MatterLink : IMatterLink() {
|
||||||
logger = event.modLog
|
logger = event.modLog
|
||||||
logger.info("Building bridge!")
|
logger.info("Building bridge!")
|
||||||
|
|
||||||
MatterLinkConfig(event.suggestedConfigurationFile)
|
cfg = MatterLinkConfig(event.suggestedConfigurationFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
|
|
|
@ -5,7 +5,7 @@ import matterlink.config.cfg
|
||||||
import net.minecraftforge.common.config.Configuration
|
import net.minecraftforge.common.config.Configuration
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class MatterLinkConfig(file: File) : BaseConfig(file) {
|
class MatterLinkConfig(val file: File) : BaseConfig() {
|
||||||
init {
|
init {
|
||||||
logger.info("Reading bridge blueprints... from {}", file)
|
logger.info("Reading bridge blueprints... from {}", file)
|
||||||
val config = Configuration(file)
|
val config = Configuration(file)
|
||||||
|
@ -20,11 +20,7 @@ class MatterLinkConfig(file: File) : BaseConfig(file) {
|
||||||
)
|
)
|
||||||
|
|
||||||
if (config.hasChanged()) config.save()
|
if (config.hasChanged()) config.save()
|
||||||
|
|
||||||
cfg = this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun reload(file: File) {
|
override fun load() = MatterLinkConfig(file)
|
||||||
MatterLinkConfig(file)
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@ import matterlink.bridge.command.BridgeCommandRegistry
|
||||||
import matterlink.bridge.command.HelpCommand
|
import matterlink.bridge.command.HelpCommand
|
||||||
import matterlink.bridge.command.PlayerListCommand
|
import matterlink.bridge.command.PlayerListCommand
|
||||||
import matterlink.command.CommandMatterlink
|
import matterlink.command.CommandMatterlink
|
||||||
|
import matterlink.config.cfg
|
||||||
import net.minecraft.util.text.TextComponentString
|
import net.minecraft.util.text.TextComponentString
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler
|
import net.minecraftforge.fml.common.FMLCommonHandler
|
||||||
import net.minecraftforge.fml.common.Mod
|
import net.minecraftforge.fml.common.Mod
|
||||||
|
@ -37,7 +38,7 @@ object MatterLink : IMatterLink() {
|
||||||
logger = event.modLog
|
logger = event.modLog
|
||||||
logger.info("Building bridge!")
|
logger.info("Building bridge!")
|
||||||
|
|
||||||
MatterLinkConfig(event.suggestedConfigurationFile)
|
cfg = MatterLinkConfig(event.suggestedConfigurationFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
|
|
|
@ -5,7 +5,7 @@ import matterlink.config.cfg
|
||||||
import net.minecraftforge.common.config.Configuration
|
import net.minecraftforge.common.config.Configuration
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class MatterLinkConfig(file: File) : BaseConfig(file) {
|
class MatterLinkConfig(val file: File) : BaseConfig() {
|
||||||
init {
|
init {
|
||||||
logger.info("Reading bridge blueprints... from {}", file)
|
logger.info("Reading bridge blueprints... from {}", file)
|
||||||
val config = Configuration(file)
|
val config = Configuration(file)
|
||||||
|
@ -20,11 +20,7 @@ class MatterLinkConfig(file: File) : BaseConfig(file) {
|
||||||
)
|
)
|
||||||
|
|
||||||
if (config.hasChanged()) config.save()
|
if (config.hasChanged()) config.save()
|
||||||
|
|
||||||
cfg = this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun reload(file: File) {
|
override fun load() = MatterLinkConfig(file)
|
||||||
MatterLinkConfig(file)
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@ import matterlink.bridge.command.BridgeCommandRegistry
|
||||||
import matterlink.bridge.command.HelpCommand
|
import matterlink.bridge.command.HelpCommand
|
||||||
import matterlink.bridge.command.PlayerListCommand
|
import matterlink.bridge.command.PlayerListCommand
|
||||||
import matterlink.command.CommandMatterlink
|
import matterlink.command.CommandMatterlink
|
||||||
|
import matterlink.config.cfg
|
||||||
import net.minecraft.util.text.TextComponentString
|
import net.minecraft.util.text.TextComponentString
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler
|
import net.minecraftforge.fml.common.FMLCommonHandler
|
||||||
import net.minecraftforge.fml.common.Mod
|
import net.minecraftforge.fml.common.Mod
|
||||||
|
@ -36,7 +37,7 @@ object MatterLink : IMatterLink() {
|
||||||
logger = event.modLog
|
logger = event.modLog
|
||||||
logger.info("Building bridge!")
|
logger.info("Building bridge!")
|
||||||
|
|
||||||
MatterLinkConfig(event.suggestedConfigurationFile)
|
cfg = MatterLinkConfig(event.suggestedConfigurationFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
|
|
|
@ -5,7 +5,7 @@ import matterlink.config.cfg
|
||||||
import net.minecraftforge.common.config.Configuration
|
import net.minecraftforge.common.config.Configuration
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class MatterLinkConfig(file: File) : BaseConfig(file) {
|
class MatterLinkConfig(val file: File) : BaseConfig() {
|
||||||
init {
|
init {
|
||||||
logger.info("Reading bridge blueprints... from {}", file)
|
logger.info("Reading bridge blueprints... from {}", file)
|
||||||
val config = Configuration(file)
|
val config = Configuration(file)
|
||||||
|
@ -19,10 +19,7 @@ class MatterLinkConfig(file: File) : BaseConfig(file) {
|
||||||
addCustomCategoryComment = config::addCustomCategoryComment
|
addCustomCategoryComment = config::addCustomCategoryComment
|
||||||
)
|
)
|
||||||
if (config.hasChanged()) config.save()
|
if (config.hasChanged()) config.save()
|
||||||
cfg = this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun reload(file: File) {
|
override fun load() = MatterLinkConfig(file)
|
||||||
MatterLinkConfig(file)
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
package matterlink.command
|
package matterlink.command
|
||||||
|
|
||||||
import matterlink.bridge.MessageHandler
|
import matterlink.bridge.MessageHandler
|
||||||
import matterlink.config.BaseConfig
|
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
import matterlink.instance
|
import matterlink.instance
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ object CommandCore {
|
||||||
}
|
}
|
||||||
"reload" -> {
|
"reload" -> {
|
||||||
if (MessageHandler.connected) instance.disconnect()
|
if (MessageHandler.connected) instance.disconnect()
|
||||||
cfg!!.reload(cfg!!.file)
|
cfg = cfg!!.load()
|
||||||
if (!MessageHandler.connected) instance.connect()
|
if (!MessageHandler.connected) instance.connect()
|
||||||
"Bridge config reloaded!"
|
"Bridge config reloaded!"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package matterlink.config
|
package matterlink.config
|
||||||
|
|
||||||
import java.io.File
|
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
var cfg: BaseConfig? = null
|
var cfg: BaseConfig? = null
|
||||||
|
|
||||||
abstract class BaseConfig(val file : File) {
|
abstract class BaseConfig {
|
||||||
companion object {
|
companion object {
|
||||||
private val CATEGORY_RELAY_OPTIONS = "relay"
|
private val CATEGORY_RELAY_OPTIONS = "relay"
|
||||||
private val CATEGORY_FORMATTING_INCOMING = "formatting"
|
private val CATEGORY_FORMATTING_INCOMING = "formatting"
|
||||||
|
@ -14,9 +13,8 @@ abstract class BaseConfig(val file : File) {
|
||||||
private val CATEGORY_COMMAND = "command"
|
private val CATEGORY_COMMAND = "command"
|
||||||
private val CATEGORY_DEATH = "death"
|
private val CATEGORY_DEATH = "death"
|
||||||
|
|
||||||
@Deprecated("Use BaseConfig.loadConfig(file : File) instead")
|
|
||||||
fun reload() {
|
fun reload() {
|
||||||
cfg = cfg!!.javaClass.getConstructor(cfg!!.file.javaClass).newInstance(cfg!!.file)
|
cfg = cfg!!.load()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,5 +257,5 @@ abstract class BaseConfig(val file : File) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun reload(file : File)
|
abstract fun load(): BaseConfig
|
||||||
}
|
}
|
Loading…
Reference in New Issue