improve logging

This commit is contained in:
nikky 2018-07-11 20:56:07 +02:00
parent 83501c867f
commit 93c86463c4
23 changed files with 136 additions and 163 deletions

View File

@ -19,8 +19,6 @@ import org.apache.logging.log4j.Level
import org.apache.logging.log4j.Logger import org.apache.logging.log4j.Logger
import java.util.* import java.util.*
lateinit var logger: Logger
@Mod( @Mod(
modid = MODID, modid = MODID,
name = NAME, version = MODVERSION, name = NAME, version = MODVERSION,
@ -37,7 +35,7 @@ object MatterLink : IMatterLink() {
@Mod.EventHandler @Mod.EventHandler
fun preInit(event: FMLPreInitializationEvent) { fun preInit(event: FMLPreInitializationEvent) {
logger = event.modLog logger = event.modLog as org.apache.logging.log4j.core.Logger
logger.info("Building bridge!") logger.info("Building bridge!")
cfg = BaseConfig(event.modConfigurationDirectory).load() cfg = BaseConfig(event.modConfigurationDirectory).load()
@ -79,11 +77,11 @@ object MatterLink : IMatterLink() {
override fun wrappedSendToPlayer(uuid: UUID, msg: String) { override fun wrappedSendToPlayer(uuid: UUID, msg: String) {
val profile = profileByUUID(uuid) ?: run { val profile = profileByUUID(uuid) ?: run {
error("cannot find player by uuid $uuid") logger.error("cannot find player by uuid $uuid")
return return
} }
val player = playerByProfile(profile) ?: run { val player = playerByProfile(profile) ?: run {
error("${profile.name} is not online") logger.error("${profile.name} is not online")
return return
} }
player.sendMessage(TextComponentString(msg)) player.sendMessage(TextComponentString(msg))
@ -97,14 +95,14 @@ object MatterLink : IMatterLink() {
private fun profileByUUID(uuid: UUID): GameProfile? = try { private fun profileByUUID(uuid: UUID): GameProfile? = try {
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getProfileByUUID(uuid) FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getProfileByUUID(uuid)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
warn("cannot find profile by uuid $uuid") logger.warn("cannot find profile by uuid $uuid")
null null
} }
private fun profileByName(username: String): GameProfile? = try { private fun profileByName(username: String): GameProfile? = try {
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getGameProfileForUsername(username) FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getGameProfileForUsername(username)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
warn("cannot find profile by username $username") logger.warn("cannot find profile by username $username")
null null
} }
@ -112,10 +110,6 @@ object MatterLink : IMatterLink() {
override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name 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( override fun commandSenderFor(
user: String, user: String,
env: IBridgeCommand.CommandEnvironment, env: IBridgeCommand.CommandEnvironment,

View File

@ -1,11 +1,13 @@
package matterlink package matterlink
import com.mojang.authlib.GameProfile import com.mojang.authlib.GameProfile
import jline.internal.Log.warn
import matterlink.bridge.command.IBridgeCommand import matterlink.bridge.command.IBridgeCommand
import matterlink.command.MatterLinkCommand import matterlink.command.MatterLinkCommand
import matterlink.command.MatterLinkCommandSender import matterlink.command.MatterLinkCommandSender
import matterlink.config.BaseConfig import matterlink.config.BaseConfig
import matterlink.config.cfg import matterlink.config.cfg
import net.minecraft.entity.ai.EntityMoveHelper
import net.minecraft.entity.player.EntityPlayerMP import net.minecraft.entity.player.EntityPlayerMP
import net.minecraft.util.text.TextComponentString import net.minecraft.util.text.TextComponentString
import net.minecraftforge.common.ForgeVersion import net.minecraftforge.common.ForgeVersion
@ -19,8 +21,6 @@ import org.apache.logging.log4j.Level
import org.apache.logging.log4j.Logger import org.apache.logging.log4j.Logger
import java.util.* import java.util.*
lateinit var logger: Logger
@Mod( @Mod(
modid = MODID, modid = MODID,
name = NAME, version = MODVERSION, name = NAME, version = MODVERSION,
@ -37,7 +37,7 @@ object MatterLink : IMatterLink() {
@Mod.EventHandler @Mod.EventHandler
fun preInit(event: FMLPreInitializationEvent) { fun preInit(event: FMLPreInitializationEvent) {
logger = event.modLog logger = event.modLog as org.apache.logging.log4j.core.Logger
logger.info("Building bridge!") logger.info("Building bridge!")
cfg = BaseConfig(event.modConfigurationDirectory).load() cfg = BaseConfig(event.modConfigurationDirectory).load()
@ -67,11 +67,11 @@ object MatterLink : IMatterLink() {
override fun wrappedSendToPlayer(username: String, msg: String) { override fun wrappedSendToPlayer(username: String, msg: String) {
val profile = profileByName(username) ?: run { val profile = profileByName(username) ?: run {
error("cannot find player by name $username") logger.error("cannot find player by name $username")
return return
} }
val player = playerByProfile(profile) ?: run { val player = playerByProfile(profile) ?: run {
error("${profile.name} is not online") logger.error("${profile.name} is not online")
return return
} }
player.sendMessage(TextComponentString(msg)) player.sendMessage(TextComponentString(msg))
@ -79,11 +79,11 @@ object MatterLink : IMatterLink() {
override fun wrappedSendToPlayer(uuid: UUID, msg: String) { override fun wrappedSendToPlayer(uuid: UUID, msg: String) {
val profile = profileByUUID(uuid) ?: run { val profile = profileByUUID(uuid) ?: run {
error("cannot find player by uuid $uuid") logger.error("cannot find player by uuid $uuid")
return return
} }
val player = playerByProfile(profile) ?: run { val player = playerByProfile(profile) ?: run {
error("${profile.name} is not online") logger.error("${profile.name} is not online")
return return
} }
player.sendMessage(TextComponentString(msg)) player.sendMessage(TextComponentString(msg))
@ -97,14 +97,14 @@ object MatterLink : IMatterLink() {
private fun profileByUUID(uuid: UUID): GameProfile? = try { private fun profileByUUID(uuid: UUID): GameProfile? = try {
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getProfileByUUID(uuid) FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getProfileByUUID(uuid)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
warn("cannot find profile by uuid $uuid") logger.warn("cannot find profile by uuid $uuid")
null null
} }
private fun profileByName(username: String): GameProfile? = try { private fun profileByName(username: String): GameProfile? = try {
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getGameProfileForUsername(username) FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getGameProfileForUsername(username)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
warn("cannot find profile by username $username") logger.warn("cannot find profile by username $username")
null null
} }
@ -112,9 +112,6 @@ object MatterLink : IMatterLink() {
override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name 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( override fun commandSenderFor(
user: String, user: String,
env: IBridgeCommand.CommandEnvironment, env: IBridgeCommand.CommandEnvironment,

View File

@ -49,15 +49,10 @@ object EventHandler {
@SubscribeEvent @SubscribeEvent
@JvmStatic @JvmStatic
fun commandEvent(e: CommandEvent) { 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 { val sender = when {
e.sender is DedicatedServer -> cfg.outgoing.systemUser e.sender is DedicatedServer -> cfg.outgoing.systemUser
else -> e.sender.displayName.unformattedText else -> e.sender.displayName.unformattedText
} }
instance.log("DEBUG","sender $sender")
val args = e.parameters.joinToString(" ") val args = e.parameters.joinToString(" ")
val type = when { val type = when {
e.command is CommandEmote -> USER_ACTION e.command is CommandEmote -> USER_ACTION

View File

@ -1,6 +1,7 @@
package matterlink package matterlink
import com.mojang.authlib.GameProfile import com.mojang.authlib.GameProfile
import jline.internal.Log.warn
import matterlink.bridge.command.IBridgeCommand import matterlink.bridge.command.IBridgeCommand
import matterlink.command.AuthCommand import matterlink.command.AuthCommand
import matterlink.command.MatterLinkCommand 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.FMLServerStartingEvent
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent import net.minecraftforge.fml.common.event.FMLServerStoppingEvent
import org.apache.logging.log4j.Level import org.apache.logging.log4j.Level
import org.apache.logging.log4j.Logger import org.apache.logging.log4j.core.config.Configurator
import java.util.* import java.util.*
lateinit var logger: Logger
@Mod( @Mod(
modid = MODID, modid = MODID,
@ -34,12 +34,14 @@ lateinit var logger: Logger
object MatterLink : IMatterLink() { object MatterLink : IMatterLink() {
init { init {
Configurator.setLevel(MODID, Level.DEBUG)
instance = this instance = this
} }
@Mod.EventHandler @Mod.EventHandler
fun preInit(event: FMLPreInitializationEvent) { 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!") logger.info("Building bridge!")
cfg = BaseConfig(event.modConfigurationDirectory).load() cfg = BaseConfig(event.modConfigurationDirectory).load()
@ -52,7 +54,7 @@ object MatterLink : IMatterLink() {
@Mod.EventHandler @Mod.EventHandler
fun serverStarting(event: FMLServerStartingEvent) { fun serverStarting(event: FMLServerStartingEvent) {
log("DEBUG", "Registering server commands") logger.debug("Registering server commands")
event.registerServerCommand(MatterLinkCommand()) event.registerServerCommand(MatterLinkCommand())
event.registerServerCommand(AuthCommand()) event.registerServerCommand(AuthCommand())
start() start()
@ -70,11 +72,11 @@ object MatterLink : IMatterLink() {
override fun wrappedSendToPlayer(username: String, msg: String) { override fun wrappedSendToPlayer(username: String, msg: String) {
val profile = profileByName(username) ?: run { val profile = profileByName(username) ?: run {
error("cannot find player by name $username") logger.error("cannot find player by name $username")
return return
} }
val player = playerByProfile(profile) ?: run { val player = playerByProfile(profile) ?: run {
error("${profile.name} is not online") logger.error("${profile.name} is not online")
return return
} }
player.sendMessage(TextComponentString(msg)) player.sendMessage(TextComponentString(msg))
@ -82,11 +84,11 @@ object MatterLink : IMatterLink() {
override fun wrappedSendToPlayer(uuid: UUID, msg: String) { override fun wrappedSendToPlayer(uuid: UUID, msg: String) {
val profile = profileByUUID(uuid) ?: run { val profile = profileByUUID(uuid) ?: run {
error("cannot find player by uuid $uuid") logger.error("cannot find player by uuid $uuid")
return return
} }
val player = playerByProfile(profile) ?: run { val player = playerByProfile(profile) ?: run {
error("${profile.name} is not online") logger.error("${profile.name} is not online")
return return
} }
player.sendMessage(TextComponentString(msg)) player.sendMessage(TextComponentString(msg))
@ -115,8 +117,8 @@ object MatterLink : IMatterLink() {
override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name
override fun log(level: String, formatString: String, vararg data: Any) = // override fun log(level: String, formatString: String, vararg data: Any) =
logger.log(Level.toLevel(level, Level.INFO), formatString, *data) // logger.log(Level.toLevel(level, Level.INFO), formatString, *data)
override fun commandSenderFor( override fun commandSenderFor(
user: String, user: String,

View File

@ -21,8 +21,6 @@ import org.apache.logging.log4j.Level
import org.apache.logging.log4j.Logger import org.apache.logging.log4j.Logger
import java.util.* import java.util.*
lateinit var logger: Logger
@Mod( @Mod(
modid = MODID, modid = MODID,
name = NAME, version = MODVERSION, name = NAME, version = MODVERSION,
@ -39,7 +37,7 @@ class MatterLink : IMatterLink() {
MinecraftForge.EVENT_BUS.register(EventHandler) MinecraftForge.EVENT_BUS.register(EventHandler)
FMLCommonHandler.instance().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!") logger.info("Building bridge!")
cfg = BaseConfig(event.modConfigurationDirectory).load() cfg = BaseConfig(event.modConfigurationDirectory).load()
@ -69,11 +67,11 @@ class MatterLink : IMatterLink() {
override fun wrappedSendToPlayer(username: String, msg: String) { override fun wrappedSendToPlayer(username: String, msg: String) {
val profile = profileByName(username) ?: run { val profile = profileByName(username) ?: run {
error("cannot find player by name $username") logger.error("cannot find player by name $username")
return return
} }
val player = playerByProfile(profile) ?: run { val player = playerByProfile(profile) ?: run {
error("${profile.name} is not online") logger.error("${profile.name} is not online")
return return
} }
player.addChatMessage(ChatComponentText(msg)) player.addChatMessage(ChatComponentText(msg))
@ -81,11 +79,11 @@ class MatterLink : IMatterLink() {
override fun wrappedSendToPlayer(uuid: UUID, msg: String) { override fun wrappedSendToPlayer(uuid: UUID, msg: String) {
val profile = profileByUUID(uuid) ?: run { val profile = profileByUUID(uuid) ?: run {
error("cannot find player by uuid $uuid") logger.error("cannot find player by uuid $uuid")
return return
} }
val player = playerByProfile(profile) ?: run { val player = playerByProfile(profile) ?: run {
error("${profile.name} is not online") logger.error("${profile.name} is not online")
return return
} }
player.addChatMessage(ChatComponentText(msg)) player.addChatMessage(ChatComponentText(msg))
@ -101,14 +99,14 @@ class MatterLink : IMatterLink() {
private fun profileByUUID(uuid: UUID): GameProfile? = try { private fun profileByUUID(uuid: UUID): GameProfile? = try {
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.func_152652_a(uuid) FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.func_152652_a(uuid)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
warn("cannot find profile by uuid $uuid") logger.warn("cannot find profile by uuid $uuid")
null null
} }
private fun profileByName(username: String): GameProfile? = try { private fun profileByName(username: String): GameProfile? = try {
FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getGameProfileForUsername(username) FMLCommonHandler.instance().minecraftServerInstance.playerProfileCache.getGameProfileForUsername(username)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
warn("cannot find profile by username $username") logger.warn("cannot find profile by username $username")
null null
} }
@ -116,9 +114,6 @@ class MatterLink : IMatterLink() {
override fun uuidToName(uuid: UUID): String? = profileByUUID(uuid)?.name 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( override fun commandSenderFor(
user: String, user: String,
env: IBridgeCommand.CommandEnvironment, env: IBridgeCommand.CommandEnvironment,

@ -1 +1 @@
Subproject commit bb136c12e3ae50498b3435fc11dbd833efdb6a1c Subproject commit 93ab86ee821380584c22ac60d77737388976e531

2
api

@ -1 +1 @@
Subproject commit 15e4d115dd0e1ac1e5d287c48d6dc76a6a488ed7 Subproject commit 75138cec00c66d479709f4b44d78ca3005993474

View File

@ -1,5 +1,5 @@
plugins { plugins {
id "org.jetbrains.kotlin.jvm" version '1.2.51' id "org.jetbrains.kotlin.jvm" version '1.2.41'
id 'idea' id 'idea'
} }

View File

@ -26,7 +26,9 @@ dependencies {
compile project(":Jankson") 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.code.gson', name: 'gson', version: '+'
compile group: 'com.google.guava', name: 'guava', version: '+' compile group: 'com.google.guava', name: 'guava', version: '+'

View File

@ -1,14 +1,17 @@
package matterlink package matterlink
import matterlink.api.MessageHandler
import matterlink.bridge.MessageHandlerInst import matterlink.bridge.MessageHandlerInst
import matterlink.bridge.command.BridgeCommandRegistry import matterlink.bridge.command.BridgeCommandRegistry
import matterlink.bridge.command.IBridgeCommand import matterlink.bridge.command.IBridgeCommand
import matterlink.bridge.command.IMinecraftCommandSender import matterlink.bridge.command.IMinecraftCommandSender
import matterlink.config.cfg import matterlink.config.cfg
import matterlink.update.UpdateChecker import matterlink.update.UpdateChecker
import org.apache.logging.log4j.core.Logger
import java.util.* import java.util.*
lateinit var instance: IMatterLink lateinit var instance: IMatterLink
lateinit var logger: Logger
abstract class IMatterLink { abstract class IMatterLink {
abstract val mcVersion: String abstract val mcVersion: String
@ -26,16 +29,17 @@ abstract class IMatterLink {
abstract fun uuidToName(uuid: UUID): String? abstract fun uuidToName(uuid: UUID): String?
fun start() { fun start() {
MessageHandlerInst.logger = { level, msg -> // MessageHandlerInst.logger = { level, msg ->
when (level) { // when (level) {
"FATAL" -> fatal(msg) // "FATAL" -> logger.fatal(msg)
"ERROR" -> error(msg) // "ERROR" -> logger.error(msg)
"WARN" -> warn(msg) // "WARN" -> logger.warn(msg)
"INFO" -> info(msg) // "INFO" -> logger.info(msg)
"DEBUG" -> debug(msg) // "DEBUG" -> logger.debug(msg)
"TRACE" -> trace(msg) // "TRACE" -> logger.trace(msg)
} // }
} // }
MessageHandlerInst.logger = logger
serverStartTime = System.currentTimeMillis() serverStartTime = System.currentTimeMillis()
if (cfg.connect.autoConnect) if (cfg.connect.autoConnect)
@ -47,22 +51,22 @@ abstract class IMatterLink {
MessageHandlerInst.stop("Server shutting down, disconnecting from matterbridge API") 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 fatal(formatString: String, vararg data: Any) = log("FATAL", formatString, *data)
fun error(formatString: String, vararg data: Any) = log("ERROR", 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 warn(formatString: String, vararg data: Any) = log("WARN", formatString, *data)
fun info(formatString: String, vararg data: Any) = log("INFO", formatString, *data) // fun info(formatString: String, vararg data: Any) = log("INFO", formatString, *data)
//
fun debug(formatString: String, vararg data: Any) { // fun debug(formatString: String, vararg data: Any) {
if (cfg.debug.logLevel == "DEBUG" || cfg.debug.logLevel == "TRACE") // if (cfg.debug.logLevel == "DEBUG" || cfg.debug.logLevel == "TRACE")
log("INFO", "DEBUG: " + formatString.replace("\n", "\nDEBUG: "), *data) // log("INFO", "DEBUG: " + formatString.replace("\n", "\nDEBUG: "), *data)
} // }
//
fun trace(formatString: String, vararg data: Any) { // fun trace(formatString: String, vararg data: Any) {
if (cfg.debug.logLevel == "TRACE") // if (cfg.debug.logLevel == "TRACE")
log("INFO", "TRACE: " + formatString.replace("\n", "\nTRACE: "), *data) // log("INFO", "TRACE: " + formatString.replace("\n", "\nTRACE: "), *data)
} // }
/** /**
* in milliseconds * in milliseconds

View File

@ -85,7 +85,7 @@ object PasteUtil {
} }
val textResponse = http.inputStream.bufferedReader().use { it.readText() } val textResponse = http.inputStream.bufferedReader().use { it.readText() }
instance.debug("response: $textResponse") logger.debug("response: $textResponse")
// val jsonObject = jankson.load(http.inputStream) // val jsonObject = jankson.load(http.inputStream)
return jankson.fromJson(textResponse) return jankson.fromJson(textResponse)
} }

View File

@ -67,7 +67,7 @@ fun randomString(length: Int = 6): String =
java.util.UUID.randomUUID().toString().replace("-", "").take(length) java.util.UUID.randomUUID().toString().replace("-", "").take(length)
fun <T : Any> JsonObject.getOrDefault(key: String, default: T, comment: String? = null): T { fun <T : Any> 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)!! return putDefault(key, default, comment)!!
} }

View File

@ -11,7 +11,7 @@ object MessageHandlerInst : MessageHandler() {
} }
fun transmit(msg: ApiMessage, cause: String, maxLines: Int = cfg.outgoing.inlineLimit) { 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 { try {
val response = PasteUtil.paste( val response = PasteUtil.paste(
Paste( Paste(
@ -20,15 +20,15 @@ object MessageHandlerInst : MessageHandler() {
PasteSection( PasteSection(
name = "log.txt", name = "log.txt",
syntax = "text", syntax = "text",
contents = msg.text.replace("\n", "\\n") contents = msg.text
) )
) )
) )
) )
msg.text = msg.text.substringBefore('\n') msg.text = msg.text.substringBefore('\n')
.take(20) + "... " + response.link .take(25) + "... " + response.link
} catch(e: Exception) { } catch(e: Exception) {
instance.error(e.stackTraceString) logger.error(e.stackTraceString)
} }
} }
super.transmit(msg) super.transmit(msg)

View File

@ -7,6 +7,7 @@ import matterlink.config.IdentitiesConfig
import matterlink.config.PermissionConfig import matterlink.config.PermissionConfig
import matterlink.config.cfg import matterlink.config.cfg
import matterlink.instance import matterlink.instance
import matterlink.logger
import matterlink.stripColorOut import matterlink.stripColorOut
import java.util.* import java.util.*
@ -31,7 +32,7 @@ object BridgeCommandRegistry {
val env = IBridgeCommand.CommandEnvironment.BridgeEnv(input.username, input.userid, input.account, uuid) val env = IBridgeCommand.CommandEnvironment.BridgeEnv(input.username, input.userid, input.account, uuid)
return commandMap[cmd[0]]?.let { return commandMap[cmd[0]]?.let {
if (!it.reachedTimeout()) { if (!it.reachedTimeout()) {
instance.debug("dropped command ${it.alias}") logger.debug("dropped command ${it.alias}")
return false return false
} }
it.preExecute() // resets the tickCounter it.preExecute() // resets the tickCounter
@ -57,7 +58,7 @@ object BridgeCommandRegistry {
return commandMap[cmd[0]]?.let { return commandMap[cmd[0]]?.let {
if (!it.reachedTimeout()) { if (!it.reachedTimeout()) {
instance.debug("dropped command ${it.alias}") logger.debug("dropped command ${it.alias}")
return false return false
} }
it.preExecute() // resets the tickCounter it.preExecute() // resets the tickCounter
@ -74,11 +75,11 @@ object BridgeCommandRegistry {
fun register(alias: String, cmd: IBridgeCommand): Boolean { fun register(alias: String, cmd: IBridgeCommand): Boolean {
if (alias.isBlank() || commandMap.containsKey(alias)) { if (alias.isBlank() || commandMap.containsKey(alias)) {
instance.error("Failed to register command: '$alias'") logger.error("Failed to register command: '$alias'")
return false return false
} }
if (!cmd.validate()) { if (!cmd.validate()) {
instance.error("Failed to validate command: '$alias'") logger.error("Failed to validate command: '$alias'")
return false return false
} }
//TODO: maybe write alias to command here ? //TODO: maybe write alias to command here ?

View File

@ -2,6 +2,7 @@ package matterlink.bridge.command
import matterlink.instance import matterlink.instance
import matterlink.lazyFormat import matterlink.lazyFormat
import matterlink.logger
import matterlink.stripColorIn import matterlink.stripColorIn
data class CustomCommand( data class CustomCommand(
@ -18,7 +19,7 @@ data class CustomCommand(
override fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean { override fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean {
if (argumentsRegex != null) { if (argumentsRegex != null) {
instance.debug("testing '$args' against '${argumentsRegex.pattern}'") logger.debug("testing '$args' against '${argumentsRegex.pattern}'")
if (!argumentsRegex.matches(args)) { if (!argumentsRegex.matches(args)) {
env.respond("$user sent invalid input to command $alias") env.respond("$user sent invalid input to command $alias")
return false return false

View File

@ -6,6 +6,7 @@ import matterlink.config.PermissionConfig
import matterlink.config.cfg import matterlink.config.cfg
import matterlink.handlers.TickHandler import matterlink.handlers.TickHandler
import matterlink.instance import matterlink.instance
import matterlink.logger
import matterlink.stripColorOut import matterlink.stripColorOut
import java.util.* import java.util.*
@ -72,9 +73,9 @@ abstract class IBridgeCommand {
abstract fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean abstract fun execute(alias: String, user: String, env: CommandEnvironment, args: String): Boolean
fun canExecute(uuid: UUID?): 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 val canExec = getPermLevel(uuid) >= permLevel
instance.trace("canExecute return $canExec") logger.trace("canExecute return $canExec")
return canExec return canExec
} }

View File

@ -4,11 +4,8 @@ import blue.endless.jankson.Jankson
import blue.endless.jankson.JsonObject import blue.endless.jankson.JsonObject
import blue.endless.jankson.impl.Marshaller import blue.endless.jankson.impl.Marshaller
import blue.endless.jankson.impl.SyntaxError import blue.endless.jankson.impl.SyntaxError
import matterlink.*
import matterlink.bridge.MessageHandlerInst import matterlink.bridge.MessageHandlerInst
import matterlink.getOrDefault
import matterlink.instance
import matterlink.registerTypeAdapter
import matterlink.stackTraceString
import java.io.File import java.io.File
import java.io.FileNotFoundException import java.io.FileNotFoundException
@ -20,13 +17,12 @@ data class BaseConfig(val rootDir: File) {
val configFile: File = cfgDirectory.resolve("matterlink.hjson") val configFile: File = cfgDirectory.resolve("matterlink.hjson")
init { init {
instance.info("Reading bridge blueprints... from {}", rootDir) logger.info("Reading bridge blueprints... from {}", rootDir)
baseCfg = this baseCfg = this
} }
data class MatterLinkConfig( data class MatterLinkConfig(
val connect: ConnectOptions = ConnectOptions(), val connect: ConnectOptions = ConnectOptions(),
val debug: DebugOptions = DebugOptions(),
val incoming: IncomingOptions = IncomingOptions(), val incoming: IncomingOptions = IncomingOptions(),
val outgoing: OutgoingOptions = OutgoingOptions(), val outgoing: OutgoingOptions = OutgoingOptions(),
val command: CommandOptions = CommandOptions(), val command: CommandOptions = CommandOptions(),
@ -51,10 +47,6 @@ data class BaseConfig(val rootDir: File) {
val reconnectWait: Long = 500 val reconnectWait: Long = 500
) )
data class DebugOptions(
val logLevel: String = "INFO"
)
data class IncomingOptions( data class IncomingOptions(
val chat: String = "<{username}> {text}", val chat: String = "<{username}> {text}",
val joinPart: String = "§6-- {username} {text}", val joinPart: String = "§6-- {username} {text}",
@ -137,11 +129,6 @@ data class BaseConfig(val rootDir: File) {
ConnectOptions(), ConnectOptions(),
"Connection Settings" "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 = it.getOrDefault(
"incoming", "incoming",
IncomingOptions(), IncomingOptions(),
@ -229,13 +216,6 @@ data class BaseConfig(val rootDir: File) {
) )
} }
} }
.registerTypeAdapter {
with(DebugOptions()) {
DebugOptions(
logLevel = it.getOrDefault("loglevel", logLevel, "MatterLink log level")
)
}
}
.registerTypeAdapter { .registerTypeAdapter {
with(IncomingOptions()) { with(IncomingOptions()) {
IncomingOptions( IncomingOptions(
@ -384,33 +364,34 @@ data class BaseConfig(val rootDir: File) {
val jsonObject = try { val jsonObject = try {
jankson.load(configFile) jankson.load(configFile)
} catch (e: SyntaxError) { } catch (e: SyntaxError) {
instance.error("error loading config: ${e.completeMessage}") logger.error("error loading config: ${e.completeMessage}")
jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject
} catch (e: FileNotFoundException) { } catch (e: FileNotFoundException) {
instance.error("creating config file $configFile") logger.error("creating config file $configFile")
configFile.absoluteFile.parentFile.mkdirs() configFile.absoluteFile.parentFile.mkdirs()
configFile.createNewFile() configFile.createNewFile()
jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject jankson.marshaller.serialize(MatterLinkConfig()) as JsonObject
} }
instance.info("finished loading base config") logger.info("finished loading base config")
val tmpCfg = try { val tmpCfg = try {
//cfgDirectory.resolve("debug.matterlink.hjson").writeText(jsonObject.toJson(false, true)) //cfgDirectory.resolve("debug.matterlink.hjson").writeText(jsonObject.toJson(false, true))
jankson.fromJson(jsonObject, MatterLinkConfig::class.java).apply { jankson.fromJson(jsonObject, MatterLinkConfig::class.java).apply {
configFile.writeText(jsonObject.toJson(true, true)) 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) { } catch (e: SyntaxError) {
instance.error("error parsing config: ${e.completeMessage} ") logger.error("error parsing config: ${e.completeMessage} ")
instance.error(e.stackTraceString) logger.error(e.stackTraceString)
cfgDirectory.resolve("error.matterlink.hjson").writeText(jsonObject.toJson(false, true)) cfgDirectory.resolve("error.matterlink.hjson").writeText(jsonObject.toJson(false, true))
MatterLinkConfig() MatterLinkConfig()
} catch (e: IllegalStateException) { } catch (e: IllegalStateException) {
instance.error(e.stackTraceString) logger.error(e.stackTraceString)
cfgDirectory.resolve("error.matterlink.hjson").writeText(jsonObject.toJson(false, true)) cfgDirectory.resolve("error.matterlink.hjson").writeText(jsonObject.toJson(false, true))
MatterLinkConfig() MatterLinkConfig()
} catch (e: NullPointerException) { } 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)) cfgDirectory.resolve("error.matterlink.hjson").writeText(jsonObject.toJson(false, true))
MatterLinkConfig() MatterLinkConfig()
} }

View File

@ -4,12 +4,9 @@ import blue.endless.jankson.Jankson
import blue.endless.jankson.JsonObject import blue.endless.jankson.JsonObject
import blue.endless.jankson.JsonPrimitive import blue.endless.jankson.JsonPrimitive
import blue.endless.jankson.impl.SyntaxError import blue.endless.jankson.impl.SyntaxError
import matterlink.*
import matterlink.bridge.command.CommandType import matterlink.bridge.command.CommandType
import matterlink.bridge.command.CustomCommand import matterlink.bridge.command.CustomCommand
import matterlink.getOrDefault
import matterlink.instance
import matterlink.registerPrimitiveTypeAdapter
import matterlink.registerTypeAdapter
import java.io.File import java.io.File
import java.io.FileNotFoundException import java.io.FileNotFoundException
@ -103,7 +100,7 @@ object CommandConfig {
val jsonObject = try { val jsonObject = try {
jankson.load(configFile) jankson.load(configFile)
} catch (e: SyntaxError) { } catch (e: SyntaxError) {
instance.error("error parsing config: ${e.completeMessage}") logger.error("error parsing config: ${e.completeMessage}")
JsonObject() JsonObject()
} catch (e: FileNotFoundException) { } catch (e: FileNotFoundException) {
configFile.createNewFile() configFile.createNewFile()
@ -112,13 +109,13 @@ object CommandConfig {
// clear commands // clear commands
commands.clear() commands.clear()
jsonObject.forEach { key, element -> jsonObject.forEach { key, element ->
instance.trace("loading command '$key'") logger.trace("loading command '$key'")
val command = jsonObject.get(CustomCommand::class.java, key) val command = jsonObject.get(CustomCommand::class.java, key)
if (command != null) if (command != null)
commands[key] = command commands[key] = command
else { else {
instance.error("could not parse key: $key, value: '$element' as CustomCommand") logger.error("could not parse key: $key, value: '$element' as CustomCommand")
instance.error("skipping $key") logger.error("skipping $key")
} }
} }
@ -131,8 +128,8 @@ object CommandConfig {
} }
} }
instance.debug("loaded jsonObj: $jsonObject") logger.debug("loaded jsonObj: $jsonObject")
instance.debug("loaded commandMap: $commands") logger.debug("loaded commandMap: $commands")
val defaultJsonObject = jankson.marshaller.serialize(CustomCommand.DEFAULT) as JsonObject val defaultJsonObject = jankson.marshaller.serialize(CustomCommand.DEFAULT) as JsonObject
val nonDefaultJsonObj = jsonObject.clone() val nonDefaultJsonObj = jsonObject.clone()

View File

@ -7,8 +7,7 @@ import blue.endless.jankson.impl.SyntaxError
import com.google.common.cache.Cache import com.google.common.cache.Cache
import com.google.common.cache.CacheBuilder import com.google.common.cache.CacheBuilder
import matterlink.getList import matterlink.getList
import matterlink.getOrDefault import matterlink.logger
import matterlink.instance
import java.io.File import java.io.File
import java.io.FileNotFoundException import java.io.FileNotFoundException
import java.util.* import java.util.*
@ -53,13 +52,13 @@ object IdentitiesConfig {
val jsonUserMap = this.putDefault(uuid, JsonObject(), uuidComment) val jsonUserMap = this.putDefault(uuid, JsonObject(), uuidComment)
if (jsonUserMap is JsonObject) { if (jsonUserMap is JsonObject) {
userMap.forEach { platform, (user, comment) -> 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) val element = Marshaller.getFallback().serialize(user)
jsonUserMap.putDefault(platform, element, comment.takeUnless { it.isBlank() }) jsonUserMap.putDefault(platform, element, comment.takeUnless { it.isBlank() })
} }
this[uuid] = jsonUserMap this[uuid] = jsonUserMap
} else { } 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 { jsonObject = try {
jankson.load(configFile) jankson.load(configFile)
} catch (e: SyntaxError) { } catch (e: SyntaxError) {
instance.error("error parsing config: ${e.completeMessage}") logger.error("error parsing config: ${e.completeMessage}")
save = false save = false
defaultJsonObject defaultJsonObject
} catch (e: FileNotFoundException) { } 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() configFile.createNewFile()
defaultJsonObject defaultJsonObject
} }
@ -86,7 +85,7 @@ object IdentitiesConfig {
val identMap: MutableMap<String, List<String>> = tmpIdents[uuid]?.toMutableMap() ?: mutableMapOf() val identMap: MutableMap<String, List<String>> = tmpIdents[uuid]?.toMutableMap() ?: mutableMapOf()
if (jsonIdentifier is JsonObject) { if (jsonIdentifier is JsonObject) {
jsonIdentifier.forEach { platform, user -> jsonIdentifier.forEach { platform, user ->
instance.info("$uuid $platform $user") logger.info("$uuid $platform $user")
identMap[platform] = jsonIdentifier.getList(platform) ?: emptyList() identMap[platform] = jsonIdentifier.getList(platform) ?: emptyList()
} }
} }
@ -94,7 +93,7 @@ object IdentitiesConfig {
} }
idents = tmpIdents.toMap() idents = tmpIdents.toMap()
instance.info("Identities loaded") logger.info("Identities loaded")
if (save) if (save)
configFile.writeText(jsonObject.toJson(true, true)) configFile.writeText(jsonObject.toJson(true, true))
@ -119,7 +118,7 @@ object IdentitiesConfig {
return idents.entries.firstOrNull { (uuid, usermap) -> return idents.entries.firstOrNull { (uuid, usermap) ->
usermap.entries.any { (_platform, userids) -> usermap.entries.any { (_platform, userids) ->
if (platform.equals(_platform, true)) if (platform.equals(_platform, true))
instance.info("platform: $_platform userids: $userids") logger.info("platform: $_platform userids: $userids")
platform.equals(_platform, true) && userids.contains(userid) platform.equals(_platform, true) && userids.contains(userid)
} }
}?.key?.let { UUID.fromString(it) } }?.key?.let { UUID.fromString(it) }

View File

@ -7,6 +7,7 @@ import com.google.common.cache.Cache
import com.google.common.cache.CacheBuilder import com.google.common.cache.CacheBuilder
import matterlink.getReified import matterlink.getReified
import matterlink.instance import matterlink.instance
import matterlink.logger
import java.io.File import java.io.File
import java.io.FileNotFoundException import java.io.FileNotFoundException
import java.util.* import java.util.*
@ -49,11 +50,11 @@ object PermissionConfig {
jsonObject = try { jsonObject = try {
jankson.load(configFile) jankson.load(configFile)
} catch (e: SyntaxError) { } catch (e: SyntaxError) {
instance.error("error parsing config: ${e.completeMessage}") logger.error("error parsing config: ${e.completeMessage}")
save = false save = false
defaultJsonObject defaultJsonObject
} catch (e: FileNotFoundException) { } 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() configFile.createNewFile()
defaultJsonObject defaultJsonObject
} }
@ -66,13 +67,13 @@ object PermissionConfig {
for ((uuid, powerlevel) in jsonObject) { for ((uuid, powerlevel) in jsonObject) {
val tmpLevel = jsonObject.getReified<Double>(uuid) val tmpLevel = jsonObject.getReified<Double>(uuid)
if (tmpLevel == null) { if (tmpLevel == null) {
instance.warn("cannot parse permission uuid: $uuid level: $powerlevel") logger.warn("cannot parse permission uuid: $uuid level: $powerlevel")
continue continue
} }
tmpPerms[uuid] = tmpLevel tmpPerms[uuid] = tmpLevel
} }
instance.info("Permissions reloaded") logger.info("Permissions reloaded")
if (save) if (save)
configFile.writeText(jsonObject.toJson(true, true)) configFile.writeText(jsonObject.toJson(true, true))

View File

@ -4,6 +4,7 @@ import matterlink.api.ApiMessage
import matterlink.bridge.MessageHandlerInst import matterlink.bridge.MessageHandlerInst
import matterlink.bridge.command.BridgeCommandRegistry import matterlink.bridge.command.BridgeCommandRegistry
import matterlink.instance import matterlink.instance
import matterlink.logger
import matterlink.stripColorOut import matterlink.stripColorOut
import java.util.* import java.util.*
@ -23,7 +24,7 @@ object ChatProcessor {
), ),
cause = "Message from $user" cause = "Message from $user"
) )
else -> instance.warn("WARN: dropped blank message by '$user'") else -> logger.warn("WARN: dropped blank message by '$user'")
} }
return false return false
} }

View File

@ -5,6 +5,7 @@ import matterlink.bridge.command.BridgeCommandRegistry
import matterlink.bridge.format import matterlink.bridge.format
import matterlink.config.cfg import matterlink.config.cfg
import matterlink.instance import matterlink.instance
import matterlink.logger
import matterlink.stripColorIn import matterlink.stripColorIn
object ServerChatHandler { object ServerChatHandler {
@ -14,7 +15,7 @@ object ServerChatHandler {
*/ */
fun writeIncomingToChat() { fun writeIncomingToChat() {
if (MessageHandlerInst.queue.isNotEmpty()) if (MessageHandlerInst.queue.isNotEmpty())
instance.debug("incoming: " + MessageHandlerInst.queue.toString()) logger.debug("incoming: " + MessageHandlerInst.queue.toString())
val nextMessage = MessageHandlerInst.queue.poll() ?: null val nextMessage = MessageHandlerInst.queue.poll() ?: null
if (nextMessage?.gateway == cfg.connect.gateway) { if (nextMessage?.gateway == cfg.connect.gateway) {
@ -32,11 +33,11 @@ object ServerChatHandler {
val user = nextMessage.username val user = nextMessage.username
val text = nextMessage.text val text = nextMessage.text
val json = nextMessage.encode() val json = nextMessage.encode()
instance.debug("Threw out message with unhandled event: ${nextMessage.event}") logger.debug("Threw out message with unhandled event: ${nextMessage.event}")
instance.debug(" Message contents:") logger.debug(" Message contents:")
instance.debug(" User: $user") logger.debug(" User: $user")
instance.debug(" Text: $text") logger.debug(" Text: $text")
instance.debug(" JSON: $json") logger.debug(" JSON: $json")
return return
} }
} }

View File

@ -6,6 +6,7 @@ import matterlink.api.ApiMessage
import matterlink.bridge.MessageHandlerInst import matterlink.bridge.MessageHandlerInst
import matterlink.config.cfg import matterlink.config.cfg
import matterlink.instance import matterlink.instance
import matterlink.logger
import java.io.BufferedReader import java.io.BufferedReader
import java.net.HttpURLConnection import java.net.HttpURLConnection
import java.net.URL import java.net.URL
@ -25,11 +26,11 @@ class UpdateChecker : Thread() {
override fun run() { override fun run() {
if (instance.modVersion.contains("-build")) { if (instance.modVersion.contains("-build")) {
instance.debug("Not checking updates on Jenkins build") logger.debug("Not checking updates on Jenkins build")
return return
} }
if (instance.modVersion.contains("-dev")) { if (instance.modVersion.contains("-dev")) {
instance.debug("Not checking updates on developer build") logger.debug("Not checking updates on developer build")
return return
} }
@ -37,14 +38,14 @@ class UpdateChecker : Thread() {
.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
.create() .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 url = URL("https://cursemeta.dries007.net/api/v2/direct/GetAllFilesForAddOn/287323")
val con = url.openConnection() as HttpURLConnection val con = url.openConnection() as HttpURLConnection
with(instance) { with(instance) {
val useragent = "MatterLink/$modVersion MinecraftForge/$mcVersion-$forgeVersion (https://github.com/elytra/MatterLink)" 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) con.setRequestProperty("User-Agent", useragent)
} }
@ -55,7 +56,7 @@ class UpdateChecker : Thread() {
//put all of the buffer content onto the string //put all of the buffer content onto the string
val content = buffer.readText() val content = buffer.readText()
instance.trace("updateData: $content") logger.trace("updateData: $content")
gson.fromJson(content, Array<CurseFile>::class.java) gson.fromJson(content, Array<CurseFile>::class.java)
.filter { .filter {
@ -64,7 +65,7 @@ class UpdateChecker : Thread() {
.sortedByDescending { it.fileName.substringAfterLast(" ") } .sortedByDescending { it.fileName.substringAfterLast(" ") }
} else { } else {
instance.error("Could not check for updates!") logger.error("Could not check for updates!")
return return
} }
@ -78,13 +79,13 @@ class UpdateChecker : Thread() {
val possibleUpdates = mutableListOf<CurseFile>() val possibleUpdates = mutableListOf<CurseFile>()
apiUpdateList.forEach { apiUpdateList.forEach {
instance.debug(it.toString()) logger.debug(it.toString())
val version = it.fileName.substringAfterLast("-").split('.').map { it.toInt() } val version = it.fileName.substringAfterLast("-").split('.').map { it.toInt() }
var bigger = false var bigger = false
version.forEachIndexed { index, chunk -> version.forEachIndexed { index, chunk ->
if (!bigger) { if (!bigger) {
val currentChunk = modVersionChunks.getOrNull(index) ?: 0 val currentChunk = modVersionChunks.getOrNull(index) ?: 0
instance.debug("$chunk > $currentChunk") logger.debug("$chunk > $currentChunk")
if (chunk < currentChunk) if (chunk < currentChunk)
return@forEach return@forEach
@ -102,12 +103,12 @@ class UpdateChecker : Thread() {
val count = possibleUpdates.count() val count = possibleUpdates.count()
val version = if (count == 1) "version" else "versions" 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 { 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( MessageHandlerInst.transmit(
ApiMessage( ApiMessage(
text = "MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}" text = "MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}"