Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 9c2bb9d

Browse files
authored
Merge pull request #140 from DockyardMC/fix/update-checker
fix the update checker
2 parents 7135082 + c679c45 commit 9c2bb9d

File tree

2 files changed

+47
-28
lines changed

2 files changed

+47
-28
lines changed

src/main/kotlin/Main.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ fun main() {
2525
val server = DockyardServer {
2626
withIp("0.0.0.0")
2727
withPort(25565)
28-
withUpdateChecker(false)
2928
useDebugMode(true)
3029
}
3130

src/main/kotlin/io/github/dockyardmc/utils/UpdateChecker.kt

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,60 @@ class UpdateChecker {
1616

1717
companion object {
1818
val LOG_TYPE = CustomLogType("\uFE0F Update Checker", AnsiPair.ORANGE)
19+
const val URL = "https://mvn.devos.one/api/maven/latest/details/releases/io/github/dockyardmc/dockyard"
20+
21+
22+
fun compareVersions(version1: String, version2: String): CurrentVersionStatus {
23+
val v1 = version1.split('.').map { it.toInt() }
24+
val v2 = version2.split('.').map { it.toInt() }
25+
26+
val maxLength = maxOf(v1.size, v2.size)
27+
28+
val paddedV1 = v1 + List(maxLength - v1.size) { 0 }
29+
val paddedV2 = v2 + List(maxLength - v2.size) { 0 }
30+
31+
for (i in paddedV1.indices) {
32+
when {
33+
paddedV1[i] > paddedV2[i] -> return CurrentVersionStatus.DEV_VERSION
34+
paddedV1[i] < paddedV2[i] -> return CurrentVersionStatus.OUTDATED
35+
}
36+
}
37+
return CurrentVersionStatus.UP_TO_DATE
38+
}
1939
}
20-
//
21-
// init {
22-
// val client = HttpClient.newHttpClient()
23-
// val request = HttpRequest.newBuilder().uri(URI("https://mvn.devos.one/api/maven/details/releases/io/github/dockyardmc/dockyard")).build()
24-
// client.sendAsync(request, BodyHandlers.ofString()).thenAccept { res ->
25-
// val response = Json.decodeFromString<ReposliteResponse>(res.body())
26-
// val latestVersion = response.files.last { file -> file.type == "DIRECTORY" }.name
27-
// val publishedVersionContainCurrentVersion = response.files.firstOrNull { file -> file.name == DockyardServer.versionInfo.dockyardVersion } != null
28-
//
29-
// if(latestVersion != DockyardServer.versionInfo.dockyardVersion) {
30-
// if(!publishedVersionContainCurrentVersion) {
31-
// log("You are currently running an outdated DockyardMC version. Consider updating to the latest ($latestVersion)", LOG_TYPE)
32-
// } else {
33-
// log("You are currently running a developer version of DockyardMC. Things might be VERY broken", LOG_TYPE)
34-
// }
35-
// }
36-
// }
37-
// }
3840

39-
@Serializable
40-
data class ReposliteResponse(
41-
val name: String,
42-
val files: List<File>,
43-
val type: String,
44-
)
41+
enum class CurrentVersionStatus {
42+
OUTDATED,
43+
UP_TO_DATE,
44+
DEV_VERSION
45+
}
46+
47+
init {
48+
val client = HttpClient.newHttpClient()
49+
val request = HttpRequest.newBuilder().uri(URI(URL)).build()
50+
51+
client.sendAsync(request, BodyHandlers.ofString()).thenAccept { res ->
52+
val latestVersion = Json.decodeFromString<ReposliteResponse>(res.body()).name.replace("dockyard-", "").replace(".jar", "")
53+
val status = compareVersions(DockyardServer.versionInfo.dockyardVersion, latestVersion)
54+
log("$status, ${DockyardServer.versionInfo.dockyardVersion} - $latestVersion ")
55+
when(status) {
56+
CurrentVersionStatus.OUTDATED -> {
57+
log("You are currently running an outdated DockyardMC version. Consider updating to the latest ($latestVersion)", LOG_TYPE)
58+
}
59+
CurrentVersionStatus.UP_TO_DATE -> {}
60+
CurrentVersionStatus.DEV_VERSION -> {
61+
log("You are currently running a dev version of DockyardMC. Things maybe be broken", LOG_TYPE)
62+
}
63+
}
64+
}
65+
}
4566

4667
@Serializable
47-
data class File(
68+
data class ReposliteResponse(
4869
val name: String,
4970
val type: String,
5071
val contentType: String? = null,
5172
val contentLength: Long? = null,
5273
val lastModifiedTime: Double? = null,
5374
)
54-
}
55-
75+
}

0 commit comments

Comments
 (0)