update update checker

This commit is contained in:
Nikky Ai 2018-03-07 23:03:35 +01:00
parent 4e8fba5725
commit 08affaf9ec
8 changed files with 31 additions and 12 deletions

View File

@ -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()
}

View File

@ -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()
}

View File

@ -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()
}

View File

@ -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()
}

View File

@ -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() {

View File

@ -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) {

View File

@ -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<CurseFile>::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}"
))
}
}

View File

@ -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