Skip to content

Commit

Permalink
Fix crash if json prop is null in version checker (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Iru21 committed Mar 12, 2023
1 parent 8b7f58d commit 1efe038
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
@@ -1,4 +1,4 @@
kotlin.code.style = official
minecraftVersion = 1.17
pluginName = Authy
pluginVersion = 3.2.4
pluginVersion = 3.2.5
9 changes: 4 additions & 5 deletions src/main/kotlin/me/iru/utils/versionChecker.kt
Expand Up @@ -10,9 +10,9 @@ import java.net.http.HttpResponse


fun isNewVersionAvailable(): Pair<Boolean, String> {
val latestRelease = getLatestRelease()
val latestVersion = latestRelease.get("tag_name").asString
return Pair(versionToNum(Authy.instance.version) < versionToNum(latestVersion), latestVersion)
val current = Authy.instance.version
val latestVersion = getLatestRelease().get("tag_name")?.asString ?: current
return Pair(versionToNum(current) < versionToNum(latestVersion), latestVersion)
}

private fun versionToNum(ver: String): Int {
Expand All @@ -33,6 +33,5 @@ private fun getLatestRelease(): JsonObject {
.build()

val res = client.send(request, HttpResponse.BodyHandlers.ofString())
val d: String = res.body()
return JsonParser().parse(d).asJsonObject
return JsonParser().parse(res.body()).asJsonObject
}

0 comments on commit 1efe038

Please sign in to comment.