switch main config to hjson
This commit is contained in:
parent
6af52cc58e
commit
5eb79935ba
|
@ -2,6 +2,7 @@ package matterlink
|
|||
|
||||
import matterlink.command.CommandMatterlink
|
||||
import matterlink.command.MatterLinkCommandSender
|
||||
import matterlink.config.BaseConfig
|
||||
import matterlink.config.cfg
|
||||
import net.minecraft.util.text.TextComponentString
|
||||
import net.minecraftforge.common.ForgeVersion
|
||||
|
@ -35,7 +36,7 @@ object MatterLink : IMatterLink() {
|
|||
logger = event.modLog
|
||||
logger.info("Building bridge!")
|
||||
|
||||
cfg = MatterLinkConfig(event.modConfigurationDirectory)
|
||||
cfg = BaseConfig(event.modConfigurationDirectory).load()
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package matterlink
|
||||
|
||||
import matterlink.config.BaseConfig
|
||||
import net.minecraftforge.common.config.Configuration
|
||||
import java.io.File
|
||||
|
||||
class MatterLinkConfig(val baseCfgDir: File) : BaseConfig(baseCfgDir) {
|
||||
init {
|
||||
logger.info("Reading bridge blueprints... from {}", cfgDirectory)
|
||||
val config = Configuration(mainCfgFile)
|
||||
|
||||
load(
|
||||
getBoolean = config::getBoolean,
|
||||
getString = config::getString,
|
||||
getStringValidated = config::getString,
|
||||
getStringValidValues = config::getString,
|
||||
getStringList = config::getStringList,
|
||||
addCustomCategoryComment = config::addCustomCategoryComment
|
||||
)
|
||||
if (config.hasChanged()) config.save()
|
||||
}
|
||||
|
||||
override fun load() = MatterLinkConfig(baseCfgDir)
|
||||
}
|
|
@ -2,6 +2,7 @@ package matterlink
|
|||
|
||||
import matterlink.command.CommandMatterlink
|
||||
import matterlink.command.MatterLinkCommandSender
|
||||
import matterlink.config.BaseConfig
|
||||
import matterlink.config.cfg
|
||||
import net.minecraft.util.text.TextComponentString
|
||||
import net.minecraftforge.common.ForgeVersion
|
||||
|
@ -35,7 +36,7 @@ object MatterLink : IMatterLink() {
|
|||
logger = event.modLog
|
||||
logger.info("Building bridge!")
|
||||
|
||||
cfg = MatterLinkConfig(event.modConfigurationDirectory)
|
||||
cfg = BaseConfig(event.modConfigurationDirectory).load()
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package matterlink
|
||||
|
||||
import matterlink.config.BaseConfig
|
||||
import net.minecraftforge.common.config.Configuration
|
||||
import java.io.File
|
||||
|
||||
class MatterLinkConfig(val baseCfgDir: File) : BaseConfig(baseCfgDir) {
|
||||
init {
|
||||
logger.info("Reading bridge blueprints... from {}", cfgDirectory)
|
||||
val config = Configuration(mainCfgFile)
|
||||
|
||||
load(
|
||||
getBoolean = config::getBoolean,
|
||||
getString = config::getString,
|
||||
getStringValidated = config::getString,
|
||||
getStringValidValues = config::getString,
|
||||
getStringList = config::getStringList,
|
||||
addCustomCategoryComment = config::addCustomCategoryComment
|
||||
)
|
||||
if (config.hasChanged()) config.save()
|
||||
}
|
||||
|
||||
override fun load() = MatterLinkConfig(baseCfgDir)
|
||||
}
|
|
@ -2,12 +2,16 @@ package matterlink
|
|||
|
||||
import matterlink.command.CommandMatterlink
|
||||
import matterlink.command.MatterLinkCommandSender
|
||||
import matterlink.config.BaseConfig
|
||||
import matterlink.config.cfg
|
||||
import net.minecraft.util.text.TextComponentString
|
||||
import net.minecraftforge.common.ForgeVersion
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler
|
||||
import net.minecraftforge.fml.common.Mod
|
||||
import net.minecraftforge.fml.common.event.*
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
|
||||
import net.minecraftforge.fml.common.event.FMLServerStartingEvent
|
||||
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent
|
||||
import org.apache.logging.log4j.Level
|
||||
import org.apache.logging.log4j.Logger
|
||||
|
||||
|
@ -32,7 +36,7 @@ object MatterLink : IMatterLink() {
|
|||
logger = event.modLog
|
||||
logger.info("Building bridge!")
|
||||
|
||||
cfg = MatterLinkConfig(event.modConfigurationDirectory)
|
||||
cfg = BaseConfig(event.modConfigurationDirectory).load()
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
@ -40,11 +44,6 @@ object MatterLink : IMatterLink() {
|
|||
this.registerBridgeCommands()
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
fun serverAboutToStart(event: FMLServerAboutToStartEvent) {
|
||||
// MessageHandlerInst.start(clear = true)
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
fun serverStarting(event: FMLServerStartingEvent) {
|
||||
log("DEBUG", "Registering server commands")
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package matterlink
|
||||
|
||||
import matterlink.config.BaseConfig
|
||||
import net.minecraftforge.common.config.Configuration
|
||||
import java.io.File
|
||||
|
||||
class MatterLinkConfig(val baseCfgDir: File) : BaseConfig(baseCfgDir) {
|
||||
init {
|
||||
logger.info("Reading bridge blueprints... from {}", cfgDirectory)
|
||||
val config = Configuration(mainCfgFile)
|
||||
|
||||
load(
|
||||
getBoolean = config::getBoolean,
|
||||
getString = config::getString,
|
||||
getStringValidated = config::getString,
|
||||
getStringValidValues = config::getString,
|
||||
getStringList = config::getStringList,
|
||||
addCustomCategoryComment = config::addCustomCategoryComment
|
||||
)
|
||||
if (config.hasChanged()) config.save()
|
||||
}
|
||||
|
||||
override fun load() = MatterLinkConfig(baseCfgDir)
|
||||
}
|
|
@ -8,6 +8,7 @@ import cpw.mods.fml.common.event.FMLServerStartingEvent
|
|||
import cpw.mods.fml.common.event.FMLServerStoppingEvent
|
||||
import matterlink.command.CommandMatterlink
|
||||
import matterlink.command.MatterLinkCommandSender
|
||||
import matterlink.config.BaseConfig
|
||||
import matterlink.config.cfg
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.util.ChatComponentText
|
||||
|
@ -37,7 +38,7 @@ class MatterLink : IMatterLink() {
|
|||
logger = event.modLog
|
||||
logger.info("Building bridge!")
|
||||
|
||||
cfg = MatterLinkConfig(event.modConfigurationDirectory)
|
||||
cfg = BaseConfig(event.modConfigurationDirectory).load()
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package matterlink
|
||||
|
||||
import matterlink.config.BaseConfig
|
||||
import net.minecraftforge.common.config.Configuration
|
||||
import java.io.File
|
||||
|
||||
class MatterLinkConfig(val baseCfgDir: File) : BaseConfig(baseCfgDir) {
|
||||
init {
|
||||
logger.info("Reading bridge blueprints... from {}", cfgDirectory)
|
||||
val config = Configuration(mainCfgFile)
|
||||
|
||||
load(
|
||||
getBoolean = config::getBoolean,
|
||||
getString = config::getString,
|
||||
getStringValidated = config::getString,
|
||||
getStringValidValues = config::getString,
|
||||
getStringList = config::getStringList,
|
||||
addCustomCategoryComment = config::addCustomCategoryComment
|
||||
)
|
||||
if (config.hasChanged()) config.save()
|
||||
}
|
||||
|
||||
override fun load() = MatterLinkConfig(baseCfgDir)
|
||||
}
|
2
Jankson
2
Jankson
|
@ -1 +1 @@
|
|||
Subproject commit ce97d00016a58a4402d919155efa0fccec5ea9e6
|
||||
Subproject commit 90b600e2acdbba48a9a3c39d85a49a9ec24e8db1
|
|
@ -1,5 +1,6 @@
|
|||
package matterlink
|
||||
|
||||
import blue.endless.jankson.JsonObject
|
||||
import matterlink.config.cfg
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
|
@ -53,4 +54,9 @@ val Exception.stackTraceString: String
|
|||
val sw = StringWriter()
|
||||
this.printStackTrace(PrintWriter(sw))
|
||||
return sw.toString()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> JsonObject.getOrDefault(key: String, default: T, comment: String? = null): T {
|
||||
instance.info("type: ${T::class.java.name} key: $key default: $default")
|
||||
return putDefault(key, default, comment)!!
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ object BridgeCommandRegistry {
|
|||
fun handleCommand(input: ApiMessage): Boolean {
|
||||
if (!cfg.command.enable || input.text.isBlank()) return false
|
||||
|
||||
if (input.text[0] != cfg.command.prefix[0] || input.text.length < 2) return false
|
||||
if (input.text[0] != cfg.command.prefix || input.text.length < 2) return false
|
||||
|
||||
val cmd = input.text.substring(1).split(' ', ignoreCase = false, limit = 2)
|
||||
val args = if (cmd.size == 2) cmd[1] else ""
|
||||
|
|
|
@ -2,6 +2,7 @@ package matterlink.command
|
|||
|
||||
import matterlink.bridge.MessageHandlerInst
|
||||
import matterlink.bridge.command.BridgeCommandRegistry
|
||||
import matterlink.config.baseCfg
|
||||
import matterlink.config.cfg
|
||||
|
||||
object CommandCore {
|
||||
|
@ -26,7 +27,7 @@ object CommandCore {
|
|||
"reload" -> {
|
||||
// if (MessageHandlerInst.connected)
|
||||
MessageHandlerInst.stop("Bridge restarting (reload command issued by console)")
|
||||
cfg = cfg.load()
|
||||
cfg = baseCfg.load()
|
||||
BridgeCommandRegistry.reloadCommands()
|
||||
// if (!MessageHandlerInst.connected)
|
||||
MessageHandlerInst.start("Bridge reconnected", false)
|
||||
|
|
|
@ -1,26 +1,40 @@
|
|||
package matterlink.config
|
||||
|
||||
import blue.endless.jankson.Jankson
|
||||
import blue.endless.jankson.JsonObject
|
||||
import blue.endless.jankson.impl.Marshaller
|
||||
import blue.endless.jankson.impl.SyntaxError
|
||||
import matterlink.bridge.MessageHandlerInst
|
||||
import matterlink.getOrDefault
|
||||
import matterlink.instance
|
||||
import matterlink.stackTraceString
|
||||
import java.io.File
|
||||
import java.util.regex.Pattern
|
||||
import java.io.FileNotFoundException
|
||||
|
||||
lateinit var cfg: BaseConfig
|
||||
lateinit var cfg: BaseConfig.MatterLinkConfig
|
||||
lateinit var baseCfg: BaseConfig
|
||||
|
||||
abstract class BaseConfig(rootDir: File) {
|
||||
data class BaseConfig(val rootDir: File) {
|
||||
val cfgDirectory: File = rootDir.resolve("matterlink")
|
||||
val mainCfgFile: File = cfgDirectory.resolve("matterlink.cfg")
|
||||
val configFile: File = cfgDirectory.resolve("matterlink.hjson")
|
||||
|
||||
init {
|
||||
instance.info("Reading bridge blueprints... from {}", rootDir)
|
||||
baseCfg = this
|
||||
}
|
||||
|
||||
var connect = ConnectOptions()
|
||||
var debug = DebugOptions()
|
||||
var incoming = IncomingOption()
|
||||
var outgoing = OutgoingOptions()
|
||||
var command = CommandOptions()
|
||||
var update = UpdateOptions()
|
||||
data class MatterLinkConfig(
|
||||
val connect: ConnectOptions = ConnectOptions(),
|
||||
val debug: DebugOptions = DebugOptions(),
|
||||
val incoming: IncomingOptions = IncomingOptions(),
|
||||
val outgoing: OutgoingOptions = OutgoingOptions(),
|
||||
val command: CommandOptions = CommandOptions(),
|
||||
val update: UpdateOptions = UpdateOptions()
|
||||
)
|
||||
|
||||
|
||||
data class CommandOptions(
|
||||
val prefix: String = "!",
|
||||
val prefix: Char = '!',
|
||||
val enable: Boolean = true
|
||||
)
|
||||
|
||||
|
@ -36,10 +50,10 @@ abstract class BaseConfig(rootDir: File) {
|
|||
var logLevel: String = "INFO"
|
||||
)
|
||||
|
||||
data class IncomingOption(
|
||||
data class IncomingOptions(
|
||||
val chat: String = "<{username}> {text}",
|
||||
val joinPart: String = "§6-- {username} {text}",
|
||||
val action: String = "§5* {username} {text}",
|
||||
val joinPart: String = "",//"§6-- {username} {text}",
|
||||
val action: String = "",//"§5* {username} {text}",
|
||||
var stripColors: Boolean = true
|
||||
)
|
||||
|
||||
|
@ -58,36 +72,36 @@ abstract class BaseConfig(rootDir: File) {
|
|||
data class DeathOptions(
|
||||
val enable: Boolean = true,
|
||||
val damageType: Boolean = true,
|
||||
val damageTypeMapping: Map<String, String> = mapOf(
|
||||
"inFire" to "\uD83D\uDD25", //🔥
|
||||
"lightningBolt" to "\uD83C\uDF29", //🌩
|
||||
"onFire" to "\uD83D\uDD25", //🔥
|
||||
"lava" to "\uD83D\uDD25", //🔥
|
||||
"hotFloor" to "♨️",
|
||||
"inWall" to "",
|
||||
"cramming" to "",
|
||||
"drown" to "\uD83C\uDF0A", //🌊
|
||||
"starve" to "\uD83D\uDC80", //💀
|
||||
"cactus" to "\uD83C\uDF35", //🌵
|
||||
"fall" to "\u2BEF️", //⯯️
|
||||
"flyIntoWall" to "\uD83D\uDCA8", //💨
|
||||
"outOfWorld" to "\u2734", //✴
|
||||
"generic" to "\uD83D\uDC7B", //👻
|
||||
"magic" to "✨ ⚚",
|
||||
"indirectMagic" to "✨ ⚚",
|
||||
"wither" to "\uD83D\uDD71", //🕱
|
||||
"anvil" to "",
|
||||
"fallingBlock" to "",
|
||||
"dragonBreath" to "\uD83D\uDC32", //🐲
|
||||
"fireworks" to "\uD83C\uDF86", //🎆
|
||||
val damageTypeMapping: Map<String, Array<String>> = mapOf(
|
||||
"inFire" to arrayOf("\uD83D\uDD25"), //🔥
|
||||
"lightningBolt" to arrayOf("\uD83C\uDF29"), //🌩
|
||||
"onFire" to arrayOf("\uD83D\uDD25"), //🔥
|
||||
"lava" to arrayOf("\uD83D\uDD25"), //🔥
|
||||
"hotFloor" to arrayOf("♨️"),
|
||||
"inWall" to arrayOf(),
|
||||
"cramming" to arrayOf(),
|
||||
"drown" to arrayOf("\uD83C\uDF0A"), //🌊
|
||||
"starve" to arrayOf("\uD83D\uDC80"), //💀
|
||||
"cactus" to arrayOf("\uD83C\uDF35"), //🌵
|
||||
"fall" to arrayOf("\u2BEF️"), //⯯️
|
||||
"flyIntoWall" to arrayOf("\uD83D\uDCA8"), //💨
|
||||
"outOfWorld" to arrayOf("\u2734"), //✴
|
||||
"generic" to arrayOf("\uD83D\uDC7B"), //👻
|
||||
"magic" to arrayOf("✨ ⚚"),
|
||||
"indirectMagic" to arrayOf("✨ ⚚"),
|
||||
"wither" to arrayOf("\uD83D\uDD71"), //🕱
|
||||
"anvil" to arrayOf(),
|
||||
"fallingBlock" to arrayOf(),
|
||||
"dragonBreath" to arrayOf("\uD83D\uDC32"), //🐲
|
||||
"fireworks" to arrayOf("\uD83C\uDF86"), //🎆
|
||||
|
||||
"mob" to "\uD83D\uDC80", //💀
|
||||
"player" to "\uD83D\uDDE1", //🗡
|
||||
"arrow" to "\uD83C\uDFF9", //🏹
|
||||
"thrown" to "彡°",
|
||||
"thorns" to "\uD83C\uDF39", //🌹
|
||||
"explosion" to "\uD83D\uDCA3 \uD83D\uDCA5", //💣 💥
|
||||
"explosion.player" to "\uD83D\uDCA3 \uD83D\uDCA5" //💣 💥
|
||||
"mob" to arrayOf("\uD83D\uDC80"), //💀
|
||||
"player" to arrayOf("\uD83D\uDDE1"), //🗡
|
||||
"arrow" to arrayOf("\uD83C\uDFF9"), //🏹
|
||||
"thrown" to arrayOf("彡°"),
|
||||
"thorns" to arrayOf("\uD83C\uDF39"), //🌹
|
||||
"explosion" to arrayOf("\uD83D\uDCA3", "\uD83D\uDCA5"), //💣 💥
|
||||
"explosion.player" to arrayOf("\uD83D\uDCA3", "\uD83D\uDCA5") //💣 💥
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -101,228 +115,279 @@ abstract class BaseConfig(rootDir: File) {
|
|||
val enable: Boolean = true
|
||||
)
|
||||
|
||||
protected fun load(
|
||||
getBoolean: (key: String, category: String, default: Boolean, comment: String) -> Boolean,
|
||||
getString: (key: String, category: String, default: String, comment: String) -> String,
|
||||
getStringValidated: (key: String, category: String, default: String, comment: String, pattern: Pattern) -> String,
|
||||
getStringValidValues: (key: String, category: String, default: String, comment: String, validValues: Array<String>) -> String,
|
||||
getStringList: (name: String, category: String, defaultValues: Array<String>, comment: String) -> Array<String>,
|
||||
addCustomCategoryComment: (key: String, comment: String) -> Unit
|
||||
) {
|
||||
|
||||
var category = "commands"
|
||||
|
||||
addCustomCategoryComment(category, "User commands")
|
||||
command = CommandOptions(
|
||||
enable = getBoolean(
|
||||
"enable",
|
||||
category,
|
||||
command.enable,
|
||||
"Enable MC bridge commands"
|
||||
),
|
||||
prefix = getStringValidated(
|
||||
"prefix",
|
||||
category,
|
||||
command.prefix,
|
||||
"Prefix for MC bridge commands. Accepts a single character (not alphanumeric or /)",
|
||||
Pattern.compile("^[^0-9A-Za-z/]$")
|
||||
)
|
||||
)
|
||||
|
||||
category = "connection"
|
||||
addCustomCategoryComment(category, "Connection settings")
|
||||
connect = ConnectOptions(
|
||||
url = getString(
|
||||
"connectURL",
|
||||
category,
|
||||
connect.url,
|
||||
"The URL or IP address of the bridge server"
|
||||
),
|
||||
authToken = getString(
|
||||
"authToken",
|
||||
category,
|
||||
connect.authToken,
|
||||
"Auth token used to connect to the bridge server"
|
||||
),
|
||||
gateway = getString(
|
||||
"gateway",
|
||||
category,
|
||||
connect.gateway,
|
||||
"MatterBridge gateway"
|
||||
),
|
||||
autoConnect = getBoolean(
|
||||
"autoConnect",
|
||||
category,
|
||||
connect.autoConnect,
|
||||
"Connect the relay on startup"
|
||||
)
|
||||
)
|
||||
|
||||
category = "debug"
|
||||
addCustomCategoryComment(category, "Options to help you figure out what happens and why, because computers can be silly")
|
||||
debug = DebugOptions(
|
||||
logLevel = getStringValidValues(
|
||||
"logLevel",
|
||||
category,
|
||||
debug.logLevel,
|
||||
"MatterLink log level",
|
||||
arrayOf("INFO", "DEBUG", "TRACE")
|
||||
)
|
||||
)
|
||||
|
||||
category = "incoming"
|
||||
addCustomCategoryComment(category, "Gateway -> Server" +
|
||||
"\nOptions all about receiving messages from the API" +
|
||||
"\nFormatting options: " +
|
||||
"\nAvailable variables: {username}, {text}, {gateway}, {channel}, {protocol}, {username:antiping}")
|
||||
incoming = IncomingOption(
|
||||
chat = getString(
|
||||
"chat",
|
||||
category,
|
||||
incoming.chat,
|
||||
"Generic chat event, just talking"
|
||||
),
|
||||
joinPart = getString(
|
||||
"joinPart",
|
||||
category,
|
||||
incoming.joinPart,
|
||||
"Join and part events from other gateways"
|
||||
),
|
||||
action = getString(
|
||||
"action",
|
||||
category,
|
||||
incoming.action,
|
||||
"User actions (/me) sent by users from other gateways"
|
||||
),
|
||||
stripColors = getBoolean(
|
||||
"stripColors",
|
||||
category,
|
||||
incoming.stripColors,
|
||||
"strip colors from incoming text"
|
||||
)
|
||||
)
|
||||
|
||||
category = "outgoing"
|
||||
addCustomCategoryComment(category, "Server -> Gateway" +
|
||||
"\nOptions all about sending messages to the API")
|
||||
|
||||
outgoing = OutgoingOptions(
|
||||
systemUser = getString(
|
||||
"systemUser",
|
||||
category,
|
||||
outgoing.systemUser,
|
||||
"Name of the server user (used by death and advancement messages and the /say command)"
|
||||
),
|
||||
//outgoing events toggle
|
||||
advancements = getBoolean(
|
||||
"advancements",
|
||||
category,
|
||||
outgoing.advancements,
|
||||
"Relay player achievements / advancements"
|
||||
),
|
||||
announceConnect = getBoolean(
|
||||
"announceConnect",
|
||||
category,
|
||||
outgoing.announceConnect,
|
||||
"announce successful connection to the gateway"
|
||||
),
|
||||
announceDisconnect = getBoolean(
|
||||
"announceDisconnect",
|
||||
category,
|
||||
outgoing.announceConnect,
|
||||
"announce intention to disconnect / reconnect"
|
||||
),
|
||||
stripColors = getBoolean(
|
||||
"stripColors",
|
||||
category,
|
||||
outgoing.stripColors,
|
||||
"strip colors from nicknames and messages"
|
||||
)
|
||||
)
|
||||
|
||||
category = "outgoing.death"
|
||||
addCustomCategoryComment(category, "Death messages settings")
|
||||
outgoing.death = DeathOptions(
|
||||
|
||||
enable = getBoolean(
|
||||
"enable",
|
||||
category,
|
||||
outgoing.death.enable,
|
||||
"Relay player death messages"
|
||||
),
|
||||
damageType = getBoolean(
|
||||
"damageType",
|
||||
category,
|
||||
outgoing.death.damageType,
|
||||
"Enable Damage type symbols on death messages"
|
||||
),
|
||||
damageTypeMapping = getStringList(
|
||||
"damageTypeMapping",
|
||||
category,
|
||||
outgoing.death.damageTypeMapping.map { entry ->
|
||||
"${entry.key}=${entry.value}"
|
||||
}
|
||||
.toTypedArray(),
|
||||
"Damage type mapping for death cause, " +
|
||||
"\nseparate value and key with '=', " +
|
||||
"\nseparate multiple values with spaces\n"
|
||||
).associate {
|
||||
val key = it.substringBefore('=')
|
||||
val value = it.substringAfter('=')
|
||||
Pair(key, value)
|
||||
companion object {
|
||||
val jankson = Jankson
|
||||
.builder()
|
||||
.registerTypeAdapter(MatterLinkConfig::class.java) {
|
||||
MatterLinkConfig(
|
||||
command = it.getOrDefault(
|
||||
"command",
|
||||
CommandOptions(),
|
||||
"User commands"
|
||||
),
|
||||
connect = it.getOrDefault(
|
||||
"connect",
|
||||
ConnectOptions(),
|
||||
"Connection Settings"
|
||||
),
|
||||
debug = it.getOrDefault(
|
||||
"debug",
|
||||
DebugOptions(),
|
||||
"Options to help you figure out what happens and why, because computers can be silly"
|
||||
),
|
||||
incoming = it.getOrDefault(
|
||||
"incoming",
|
||||
IncomingOptions(),
|
||||
"""
|
||||
Gateway -> Server
|
||||
Options all about receiving messages from the API
|
||||
Formatting options:
|
||||
Available variables: {username}, {text}, {gateway}, {channel}, {protocol}, {username:antiping}
|
||||
""".trimIndent()
|
||||
),
|
||||
outgoing = it.getOrDefault(
|
||||
"outgoing",
|
||||
OutgoingOptions(),
|
||||
"""
|
||||
Server -> Gateway
|
||||
Options all about sending messages to the API
|
||||
""".trimIndent()
|
||||
),
|
||||
update = it.getOrDefault(
|
||||
"update",
|
||||
UpdateOptions(),
|
||||
"Update Settings"
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
category = "outgoing.join&part"
|
||||
addCustomCategoryComment(category, "relay join and part messages to the gatway" +
|
||||
"\nFormatting options: " +
|
||||
"\nAvailable variables: {username}, {username:antiping}")
|
||||
outgoing.joinPart = JoinPartOptions(
|
||||
enable = getBoolean(
|
||||
"enable",
|
||||
category,
|
||||
outgoing.joinPart.enable,
|
||||
"Relay when a player joins / parts the game" +
|
||||
"\nany receiving end still needs to be configured with showJoinPart = true" +
|
||||
"\nto display the messages"
|
||||
),
|
||||
joinServer = getString(
|
||||
"joinServer",
|
||||
category,
|
||||
outgoing.joinPart.joinServer,
|
||||
"user join message sent to other gateways, available variables: {username}, {username:antiping}"
|
||||
),
|
||||
partServer = getString(
|
||||
"partServer",
|
||||
category,
|
||||
outgoing.joinPart.partServer,
|
||||
"user part message sent to other gateways, available variables: {username}, {username:antiping}"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
category = "update"
|
||||
addCustomCategoryComment(category, "Update Settings")
|
||||
update = UpdateOptions(
|
||||
enable = getBoolean(
|
||||
"enable",
|
||||
category,
|
||||
update.enable,
|
||||
"Enable Update checking"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
MessageHandlerInst.config.url = connect.url
|
||||
MessageHandlerInst.config.token = connect.authToken
|
||||
MessageHandlerInst.config.gateway = connect.gateway
|
||||
MessageHandlerInst.config.reconnectWait = connect.reconnectWait
|
||||
|
||||
MessageHandlerInst.config.systemUser = outgoing.systemUser
|
||||
MessageHandlerInst.config.announceConnect = outgoing.announceConnect
|
||||
MessageHandlerInst.config.announceDisconnect = outgoing.announceDisconnect
|
||||
.registerTypeAdapter(CommandOptions::class.java) {
|
||||
with(CommandOptions()) {
|
||||
CommandOptions(
|
||||
enable = it.getOrDefault(
|
||||
"enable",
|
||||
enable,
|
||||
"Enable MC bridge commands"
|
||||
),
|
||||
prefix = it.getOrDefault(
|
||||
"prefix",
|
||||
prefix,
|
||||
"Prefix for MC bridge commands. Accepts a single character (not alphanumeric or /)"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
.registerTypeAdapter(ConnectOptions::class.java) {
|
||||
with(ConnectOptions()) {
|
||||
ConnectOptions(
|
||||
url = it.getOrDefault(
|
||||
"url",
|
||||
url,
|
||||
"The URL or IP address of the bridge server"
|
||||
),
|
||||
authToken = it.getOrDefault(
|
||||
"authToken",
|
||||
authToken,
|
||||
"Auth token used to connect to the bridge server"
|
||||
),
|
||||
gateway = it.getOrDefault(
|
||||
"gateway",
|
||||
gateway,
|
||||
"MatterBridge gateway"
|
||||
),
|
||||
autoConnect = it.getOrDefault(
|
||||
"autoConnect",
|
||||
autoConnect,
|
||||
"Connect the relay on startup"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
.registerTypeAdapter(DebugOptions::class.java) {
|
||||
with(DebugOptions()) {
|
||||
DebugOptions(
|
||||
logLevel = it.getOrDefault("loglevel", logLevel, "MatterLink log level")
|
||||
)
|
||||
}
|
||||
}
|
||||
.registerTypeAdapter(IncomingOptions::class.java) {
|
||||
with(IncomingOptions()) {
|
||||
IncomingOptions(
|
||||
chat = it.getOrDefault(
|
||||
"chat",
|
||||
chat,
|
||||
"Generic chat event, just talking"
|
||||
),
|
||||
joinPart = it.getOrDefault(
|
||||
"joinPart",
|
||||
joinPart,
|
||||
"Join and part events from other gateways"
|
||||
),
|
||||
action = it.getOrDefault(
|
||||
"action",
|
||||
action,
|
||||
"User actions (/me) sent by users from other gateways"
|
||||
),
|
||||
stripColors = it.getOrDefault(
|
||||
"stripColors",
|
||||
stripColors,
|
||||
"strip colors from incoming text"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
.registerTypeAdapter(OutgoingOptions::class.java) {
|
||||
with(OutgoingOptions()) {
|
||||
OutgoingOptions(
|
||||
systemUser = it.getOrDefault(
|
||||
"systemUser",
|
||||
systemUser,
|
||||
"Name of the server user (used by death and advancement messages and the /say command)"
|
||||
),
|
||||
advancements = it.getOrDefault(
|
||||
"advancements",
|
||||
advancements,
|
||||
"Relay player achievements / advancements"
|
||||
),
|
||||
announceConnect = it.getOrDefault(
|
||||
"announceConnect",
|
||||
announceConnect,
|
||||
"announce successful connection to the gateway"
|
||||
),
|
||||
announceDisconnect = it.getOrDefault(
|
||||
"announceDisconnect",
|
||||
announceConnect,
|
||||
"announce intention to disconnect / reconnect"
|
||||
),
|
||||
stripColors = it.getOrDefault(
|
||||
"stripColors",
|
||||
stripColors,
|
||||
"strip colors from nicknames and messages"
|
||||
),
|
||||
death = it.getOrDefault(
|
||||
"death",
|
||||
DeathOptions(),
|
||||
"Death messages settings"
|
||||
),
|
||||
joinPart = it.getOrDefault(
|
||||
"joinPart",
|
||||
JoinPartOptions(),
|
||||
"relay join and part messages to the gatway"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
.registerTypeAdapter(DeathOptions::class.java) { jsonObj ->
|
||||
with(DeathOptions()) {
|
||||
DeathOptions(
|
||||
enable = jsonObj.getOrDefault(
|
||||
"enable",
|
||||
enable,
|
||||
"Relay player death messages"
|
||||
),
|
||||
damageType = jsonObj.getOrDefault(
|
||||
"damageType",
|
||||
damageType,
|
||||
"Enable Damage type symbols on death messages"
|
||||
),
|
||||
damageTypeMapping = (jsonObj.getObject("damageTypeMapping")
|
||||
?: Marshaller.getFallback().serialize(damageTypeMapping) as JsonObject)
|
||||
.let {
|
||||
jsonObj.setComment(
|
||||
"damageTypMapping",
|
||||
"Damage type mapping for death cause"
|
||||
)
|
||||
it.mapValues { (key, element) ->
|
||||
it.getOrDefault(key, damageTypeMapping[key] ?: emptyArray(), key)
|
||||
.apply { it[key] }.apply {
|
||||
jsonObj["damageTypeMapping"] = it
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
.registerTypeAdapter(JoinPartOptions::
|
||||
class.java)
|
||||
{
|
||||
with(JoinPartOptions()) {
|
||||
JoinPartOptions(
|
||||
enable = it.getOrDefault(
|
||||
"enable",
|
||||
enable,
|
||||
"Relay when a player joins / parts the game" +
|
||||
"\nany receiving end still needs to be configured with showJoinPart = true" +
|
||||
"\nto display the messages"
|
||||
),
|
||||
joinServer = it.getOrDefault(
|
||||
"joinServer",
|
||||
joinServer,
|
||||
"user join message sent to other gateways, available variables: {username}, {username:antiping}"
|
||||
),
|
||||
partServer = it.getOrDefault(
|
||||
"partServer",
|
||||
partServer,
|
||||
"user part message sent to other gateways, available variables: {username}, {username:antiping}"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
.registerTypeAdapter(UpdateOptions::
|
||||
class.java)
|
||||
{
|
||||
with(UpdateOptions()) {
|
||||
UpdateOptions(
|
||||
enable = it.getOrDefault(
|
||||
"enable",
|
||||
enable,
|
||||
"Enable Update checking"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
.build()
|
||||
}
|
||||
|
||||
abstract fun load(): BaseConfig
|
||||
fun load(): MatterLinkConfig {
|
||||
val jsonObject = try {
|
||||
jankson.load(configFile)
|
||||
} catch (e: SyntaxError) {
|
||||
instance.error("error loading config: ${e.completeMessage}")
|
||||
Marshaller.getFallback().serialize(MatterLinkConfig()) as JsonObject
|
||||
} catch (e: FileNotFoundException) {
|
||||
instance.error("creating config file $configFile")
|
||||
configFile.createNewFile()
|
||||
Marshaller.getFallback().serialize(MatterLinkConfig()) as JsonObject
|
||||
}
|
||||
instance.info("finished loading $jsonObject")
|
||||
|
||||
val tmpCfg = try {
|
||||
cfgDirectory.resolve("debug.matterlink.hjson").writeText(jsonObject.toJson(false, true))
|
||||
jankson.fromJson(jsonObject, MatterLinkConfig::class.java).apply {
|
||||
configFile.writeText(jsonObject.toJson(true, true))
|
||||
instance.info("loaded config: $this")
|
||||
}
|
||||
} catch (e: SyntaxError) {
|
||||
instance.error("error parsing config: ${e.completeMessage} ${e.stackTraceString}")
|
||||
MatterLinkConfig()
|
||||
} catch (e: IllegalStateException) {
|
||||
instance.error(e.stackTraceString)
|
||||
MatterLinkConfig()
|
||||
}
|
||||
|
||||
|
||||
// val defaultJsonObject = jankson.load("{}")
|
||||
// jankson.fromJson(defaultJsonObject, MatterLinkConfig::class.java)
|
||||
// val nonDefault = jsonObject.getDelta(defaultJsonObject)
|
||||
|
||||
MessageHandlerInst.config.url = cfg.connect.url
|
||||
MessageHandlerInst.config.token = cfg.connect.authToken
|
||||
MessageHandlerInst.config.gateway = cfg.connect.gateway
|
||||
MessageHandlerInst.config.reconnectWait = cfg.connect.reconnectWait
|
||||
|
||||
MessageHandlerInst.config.systemUser = cfg.outgoing.systemUser
|
||||
MessageHandlerInst.config.announceConnect = cfg.outgoing.announceConnect
|
||||
MessageHandlerInst.config.announceDisconnect = cfg.outgoing.announceDisconnect
|
||||
|
||||
return tmpCfg
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ package matterlink.config
|
|||
import blue.endless.jankson.Jankson
|
||||
import blue.endless.jankson.JsonObject
|
||||
import blue.endless.jankson.JsonPrimitive
|
||||
import blue.endless.jankson.impl.Marshaller
|
||||
import blue.endless.jankson.impl.SyntaxError
|
||||
import matterlink.bridge.command.CommandType
|
||||
import matterlink.bridge.command.CustomCommand
|
||||
|
@ -15,7 +14,7 @@ typealias CommandMap = MutableMap<String, CustomCommand>
|
|||
typealias DefaultCommands = Map<String, Pair<String, CustomCommand>>
|
||||
|
||||
object CommandConfig {
|
||||
private val configFile: File = cfg.cfgDirectory.resolve("commands.json")
|
||||
private val configFile: File = baseCfg.cfgDirectory.resolve("commands.hjson")
|
||||
|
||||
private val default: DefaultCommands = mapOf(
|
||||
"tps" to ("""Your run off the mill tps commands, change it to /sampler tps or /cofh tps if you like
|
||||
|
@ -89,20 +88,14 @@ object CommandConfig {
|
|||
)
|
||||
}
|
||||
}
|
||||
.registerPrimitiveTypeAdapter(CommandType::class.java) {jsonObj ->
|
||||
CommandType.valueOf(jsonObj.toString())
|
||||
}
|
||||
.registerPrimitiveTypeAdapter(Regex::class.java) {jsonObj ->
|
||||
jsonObj.toString().toRegex()
|
||||
.registerPrimitiveTypeAdapter(Regex::class.java) {
|
||||
it.toString().toRegex()
|
||||
}
|
||||
.build()
|
||||
|
||||
Marshaller.getFallback().registerSerializer(Regex::class.java) {
|
||||
jankson.marshaller.registerSerializer(Regex::class.java) {
|
||||
JsonPrimitive(it.pattern)
|
||||
}
|
||||
Marshaller.getFallback().registerSerializer(CommandType::class.java) {
|
||||
JsonPrimitive(it.name)
|
||||
}
|
||||
|
||||
val jsonObject = try {
|
||||
jankson.load(configFile)
|
||||
|
@ -117,8 +110,13 @@ object CommandConfig {
|
|||
commands.clear()
|
||||
jsonObject.forEach { key, element ->
|
||||
instance.trace("loading command '$key'")
|
||||
val command = jankson.fromJson(element.toJson(), CustomCommand::class.java)
|
||||
commands[key] = command
|
||||
val command = jsonObject.get(CustomCommand::class.java, key)
|
||||
if(command != null)
|
||||
commands[key] = command
|
||||
else {
|
||||
instance.error("could not parse key: $key, value: '$element' as CustomCommand")
|
||||
instance.error("skipping $key")
|
||||
}
|
||||
}
|
||||
|
||||
//apply defaults
|
||||
|
@ -126,7 +124,7 @@ object CommandConfig {
|
|||
val command = commands[k]
|
||||
if (command == null || command.defaultCommand == true) {
|
||||
commands[k] = defCommand
|
||||
val element = Marshaller.getFallback().serialize(defCommand)
|
||||
val element = jankson.marshaller.serialize(defCommand)
|
||||
jsonObject.putDefault(k, element, comment)
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +132,9 @@ object CommandConfig {
|
|||
instance.debug("loaded jsonObj: $jsonObject")
|
||||
instance.debug("loaded commandMap: $commands")
|
||||
|
||||
configFile.writeText(jsonObject.toJson(true, true))
|
||||
val nonDefaultJsonObj = jsonObject.getDelta(jankson.marshaller.serialize(default.mapValues { it.value.second }) as JsonObject)
|
||||
|
||||
configFile.writeText(nonDefaultJsonObj.toJson(true, true))
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ object PermissionConfig {
|
|||
.builder()
|
||||
.build()
|
||||
|
||||
private val configFile: File = cfg.cfgDirectory.resolve("permissions.json")
|
||||
private val configFile: File = baseCfg.cfgDirectory.resolve("permissions.hjson")
|
||||
|
||||
private val default = mapOf(
|
||||
"irc.esper" to mapOf(
|
||||
|
@ -42,13 +42,17 @@ object PermissionConfig {
|
|||
}
|
||||
|
||||
default.forEach { platform, userMap ->
|
||||
val jsonUserMap = jsonObject.getOrDefault(platform, JsonObject()) as JsonObject
|
||||
userMap.forEach { user, (powerlevel, comment) ->
|
||||
instance.trace("loading platform: $platform user: $user powwerlevel: $powerlevel")
|
||||
val element = Marshaller.getFallback().serialize(powerlevel)
|
||||
jsonUserMap.putDefault(user, element, comment.takeUnless { it.isBlank() })
|
||||
val jsonUserMap = jsonObject.getOrDefault(platform, JsonObject())
|
||||
if(jsonUserMap is JsonObject) {
|
||||
userMap.forEach { user, (powerlevel, comment) ->
|
||||
instance.trace("loading platform: $platform user: $user powwerlevel: $powerlevel")
|
||||
val element = Marshaller.getFallback().serialize(powerlevel)
|
||||
jsonUserMap.putDefault(user, element, comment.takeUnless { it.isBlank() })
|
||||
}
|
||||
jsonObject[platform] = jsonUserMap
|
||||
} else {
|
||||
instance.error("cannot parse platform: $platform , value: '$jsonUserMap' as Map, skipping")
|
||||
}
|
||||
jsonObject[platform] = jsonUserMap
|
||||
}
|
||||
|
||||
jsonObject.forEach { platform, jsonUserMap ->
|
||||
|
|
|
@ -18,8 +18,8 @@ object DeathHandler {
|
|||
if (cfg.outgoing.death.enable) {
|
||||
var msg = deathMessage.stripColorOut.replace(player, player.stripColorOut.antiping)
|
||||
if (cfg.outgoing.death.damageType) {
|
||||
val emojis = cfg.outgoing.death.damageTypeMapping[damageType]?.split(' ')
|
||||
?: listOf("\uD83D\uDC7B unknown type '$damageType'")
|
||||
val emojis = cfg.outgoing.death.damageTypeMapping[damageType]
|
||||
?: arrayOf("\uD83D\uDC7B unknown type '$damageType'")
|
||||
val damageEmoji = emojis[random.nextInt(emojis.size)]
|
||||
msg += " $damageEmoji"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue