diff --git a/1.10.2/src/main/kotlin/matterlink/MatterLink.kt b/1.10.2/src/main/kotlin/matterlink/MatterLink.kt index 632da73..7b6eefa 100644 --- a/1.10.2/src/main/kotlin/matterlink/MatterLink.kt +++ b/1.10.2/src/main/kotlin/matterlink/MatterLink.kt @@ -19,8 +19,6 @@ import org.apache.logging.log4j.Level import org.apache.logging.log4j.Logger import java.util.* -lateinit var logger: Logger - @Mod( modid = MODID, name = NAME, version = MODVERSION, @@ -37,7 +35,7 @@ object MatterLink : IMatterLink() { @Mod.EventHandler fun preInit(event: FMLPreInitializationEvent) { - logger = event.modLog + logger = event.modLog as org.apache.logging.log4j.core.Logger logger.info("Building bridge!") cfg = BaseConfig(event.modConfigurationDirectory).load() @@ -79,11 +77,11 @@ object MatterLink : IMatterLink() { override fun wrappedSendToPlayer(uuid: UUID, msg: String) { val profile = profileByUUID(uuid) ?: run { - error("cannot find player by uuid $uuid") + logger.error("cannot find player by uuid $uuid") return } val player = playerByProfile(profile) ?: run { - error("${profile.name} is not online") + logger.error("${profile.name} is not online") return } player.sendMessage(TextComponentString(msg)) @@ -97,14 +95,14 @@ object MatterLink : IMatterLink() { private fun profileByUUID(uuid: UUID): GameProfile? = try { FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getProfileByUUID(uuid) } catch (e: IllegalArgumentException) { - warn("cannot find profile by uuid $uuid") + logger.warn("cannot find profile by uuid $uuid") null } private fun profileByName(username: String): GameProfile? = try { FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getGameProfileForUsername(username) } catch (e: IllegalArgumentException) { - warn("cannot find profile by username $username") + logger.warn("cannot find profile by username $username") null } @@ -112,10 +110,6 @@ object MatterLink : IMatterLink() { override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name - override fun log(level: String, formatString: String, vararg data: Any) = - logger.log(Level.toLevel(level, Level.INFO), formatString, *data) - - override fun commandSenderFor( user: String, env: IBridgeCommand.CommandEnvironment, diff --git a/1.11.2/src/main/kotlin/matterlink/MatterLink.kt b/1.11.2/src/main/kotlin/matterlink/MatterLink.kt index 7a71741..22a7171 100644 --- a/1.11.2/src/main/kotlin/matterlink/MatterLink.kt +++ b/1.11.2/src/main/kotlin/matterlink/MatterLink.kt @@ -1,11 +1,13 @@ package matterlink import com.mojang.authlib.GameProfile +import jline.internal.Log.warn import matterlink.bridge.command.IBridgeCommand import matterlink.command.MatterLinkCommand import matterlink.command.MatterLinkCommandSender import matterlink.config.BaseConfig import matterlink.config.cfg +import net.minecraft.entity.ai.EntityMoveHelper import net.minecraft.entity.player.EntityPlayerMP import net.minecraft.util.text.TextComponentString import net.minecraftforge.common.ForgeVersion @@ -19,8 +21,6 @@ import org.apache.logging.log4j.Level import org.apache.logging.log4j.Logger import java.util.* -lateinit var logger: Logger - @Mod( modid = MODID, name = NAME, version = MODVERSION, @@ -37,7 +37,7 @@ object MatterLink : IMatterLink() { @Mod.EventHandler fun preInit(event: FMLPreInitializationEvent) { - logger = event.modLog + logger = event.modLog as org.apache.logging.log4j.core.Logger logger.info("Building bridge!") cfg = BaseConfig(event.modConfigurationDirectory).load() @@ -67,11 +67,11 @@ object MatterLink : IMatterLink() { override fun wrappedSendToPlayer(username: String, msg: String) { val profile = profileByName(username) ?: run { - error("cannot find player by name $username") + logger.error("cannot find player by name $username") return } val player = playerByProfile(profile) ?: run { - error("${profile.name} is not online") + logger.error("${profile.name} is not online") return } player.sendMessage(TextComponentString(msg)) @@ -79,11 +79,11 @@ object MatterLink : IMatterLink() { override fun wrappedSendToPlayer(uuid: UUID, msg: String) { val profile = profileByUUID(uuid) ?: run { - error("cannot find player by uuid $uuid") + logger.error("cannot find player by uuid $uuid") return } val player = playerByProfile(profile) ?: run { - error("${profile.name} is not online") + logger.error("${profile.name} is not online") return } player.sendMessage(TextComponentString(msg)) @@ -97,14 +97,14 @@ object MatterLink : IMatterLink() { private fun profileByUUID(uuid: UUID): GameProfile? = try { FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getProfileByUUID(uuid) } catch (e: IllegalArgumentException) { - warn("cannot find profile by uuid $uuid") + logger.warn("cannot find profile by uuid $uuid") null } private fun profileByName(username: String): GameProfile? = try { FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getGameProfileForUsername(username) } catch (e: IllegalArgumentException) { - warn("cannot find profile by username $username") + logger.warn("cannot find profile by username $username") null } @@ -112,9 +112,6 @@ object MatterLink : IMatterLink() { override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name - override fun log(level: String, formatString: String, vararg data: Any) = - logger.log(Level.toLevel(level, Level.INFO), formatString, *data) - override fun commandSenderFor( user: String, env: IBridgeCommand.CommandEnvironment, diff --git a/1.12.2/src/main/kotlin/matterlink/EventHandler.kt b/1.12.2/src/main/kotlin/matterlink/EventHandler.kt index 7f39daa..ffdf3da 100644 --- a/1.12.2/src/main/kotlin/matterlink/EventHandler.kt +++ b/1.12.2/src/main/kotlin/matterlink/EventHandler.kt @@ -49,15 +49,10 @@ object EventHandler { @SubscribeEvent @JvmStatic fun commandEvent(e: CommandEvent) { - instance.log("DEBUG","commandEvent ${e.sender.javaClass.simpleName}") - instance.log("DEBUG","commandEvent ${e.sender.javaClass.typeName}") - instance.log("DEBUG","command ${e.command.aliases}") - instance.log("DEBUG","command ${e.command.name}") val sender = when { e.sender is DedicatedServer -> cfg.outgoing.systemUser else -> e.sender.displayName.unformattedText } - instance.log("DEBUG","sender $sender") val args = e.parameters.joinToString(" ") val type = when { e.command is CommandEmote -> USER_ACTION diff --git a/1.12.2/src/main/kotlin/matterlink/MatterLink.kt b/1.12.2/src/main/kotlin/matterlink/MatterLink.kt index 7f10f9c..6b4eb23 100644 --- a/1.12.2/src/main/kotlin/matterlink/MatterLink.kt +++ b/1.12.2/src/main/kotlin/matterlink/MatterLink.kt @@ -1,6 +1,7 @@ package matterlink import com.mojang.authlib.GameProfile +import jline.internal.Log.warn import matterlink.bridge.command.IBridgeCommand import matterlink.command.AuthCommand import matterlink.command.MatterLinkCommand @@ -17,10 +18,9 @@ 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 +import org.apache.logging.log4j.core.config.Configurator import java.util.* -lateinit var logger: Logger @Mod( modid = MODID, @@ -34,12 +34,14 @@ lateinit var logger: Logger object MatterLink : IMatterLink() { init { + Configurator.setLevel(MODID, Level.DEBUG) instance = this } @Mod.EventHandler fun preInit(event: FMLPreInitializationEvent) { - logger = event.modLog + logger = event.modLog as org.apache.logging.log4j.core.Logger + logger.level = Level.DEBUG logger.info("Building bridge!") cfg = BaseConfig(event.modConfigurationDirectory).load() @@ -52,7 +54,7 @@ object MatterLink : IMatterLink() { @Mod.EventHandler fun serverStarting(event: FMLServerStartingEvent) { - log("DEBUG", "Registering server commands") + logger.debug("Registering server commands") event.registerServerCommand(MatterLinkCommand()) event.registerServerCommand(AuthCommand()) start() @@ -70,11 +72,11 @@ object MatterLink : IMatterLink() { override fun wrappedSendToPlayer(username: String, msg: String) { val profile = profileByName(username) ?: run { - error("cannot find player by name $username") + logger.error("cannot find player by name $username") return } val player = playerByProfile(profile) ?: run { - error("${profile.name} is not online") + logger.error("${profile.name} is not online") return } player.sendMessage(TextComponentString(msg)) @@ -82,11 +84,11 @@ object MatterLink : IMatterLink() { override fun wrappedSendToPlayer(uuid: UUID, msg: String) { val profile = profileByUUID(uuid) ?: run { - error("cannot find player by uuid $uuid") + logger.error("cannot find player by uuid $uuid") return } val player = playerByProfile(profile) ?: run { - error("${profile.name} is not online") + logger.error("${profile.name} is not online") return } player.sendMessage(TextComponentString(msg)) @@ -115,8 +117,8 @@ object MatterLink : IMatterLink() { override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name - override fun log(level: String, formatString: String, vararg data: Any) = - logger.log(Level.toLevel(level, Level.INFO), formatString, *data) +// override fun log(level: String, formatString: String, vararg data: Any) = +// logger.log(Level.toLevel(level, Level.INFO), formatString, *data) override fun commandSenderFor( user: String, diff --git a/1.7.10/src/main/kotlin/matterlink/MatterLink.kt b/1.7.10/src/main/kotlin/matterlink/MatterLink.kt index d64a6ea..be6dff7 100644 --- a/1.7.10/src/main/kotlin/matterlink/MatterLink.kt +++ b/1.7.10/src/main/kotlin/matterlink/MatterLink.kt @@ -21,8 +21,6 @@ import org.apache.logging.log4j.Level import org.apache.logging.log4j.Logger import java.util.* -lateinit var logger: Logger - @Mod( modid = MODID, name = NAME, version = MODVERSION, @@ -39,7 +37,7 @@ class MatterLink : IMatterLink() { MinecraftForge.EVENT_BUS.register(EventHandler) FMLCommonHandler.instance().bus().register(EventHandler) - logger = event.modLog + logger = event.modLog as org.apache.logging.log4j.core.Logger logger.info("Building bridge!") cfg = BaseConfig(event.modConfigurationDirectory).load() @@ -69,11 +67,11 @@ class MatterLink : IMatterLink() { override fun wrappedSendToPlayer(username: String, msg: String) { val profile = profileByName(username) ?: run { - error("cannot find player by name $username") + logger.error("cannot find player by name $username") return } val player = playerByProfile(profile) ?: run { - error("${profile.name} is not online") + logger.error("${profile.name} is not online") return } player.addChatMessage(ChatComponentText(msg)) @@ -81,11 +79,11 @@ class MatterLink : IMatterLink() { override fun wrappedSendToPlayer(uuid: UUID, msg: String) { val profile = profileByUUID(uuid) ?: run { - error("cannot find player by uuid $uuid") + logger.error("cannot find player by uuid $uuid") return } val player = playerByProfile(profile) ?: run { - error("${profile.name} is not online") + logger.error("${profile.name} is not online") return } player.addChatMessage(ChatComponentText(msg)) @@ -101,14 +99,14 @@ class MatterLink : IMatterLink() { private fun profileByUUID(uuid: UUID): GameProfile? = try { FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.func_152652_a(uuid) } catch (e: IllegalArgumentException) { - warn("cannot find profile by uuid $uuid") + logger.warn("cannot find profile by uuid $uuid") null } private fun profileByName(username: String): GameProfile? = try { FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getGameProfileForUsername(username) } catch (e: IllegalArgumentException) { - warn("cannot find profile by username $username") + logger.warn("cannot find profile by username $username") null } @@ -116,9 +114,6 @@ class MatterLink : IMatterLink() { override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name - override fun log(level: String, formatString: String, vararg data: Any) = - logger.log(Level.toLevel(level, Level.INFO), formatString, *data) - override fun commandSenderFor( user: String, env: IBridgeCommand.CommandEnvironment, diff --git a/Jankson b/Jankson index bb136c1..93ab86e 160000 --- a/Jankson +++ b/Jankson @@ -1 +1 @@ -Subproject commit bb136c12e3ae50498b3435fc11dbd833efdb6a1c +Subproject commit 93ab86ee821380584c22ac60d77737388976e531 diff --git a/api b/api index 15e4d11..75138ce 160000 --- a/api +++ b/api @@ -1 +1 @@ -Subproject commit 15e4d115dd0e1ac1e5d287c48d6dc76a6a488ed7 +Subproject commit 75138cec00c66d479709f4b44d78ca3005993474 diff --git a/build.gradle b/build.gradle index 84632ce..12a58db 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "org.jetbrains.kotlin.jvm" version '1.2.51' + id "org.jetbrains.kotlin.jvm" version '1.2.41' id 'idea' } diff --git a/core/build.gradle b/core/build.gradle index 5ad0456..9ed1658 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -26,7 +26,9 @@ dependencies { compile project(":Jankson") - compile group: 'commons-logging', name: 'commons-logging', version: '1.1.3' +// compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '+' + compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '+' +// compile group: 'commons-logging', name: 'commons-logging', version: '1.1.3' compile group: 'com.google.code.gson', name: 'gson', version: '+' compile group: 'com.google.guava', name: 'guava', version: '+' diff --git a/core/src/main/kotlin/matterlink/IMatterLink.kt b/core/src/main/kotlin/matterlink/IMatterLink.kt index 30d361b..63d0a02 100644 --- a/core/src/main/kotlin/matterlink/IMatterLink.kt +++ b/core/src/main/kotlin/matterlink/IMatterLink.kt @@ -1,14 +1,17 @@ package matterlink +import matterlink.api.MessageHandler import matterlink.bridge.MessageHandlerInst import matterlink.bridge.command.BridgeCommandRegistry import matterlink.bridge.command.IBridgeCommand import matterlink.bridge.command.IMinecraftCommandSender import matterlink.config.cfg import matterlink.update.UpdateChecker +import org.apache.logging.log4j.core.Logger import java.util.* lateinit var instance: IMatterLink +lateinit var logger: Logger abstract class IMatterLink { abstract val mcVersion: String @@ -26,16 +29,17 @@ abstract class IMatterLink { abstract fun uuidToName(uuid: UUID): String? fun start() { - MessageHandlerInst.logger = { level, msg -> - when (level) { - "FATAL" -> fatal(msg) - "ERROR" -> error(msg) - "WARN" -> warn(msg) - "INFO" -> info(msg) - "DEBUG" -> debug(msg) - "TRACE" -> trace(msg) - } - } +// MessageHandlerInst.logger = { level, msg -> +// when (level) { +// "FATAL" -> logger.fatal(msg) +// "ERROR" -> logger.error(msg) +// "WARN" -> logger.warn(msg) +// "INFO" -> logger.info(msg) +// "DEBUG" -> logger.debug(msg) +// "TRACE" -> logger.trace(msg) +// } +// } + MessageHandlerInst.logger = logger serverStartTime = System.currentTimeMillis() if (cfg.connect.autoConnect) @@ -47,22 +51,22 @@ abstract class IMatterLink { MessageHandlerInst.stop("Server shutting down, disconnecting from matterbridge API") } - abstract fun log(level: String, formatString: String, vararg data: Any) +// abstract fun log(level: String, formatString: String, vararg data: Any) - fun fatal(formatString: String, vararg data: Any) = log("FATAL", formatString, *data) - fun error(formatString: String, vararg data: Any) = log("ERROR", formatString, *data) - fun warn(formatString: String, vararg data: Any) = log("WARN", formatString, *data) - fun info(formatString: String, vararg data: Any) = log("INFO", formatString, *data) - - fun debug(formatString: String, vararg data: Any) { - if (cfg.debug.logLevel == "DEBUG" || cfg.debug.logLevel == "TRACE") - log("INFO", "DEBUG: " + formatString.replace("\n", "\nDEBUG: "), *data) - } - - fun trace(formatString: String, vararg data: Any) { - if (cfg.debug.logLevel == "TRACE") - log("INFO", "TRACE: " + formatString.replace("\n", "\nTRACE: "), *data) - } +// fun fatal(formatString: String, vararg data: Any) = log("FATAL", formatString, *data) +// fun error(formatString: String, vararg data: Any) = log("ERROR", formatString, *data) +// fun warn(formatString: String, vararg data: Any) = log("WARN", formatString, *data) +// fun info(formatString: String, vararg data: Any) = log("INFO", formatString, *data) +// +// fun debug(formatString: String, vararg data: Any) { +// if (cfg.debug.logLevel == "DEBUG" || cfg.debug.logLevel == "TRACE") +// log("INFO", "DEBUG: " + formatString.replace("\n", "\nDEBUG: "), *data) +// } +// +// fun trace(formatString: String, vararg data: Any) { +// if (cfg.debug.logLevel == "TRACE") +// log("INFO", "TRACE: " + formatString.replace("\n", "\nTRACE: "), *data) +// } /** * in milliseconds diff --git a/core/src/main/kotlin/matterlink/PasteUtil.kt b/core/src/main/kotlin/matterlink/PasteUtil.kt index e40b574..852f75d 100644 --- a/core/src/main/kotlin/matterlink/PasteUtil.kt +++ b/core/src/main/kotlin/matterlink/PasteUtil.kt @@ -85,7 +85,7 @@ object PasteUtil { } val textResponse = http.inputStream.bufferedReader().use { it.readText() } - instance.debug("response: $textResponse") + logger.debug("response: $textResponse") // val jsonObject = jankson.load(http.inputStream) return jankson.fromJson(textResponse) } diff --git a/core/src/main/kotlin/matterlink/Util.kt b/core/src/main/kotlin/matterlink/Util.kt index 7351f5b..1fbc478 100644 --- a/core/src/main/kotlin/matterlink/Util.kt +++ b/core/src/main/kotlin/matterlink/Util.kt @@ -67,7 +67,7 @@ fun randomString(length: Int = 6): String = java.util.UUID.randomUUID().toString().replace("-", "").take(length) fun JsonObject.getOrDefault(key: String, default: T, comment: String? = null): T { -// instance.info("type: ${default.javaClass.name} key: $key json: >>>${this.getObject(key)?.toJson()}<<< default: $default") +// logger.info("type: ${default.javaClass.name} key: $key json: >>>${this.getObject(key)?.toJson()}<<< default: $default") return putDefault(key, default, comment)!! } diff --git a/core/src/main/kotlin/matterlink/bridge/MessageHandlerInst.kt b/core/src/main/kotlin/matterlink/bridge/MessageHandlerInst.kt index a9de88d..0a5bcec 100644 --- a/core/src/main/kotlin/matterlink/bridge/MessageHandlerInst.kt +++ b/core/src/main/kotlin/matterlink/bridge/MessageHandlerInst.kt @@ -11,7 +11,7 @@ object MessageHandlerInst : MessageHandler() { } fun transmit(msg: ApiMessage, cause: String, maxLines: Int = cfg.outgoing.inlineLimit) { - if (msg.text.count { it == '\n' } >= maxLines) { + if (msg.text.lines().count() >= maxLines) { try { val response = PasteUtil.paste( Paste( @@ -20,15 +20,15 @@ object MessageHandlerInst : MessageHandler() { PasteSection( name = "log.txt", syntax = "text", - contents = msg.text.replace("\n", "\\n") + contents = msg.text ) ) ) ) msg.text = msg.text.substringBefore('\n') - .take(20) + "... " + response.link + .take(25) + "... " + response.link } catch(e: Exception) { - instance.error(e.stackTraceString) + logger.error(e.stackTraceString) } } super.transmit(msg) diff --git a/core/src/main/kotlin/matterlink/bridge/command/BridgeCommandRegistry.kt b/core/src/main/kotlin/matterlink/bridge/command/BridgeCommandRegistry.kt index 113c341..d689197 100644 --- a/core/src/main/kotlin/matterlink/bridge/command/BridgeCommandRegistry.kt +++ b/core/src/main/kotlin/matterlink/bridge/command/BridgeCommandRegistry.kt @@ -7,6 +7,7 @@ import matterlink.config.IdentitiesConfig import matterlink.config.PermissionConfig import matterlink.config.cfg import matterlink.instance +import matterlink.logger import matterlink.stripColorOut import java.util.* @@ -31,7 +32,7 @@ object BridgeCommandRegistry { val env = IBridgeCommand.CommandEnvironment.BridgeEnv(input.username, input.userid, input.account, uuid) return commandMap[cmd[0]]?.let { if (!it.reachedTimeout()) { - instance.debug("dropped command ${it.alias}") + logger.debug("dropped command ${it.alias}") return false } it.preExecute() // resets the tickCounter @@ -57,7 +58,7 @@ object BridgeCommandRegistry { return commandMap[cmd[0]]?.let { if (!it.reachedTimeout()) { - instance.debug("dropped command ${it.alias}") + logger.debug("dropped command ${it.alias}") return false } it.preExecute() // resets the tickCounter @@ -74,11 +75,11 @@ object BridgeCommandRegistry { fun register(alias: String, cmd: IBridgeCommand): Boolean { if (alias.isBlank() || commandMap.containsKey(alias)) { - instance.error("Failed to register command: '$alias'") + logger.error("Failed to register command: '$alias'") return false } if (!cmd.validate()) { - instance.error("Failed to validate command: '$alias'") + logger.error("Failed to validate command: '$alias'") return false } //TODO: maybe write alias to command here ? diff --git a/core/src/main/kotlin/matterlink/bridge/command/CustomCommand.kt b/core/src/main/kotlin/matterlink/bridge/command/CustomCommand.kt index f50e07f..81c301e 100644 --- a/core/src/main/kotlin/matterlink/bridge/command/CustomCommand.kt +++ b/core/src/main/kotlin/matterlink/bridge/command/CustomCommand.kt @@ -2,6 +2,7 @@ package matterlink.bridge.command import matterlink.instance import matterlink.lazyFormat +import matterlink.logger import matterlink.stripColorIn data class CustomCommand( @@ -18,7 +19,7 @@ data class CustomCommand( override fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean { if (argumentsRegex != null) { - instance.debug("testing '$args' against '${argumentsRegex.pattern}'") + logger.debug("testing '$args' against '${argumentsRegex.pattern}'") if (!argumentsRegex.matches(args)) { env.respond("$user sent invalid input to command $alias") return false diff --git a/core/src/main/kotlin/matterlink/bridge/command/IBridgeCommand.kt b/core/src/main/kotlin/matterlink/bridge/command/IBridgeCommand.kt index eb996fa..b97034c 100644 --- a/core/src/main/kotlin/matterlink/bridge/command/IBridgeCommand.kt +++ b/core/src/main/kotlin/matterlink/bridge/command/IBridgeCommand.kt @@ -6,6 +6,7 @@ import matterlink.config.PermissionConfig import matterlink.config.cfg import matterlink.handlers.TickHandler import matterlink.instance +import matterlink.logger import matterlink.stripColorOut import java.util.* @@ -72,9 +73,9 @@ abstract class IBridgeCommand { abstract fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean fun canExecute(uuid: UUID?): Boolean { - instance.trace("canExecute this: $this uuid: $uuid permLevel: $permLevel") + logger.trace("canExecute this: $this uuid: $uuid permLevel: $permLevel") val canExec = getPermLevel(uuid) >= permLevel - instance.trace("canExecute return $canExec") + logger.trace("canExecute return $canExec") return canExec } diff --git a/core/src/main/kotlin/matterlink/config/BaseConfig.kt b/core/src/main/kotlin/matterlink/config/BaseConfig.kt index e3c90c4..204c377 100644 --- a/core/src/main/kotlin/matterlink/config/BaseConfig.kt +++ b/core/src/main/kotlin/matterlink/config/BaseConfig.kt @@ -4,11 +4,8 @@ import blue.endless.jankson.Jankson import blue.endless.jankson.JsonObject import blue.endless.jankson.impl.Marshaller import blue.endless.jankson.impl.SyntaxError +import matterlink.* import matterlink.bridge.MessageHandlerInst -import matterlink.getOrDefault -import matterlink.instance -import matterlink.registerTypeAdapter -import matterlink.stackTraceString import java.io.File import java.io.FileNotFoundException @@ -20,13 +17,12 @@ data class BaseConfig(val rootDir: File) { val configFile: File = cfgDirectory.resolve("matterlink.hjson") init { - instance.info("Reading bridge blueprints... from {}", rootDir) + logger.info("Reading bridge blueprints... from {}", rootDir) baseCfg = this } data class MatterLinkConfig( val connect: ConnectOptions = ConnectOptions(), - val debug: DebugOptions = DebugOptions(), val incoming: IncomingOptions = IncomingOptions(), val outgoing: OutgoingOptions = OutgoingOptions(), val command: CommandOptions = CommandOptions(), @@ -51,10 +47,6 @@ data class BaseConfig(val rootDir: File) { val reconnectWait: Long = 500 ) - data class DebugOptions( - val logLevel: String = "INFO" - ) - data class IncomingOptions( val chat: String = "<{username}> {text}", val joinPart: String = "ยง6-- {username} {text}", @@ -137,11 +129,6 @@ data class BaseConfig(val rootDir: File) { 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(), @@ -229,13 +216,6 @@ data class BaseConfig(val rootDir: File) { ) } } - .registerTypeAdapter { - with(DebugOptions()) { - DebugOptions( - logLevel = it.getOrDefault("loglevel", logLevel, "MatterLink log level") - ) - } - } .registerTypeAdapter { with(IncomingOptions()) { IncomingOptions( @@ -384,33 +364,34 @@ data class BaseConfig(val rootDir: File) { val jsonObject = try { jankson.load(configFile) } catch (e: SyntaxError) { - instance.error("error loading config: ${e.completeMessage}") + logger.error("error loading config: ${e.completeMessage}") jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject } catch (e: FileNotFoundException) { - instance.error("creating config file $configFile") + logger.error("creating config file $configFile") configFile.absoluteFile.parentFile.mkdirs() configFile.createNewFile() jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject } - instance.info("finished loading base config") + logger.info("finished loading base config") 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") + logger.info("loaded config: Main config") + logger.debug("loaded config: $this") } } catch (e: SyntaxError) { - instance.error("error parsing config: ${e.completeMessage} ") - instance.error(e.stackTraceString) + logger.error("error parsing config: ${e.completeMessage} ") + logger.error(e.stackTraceString) cfgDirectory.resolve("error.matterlink.hjson").writeText(jsonObject.toJson(false, true)) MatterLinkConfig() } catch (e: IllegalStateException) { - instance.error(e.stackTraceString) + logger.error(e.stackTraceString) cfgDirectory.resolve("error.matterlink.hjson").writeText(jsonObject.toJson(false, true)) MatterLinkConfig() } catch (e: NullPointerException) { - instance.error("error loading config: ${e.stackTraceString}") + logger.error("error loading config: ${e.stackTraceString}") cfgDirectory.resolve("error.matterlink.hjson").writeText(jsonObject.toJson(false, true)) MatterLinkConfig() } diff --git a/core/src/main/kotlin/matterlink/config/CommandConfig.kt b/core/src/main/kotlin/matterlink/config/CommandConfig.kt index eb39afe..cb7e53d 100644 --- a/core/src/main/kotlin/matterlink/config/CommandConfig.kt +++ b/core/src/main/kotlin/matterlink/config/CommandConfig.kt @@ -4,12 +4,9 @@ import blue.endless.jankson.Jankson import blue.endless.jankson.JsonObject import blue.endless.jankson.JsonPrimitive import blue.endless.jankson.impl.SyntaxError +import matterlink.* import matterlink.bridge.command.CommandType import matterlink.bridge.command.CustomCommand -import matterlink.getOrDefault -import matterlink.instance -import matterlink.registerPrimitiveTypeAdapter -import matterlink.registerTypeAdapter import java.io.File import java.io.FileNotFoundException @@ -103,7 +100,7 @@ object CommandConfig { val jsonObject = try { jankson.load(configFile) } catch (e: SyntaxError) { - instance.error("error parsing config: ${e.completeMessage}") + logger.error("error parsing config: ${e.completeMessage}") JsonObject() } catch (e: FileNotFoundException) { configFile.createNewFile() @@ -112,13 +109,13 @@ object CommandConfig { // clear commands commands.clear() jsonObject.forEach { key, element -> - instance.trace("loading command '$key'") + logger.trace("loading command '$key'") 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") + logger.error("could not parse key: $key, value: '$element' as CustomCommand") + logger.error("skipping $key") } } @@ -131,8 +128,8 @@ object CommandConfig { } } - instance.debug("loaded jsonObj: $jsonObject") - instance.debug("loaded commandMap: $commands") + logger.debug("loaded jsonObj: $jsonObject") + logger.debug("loaded commandMap: $commands") val defaultJsonObject = jankson.marshaller.serialize(CustomCommand.DEFAULT) as JsonObject val nonDefaultJsonObj = jsonObject.clone() diff --git a/core/src/main/kotlin/matterlink/config/IdentitiesConfig.kt b/core/src/main/kotlin/matterlink/config/IdentitiesConfig.kt index 6461d34..9990483 100644 --- a/core/src/main/kotlin/matterlink/config/IdentitiesConfig.kt +++ b/core/src/main/kotlin/matterlink/config/IdentitiesConfig.kt @@ -7,8 +7,7 @@ import blue.endless.jankson.impl.SyntaxError import com.google.common.cache.Cache import com.google.common.cache.CacheBuilder import matterlink.getList -import matterlink.getOrDefault -import matterlink.instance +import matterlink.logger import java.io.File import java.io.FileNotFoundException import java.util.* @@ -53,13 +52,13 @@ object IdentitiesConfig { val jsonUserMap = this.putDefault(uuid, JsonObject(), uuidComment) if (jsonUserMap is JsonObject) { userMap.forEach { platform, (user, comment) -> - instance.trace("loading uuid: $uuid platform: $platform user: $user") + logger.trace("loading uuid: $uuid platform: $platform user: $user") val element = Marshaller.getFallback().serialize(user) jsonUserMap.putDefault(platform, element, comment.takeUnless { it.isBlank() }) } this[uuid] = jsonUserMap } else { - instance.error("cannot parse uuid: $uuid , value: '$jsonUserMap' as Map, skipping") + logger.error("cannot parse uuid: $uuid , value: '$jsonUserMap' as Map, skipping") } } } @@ -68,11 +67,11 @@ object IdentitiesConfig { jsonObject = try { jankson.load(configFile) } catch (e: SyntaxError) { - instance.error("error parsing config: ${e.completeMessage}") + logger.error("error parsing config: ${e.completeMessage}") save = false defaultJsonObject } catch (e: FileNotFoundException) { - instance.error("cannot find config: $configFile .. creating sample permissions mapping") + logger.error("cannot find config: $configFile .. creating sample permissions mapping") configFile.createNewFile() defaultJsonObject } @@ -86,7 +85,7 @@ object IdentitiesConfig { val identMap: MutableMap> = tmpIdents[uuid]?.toMutableMap() ?: mutableMapOf() if (jsonIdentifier is JsonObject) { jsonIdentifier.forEach { platform, user -> - instance.info("$uuid $platform $user") + logger.info("$uuid $platform $user") identMap[platform] = jsonIdentifier.getList(platform) ?: emptyList() } } @@ -94,7 +93,7 @@ object IdentitiesConfig { } idents = tmpIdents.toMap() - instance.info("Identities loaded") + logger.info("Identities loaded") if (save) configFile.writeText(jsonObject.toJson(true, true)) @@ -119,7 +118,7 @@ object IdentitiesConfig { return idents.entries.firstOrNull { (uuid, usermap) -> usermap.entries.any { (_platform, userids) -> if (platform.equals(_platform, true)) - instance.info("platform: $_platform userids: $userids") + logger.info("platform: $_platform userids: $userids") platform.equals(_platform, true) && userids.contains(userid) } }?.key?.let { UUID.fromString(it) } diff --git a/core/src/main/kotlin/matterlink/config/PermissionConfig.kt b/core/src/main/kotlin/matterlink/config/PermissionConfig.kt index 6e5ee7d..a84704f 100644 --- a/core/src/main/kotlin/matterlink/config/PermissionConfig.kt +++ b/core/src/main/kotlin/matterlink/config/PermissionConfig.kt @@ -7,6 +7,7 @@ import com.google.common.cache.Cache import com.google.common.cache.CacheBuilder import matterlink.getReified import matterlink.instance +import matterlink.logger import java.io.File import java.io.FileNotFoundException import java.util.* @@ -49,11 +50,11 @@ object PermissionConfig { jsonObject = try { jankson.load(configFile) } catch (e: SyntaxError) { - instance.error("error parsing config: ${e.completeMessage}") + logger.error("error parsing config: ${e.completeMessage}") save = false defaultJsonObject } catch (e: FileNotFoundException) { - instance.error("cannot find config: $configFile .. creating sample permissions mapping") + logger.error("cannot find config: $configFile .. creating sample permissions mapping") configFile.createNewFile() defaultJsonObject } @@ -66,13 +67,13 @@ object PermissionConfig { for ((uuid, powerlevel) in jsonObject) { val tmpLevel = jsonObject.getReified(uuid) if (tmpLevel == null) { - instance.warn("cannot parse permission uuid: $uuid level: $powerlevel") + logger.warn("cannot parse permission uuid: $uuid level: $powerlevel") continue } tmpPerms[uuid] = tmpLevel } - instance.info("Permissions reloaded") + logger.info("Permissions reloaded") if (save) configFile.writeText(jsonObject.toJson(true, true)) diff --git a/core/src/main/kotlin/matterlink/handlers/ChatProcessor.kt b/core/src/main/kotlin/matterlink/handlers/ChatProcessor.kt index 98c62ed..1ffa2a9 100644 --- a/core/src/main/kotlin/matterlink/handlers/ChatProcessor.kt +++ b/core/src/main/kotlin/matterlink/handlers/ChatProcessor.kt @@ -4,6 +4,7 @@ import matterlink.api.ApiMessage import matterlink.bridge.MessageHandlerInst import matterlink.bridge.command.BridgeCommandRegistry import matterlink.instance +import matterlink.logger import matterlink.stripColorOut import java.util.* @@ -23,7 +24,7 @@ object ChatProcessor { ), cause = "Message from $user" ) - else -> instance.warn("WARN: dropped blank message by '$user'") + else -> logger.warn("WARN: dropped blank message by '$user'") } return false } diff --git a/core/src/main/kotlin/matterlink/handlers/ServerChatHandler.kt b/core/src/main/kotlin/matterlink/handlers/ServerChatHandler.kt index 7fe504a..85de8fb 100644 --- a/core/src/main/kotlin/matterlink/handlers/ServerChatHandler.kt +++ b/core/src/main/kotlin/matterlink/handlers/ServerChatHandler.kt @@ -5,6 +5,7 @@ import matterlink.bridge.command.BridgeCommandRegistry import matterlink.bridge.format import matterlink.config.cfg import matterlink.instance +import matterlink.logger import matterlink.stripColorIn object ServerChatHandler { @@ -14,7 +15,7 @@ object ServerChatHandler { */ fun writeIncomingToChat() { if (MessageHandlerInst.queue.isNotEmpty()) - instance.debug("incoming: " + MessageHandlerInst.queue.toString()) + logger.debug("incoming: " + MessageHandlerInst.queue.toString()) val nextMessage = MessageHandlerInst.queue.poll() ?: null if (nextMessage?.gateway == cfg.connect.gateway) { @@ -32,11 +33,11 @@ object ServerChatHandler { val user = nextMessage.username val text = nextMessage.text val json = nextMessage.encode() - instance.debug("Threw out message with unhandled event: ${nextMessage.event}") - instance.debug(" Message contents:") - instance.debug(" User: $user") - instance.debug(" Text: $text") - instance.debug(" JSON: $json") + logger.debug("Threw out message with unhandled event: ${nextMessage.event}") + logger.debug(" Message contents:") + logger.debug(" User: $user") + logger.debug(" Text: $text") + logger.debug(" JSON: $json") return } } diff --git a/core/src/main/kotlin/matterlink/update/UpdateChecker.kt b/core/src/main/kotlin/matterlink/update/UpdateChecker.kt index 726d0d0..e9b5593 100644 --- a/core/src/main/kotlin/matterlink/update/UpdateChecker.kt +++ b/core/src/main/kotlin/matterlink/update/UpdateChecker.kt @@ -6,6 +6,7 @@ import matterlink.api.ApiMessage import matterlink.bridge.MessageHandlerInst import matterlink.config.cfg import matterlink.instance +import matterlink.logger import java.io.BufferedReader import java.net.HttpURLConnection import java.net.URL @@ -25,11 +26,11 @@ class UpdateChecker : Thread() { override fun run() { if (instance.modVersion.contains("-build")) { - instance.debug("Not checking updates on Jenkins build") + logger.debug("Not checking updates on Jenkins build") return } if (instance.modVersion.contains("-dev")) { - instance.debug("Not checking updates on developer build") + logger.debug("Not checking updates on developer build") return } @@ -37,14 +38,14 @@ class UpdateChecker : Thread() { .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) .create() - instance.info("Checking for new versions...") + logger.info("Checking for new versions...") val url = URL("https://cursemeta.dries007.net/api/v2/direct/GetAllFilesForAddOn/287323") val con = url.openConnection() as HttpURLConnection with(instance) { val useragent = "MatterLink/$modVersion MinecraftForge/$mcVersion-$forgeVersion (https://github.com/elytra/MatterLink)" - instance.debug("setting User-Agent: '$useragent'") + logger.debug("setting User-Agent: '$useragent'") con.setRequestProperty("User-Agent", useragent) } @@ -55,7 +56,7 @@ class UpdateChecker : Thread() { //put all of the buffer content onto the string val content = buffer.readText() - instance.trace("updateData: $content") + logger.trace("updateData: $content") gson.fromJson(content, Array::class.java) .filter { @@ -64,7 +65,7 @@ class UpdateChecker : Thread() { .sortedByDescending { it.fileName.substringAfterLast(" ") } } else { - instance.error("Could not check for updates!") + logger.error("Could not check for updates!") return } @@ -78,13 +79,13 @@ class UpdateChecker : Thread() { val possibleUpdates = mutableListOf() apiUpdateList.forEach { - instance.debug(it.toString()) + logger.debug(it.toString()) val version = it.fileName.substringAfterLast("-").split('.').map { it.toInt() } var bigger = false version.forEachIndexed { index, chunk -> if (!bigger) { val currentChunk = modVersionChunks.getOrNull(index) ?: 0 - instance.debug("$chunk > $currentChunk") + logger.debug("$chunk > $currentChunk") if (chunk < currentChunk) return@forEach @@ -102,12 +103,12 @@ class UpdateChecker : Thread() { val count = possibleUpdates.count() val version = if (count == 1) "version" else "versions" - instance.info("Matterlink out of date! You are $count $version behind") + logger.info("Matterlink out of date! You are $count $version behind") possibleUpdates.forEach { - instance.info("version: {} download: {}", it.fileName, it.downloadURL) + logger.info("version: {} download: {}", it.fileName, it.downloadURL) } - instance.warn("Mod out of date! New $version available at ${latest.downloadURL}") + logger.warn("Mod out of date! New $version available at ${latest.downloadURL}") MessageHandlerInst.transmit( ApiMessage( text = "MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}"