From 08affaf9ecaf1a0c9ba1a063974195c2c4187606 Mon Sep 17 00:00:00 2001 From: Nikky Ai Date: Wed, 7 Mar 2018 23:03:35 +0100 Subject: [PATCH] update update checker --- .../src/main/kotlin/matterlink/MatterLink.kt | 2 ++ .../src/main/kotlin/matterlink/MatterLink.kt | 2 ++ .../src/main/kotlin/matterlink/MatterLink.kt | 2 ++ .../src/main/kotlin/matterlink/MatterLink.kt | 2 ++ .../src/main/kotlin/matterlink/IMatterLink.kt | 3 +-- .../matterlink/bridge/MessageHandler.kt | 5 ++++ .../kotlin/matterlink/update/UpdateChecker.kt | 25 ++++++++++++------- gradle.properties | 2 +- 8 files changed, 31 insertions(+), 12 deletions(-) diff --git a/1.10.2/src/main/kotlin/matterlink/MatterLink.kt b/1.10.2/src/main/kotlin/matterlink/MatterLink.kt index 84e28e2..dfdf85b 100644 --- a/1.10.2/src/main/kotlin/matterlink/MatterLink.kt +++ b/1.10.2/src/main/kotlin/matterlink/MatterLink.kt @@ -5,6 +5,7 @@ import matterlink.command.CommandMatterlink import matterlink.command.MatterLinkCommandSender 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.* @@ -64,4 +65,5 @@ object MatterLink : IMatterLink() { override val mcVersion: String = MCVERSION override val modVersion: String = MODVERSION + override val forgeVersion = ForgeVersion.getVersion() } diff --git a/1.11.2/src/main/kotlin/matterlink/MatterLink.kt b/1.11.2/src/main/kotlin/matterlink/MatterLink.kt index 8d3a9f4..fcd57f3 100644 --- a/1.11.2/src/main/kotlin/matterlink/MatterLink.kt +++ b/1.11.2/src/main/kotlin/matterlink/MatterLink.kt @@ -5,6 +5,7 @@ import matterlink.command.CommandMatterlink import matterlink.command.MatterLinkCommandSender 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.* @@ -64,4 +65,5 @@ object MatterLink : IMatterLink() { override val mcVersion: String = MCVERSION override val modVersion: String = MODVERSION + override val forgeVersion = ForgeVersion.getVersion() } diff --git a/1.12.2/src/main/kotlin/matterlink/MatterLink.kt b/1.12.2/src/main/kotlin/matterlink/MatterLink.kt index 95850c0..ae2b0a6 100644 --- a/1.12.2/src/main/kotlin/matterlink/MatterLink.kt +++ b/1.12.2/src/main/kotlin/matterlink/MatterLink.kt @@ -5,6 +5,7 @@ import matterlink.command.CommandMatterlink import matterlink.command.MatterLinkCommandSender 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.* @@ -69,4 +70,5 @@ object MatterLink : IMatterLink() { override val mcVersion: String = MCVERSION override val modVersion: String = MODVERSION + override val forgeVersion = ForgeVersion.getVersion() } diff --git a/1.7.10/src/main/kotlin/matterlink/MatterLink.kt b/1.7.10/src/main/kotlin/matterlink/MatterLink.kt index d3e6087..9f59758 100644 --- a/1.7.10/src/main/kotlin/matterlink/MatterLink.kt +++ b/1.7.10/src/main/kotlin/matterlink/MatterLink.kt @@ -9,6 +9,7 @@ import matterlink.command.MatterLinkCommandSender import matterlink.config.cfg import net.minecraft.server.MinecraftServer import net.minecraft.util.ChatComponentText +import net.minecraftforge.common.ForgeVersion import net.minecraftforge.common.MinecraftForge import org.apache.logging.log4j.Level import org.apache.logging.log4j.Logger @@ -66,4 +67,5 @@ class MatterLink : IMatterLink() { override val mcVersion: String = MCVERSION override val modVersion: String = MODVERSION + override val forgeVersion = ForgeVersion.getVersion() } diff --git a/core/src/main/kotlin/matterlink/IMatterLink.kt b/core/src/main/kotlin/matterlink/IMatterLink.kt index 2bc432f..02d3216 100644 --- a/core/src/main/kotlin/matterlink/IMatterLink.kt +++ b/core/src/main/kotlin/matterlink/IMatterLink.kt @@ -11,6 +11,7 @@ lateinit var instance: IMatterLink abstract class IMatterLink { abstract val mcVersion: String abstract val modVersion: String + abstract val forgeVersion: String abstract fun commandSenderFor(user: String, userId: String, server: String): IMinecraftCommandSender @@ -20,8 +21,6 @@ abstract class IMatterLink { fun start() { serverStartTime = System.currentTimeMillis() MessageHandler.start(clear = true, firstRun = true, message = "Server started, connecting to matterbridge API") - - UpdateChecker.run() } fun stop() { diff --git a/core/src/main/kotlin/matterlink/bridge/MessageHandler.kt b/core/src/main/kotlin/matterlink/bridge/MessageHandler.kt index 615869b..2a74215 100644 --- a/core/src/main/kotlin/matterlink/bridge/MessageHandler.kt +++ b/core/src/main/kotlin/matterlink/bridge/MessageHandler.kt @@ -2,6 +2,7 @@ package matterlink.bridge import matterlink.config.cfg import matterlink.instance +import matterlink.update.UpdateChecker import org.apache.http.client.methods.HttpPost import org.apache.http.entity.ContentType import org.apache.http.entity.StringEntity @@ -68,6 +69,10 @@ object MessageHandler { text = message //?: "Connected to matterbridge API" )) } + + if(firstRun) { + UpdateChecker.run() + } } private fun transmitMessage(message: ApiMessage) { diff --git a/core/src/main/kotlin/matterlink/update/UpdateChecker.kt b/core/src/main/kotlin/matterlink/update/UpdateChecker.kt index 1fd8116..70e4ec4 100644 --- a/core/src/main/kotlin/matterlink/update/UpdateChecker.kt +++ b/core/src/main/kotlin/matterlink/update/UpdateChecker.kt @@ -1,6 +1,9 @@ package matterlink.update -import com.google.gson.Gson +import com.google.gson.FieldNamingPolicy +import com.google.gson.GsonBuilder +import matterlink.bridge.ApiMessage +import matterlink.bridge.MessageHandler import matterlink.config.cfg import matterlink.instance import org.apache.http.HttpResponse @@ -32,15 +35,19 @@ class UpdateChecker : Thread() { return } - val gson = Gson() + val gson = GsonBuilder() + .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) + .create() instance.info("Checking for new versions...") val client: HttpClient = HttpClients.createDefault() - val request = HttpGet("https://goo.gl/5CMc1N") + val request = HttpGet("https://cursemeta.dries007.net/api/v2/direct/GetAllFilesForAddOn/287323") with(instance) { - request.setHeader("User-Agent", "Minecraft/$mcVersion MatterLink/$modVersion") + val useragent = "MatterLink/$modVersion MinecraftForge/$mcVersion-$forgeVersion (https://github.com/elytra/MatterLink)" + instance.debug("setting User-Agent: '$useragent'") + request.setHeader("User-Agent", useragent) } val response: HttpResponse = client.execute(request) @@ -53,7 +60,7 @@ class UpdateChecker : Thread() { gson.fromJson(content, Array::class.java) .filter { - it.fileStatus == "semiNormal" && it.gameVersion.contains(instance.mcVersion) + it.fileStatus == "SemiNormal" && it.gameVersion.contains(instance.mcVersion) } .sortedByDescending { it.fileName.substringAfterLast(" ") } @@ -102,9 +109,9 @@ class UpdateChecker : Thread() { } instance.warn("Mod out of date! New $version available at ${latest.downloadURL}") -// MessageHandler.transmit(ApiMessage( -// username = cfg.relay.systemUser, -// text = "Matterlink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}" -// )) + MessageHandler.transmit(ApiMessage( + username = cfg.outgoing.systemUser, + text = "MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}" + )) } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 20bd86b..897495d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ mod_name = MatterLink -mod_version = 1.5.2 +mod_version = 1.5.3 forgelin_version = 1.6.0 curse_id = 287323 curse_release_type = beta \ No newline at end of file