From d773c8537d29eaa065f97134672576bdd4c24eda Mon Sep 17 00:00:00 2001 From: Jannik Reimers Date: Thu, 13 Jun 2024 23:25:50 +0200 Subject: [PATCH] wo ist denn hier das wohnzimmer --- build.gradle.kts | 1 + .../kotlin/moe/jansel/platinum/Platinum.kt | 33 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3707677..c2f2d97 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,6 @@ plugins { kotlin("jvm") version "2.0.0" + kotlin("plugin.serialization") version "1.7.0" id("io.github.goooler.shadow") version "8.1.7" id("net.kyori.blossom") version "2.1.0" id("net.kyori.indra.git") version "3.1.3" diff --git a/src/main/kotlin/moe/jansel/platinum/Platinum.kt b/src/main/kotlin/moe/jansel/platinum/Platinum.kt index 914c90a..e8c2ea1 100644 --- a/src/main/kotlin/moe/jansel/platinum/Platinum.kt +++ b/src/main/kotlin/moe/jansel/platinum/Platinum.kt @@ -1,14 +1,22 @@ package moe.jansel.platinum import io.ktor.client.* +import io.ktor.client.call.* import io.ktor.client.engine.cio.* import io.ktor.client.plugins.* import io.ktor.client.plugins.contentnegotiation.* +import io.ktor.client.request.* +import io.ktor.http.* import io.ktor.serialization.kotlinx.json.* import io.papermc.paper.command.brigadier.Commands import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents +import kotlinx.coroutines.runBlocking +import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json +import kotlinx.serialization.json.buildJsonArray +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.TextColor import org.bukkit.Server import org.bukkit.command.CommandExecutor import org.bukkit.command.PluginCommand @@ -46,7 +54,7 @@ class Platinum : JavaPlugin() { hash = props.getProperty("gitCommit") logger.info("Loading Platinum v$version") if (version.contains("SNAPSHOT")) { - logger.info("Git Commit: $hash") + logger.info("Local Git Commit: $hash") } webClient = HttpClient(CIO) { install(ContentNegotiation) { @@ -56,6 +64,24 @@ class Platinum : JavaPlugin() { agent = "https://git.jansel.moe/jreimers/Platinum v$version(jansel@jansel.moe)" } } + if (version.contains("SNAPSHOT")) { + logger.info("Getting remote Git Commit...") + runBlocking { + val res = webClient.get("https://git.jansel.moe/api/v1/") { + url { + path("repos/jreimers/platinum/commits?limit=1") + } + } + val apires: List = res.body() + logger.info("Remote hash: ${apires[0].sha}") + if (apires[0].sha == hash) { + componentLogger.info(Component.text("Commit Hashes match, ur on the latest snapshot version", TextColor.color(0,255,0))) + } else { + logger.info("Commit Hashes mismatch, either you\'re using a commit that isnt pushed yet or you\'re out of date") + componentLogger.info(Component.text("Commit Hashes mismatch, either you\'re using a commit that isnt pushed yet or you\'re out of date", TextColor.color(255,0,0))) + } + } + } Companion.server = server pluginManager = server.pluginManager instance = this @@ -68,4 +94,9 @@ class Platinum : JavaPlugin() { private fun registerCommands() { } + + @Serializable + data class CommitApiResponse( + val sha: String + ) }