diff options
Diffstat (limited to 'src/main/kotlin')
-rw-r--r-- | src/main/kotlin/io/github/moulberry/notenoughupdates/util/Rectangle.kt | 8 | ||||
-rw-r--r-- | src/main/kotlin/io/github/moulberry/notenoughupdates/util/UrsaClient.kt | 30 |
2 files changed, 36 insertions, 2 deletions
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/Rectangle.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/Rectangle.kt index d44b7721..1882dac4 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/Rectangle.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/Rectangle.kt @@ -31,6 +31,12 @@ data class Rectangle( val x: Int, val y: Int, val width: Int, val height: Int, ) { + val centerX: Int + get() = x + width / 2 + val centerY: Int + get() = y + height / 2 + + /** * The left edge of this rectangle (Low X) */ @@ -69,7 +75,7 @@ data class Rectangle( /** * Check if this rectangle contains the given coordinate */ - fun contains(x1: Int, y1: Int) :Boolean{ + fun contains(x1: Int, y1: Int): Boolean { return left <= x1 && x1 < left + width && top <= y1 && y1 < top + height } } diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/UrsaClient.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/UrsaClient.kt index 312c5d9b..67df5bf9 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/UrsaClient.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/UrsaClient.kt @@ -20,6 +20,7 @@ package io.github.moulberry.notenoughupdates.util import com.google.gson.JsonObject +import com.mojang.authlib.exceptions.AuthenticationException import io.github.moulberry.notenoughupdates.NotEnoughUpdates import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag @@ -92,6 +93,7 @@ class UrsaClient(val apiUtil: ApiUtil) { } else { this.token = Token(validUntil, token, usedUrsaRoot) isPollingForToken = false + authenticationState = AuthenticationState.SUCCEEDED logger.log("Token saving successful") } } @@ -115,6 +117,13 @@ class UrsaClient(val apiUtil: ApiUtil) { logger.log("Request failed") continueOn(MinecraftExecutor.OnThread) isPollingForToken = false + if (e is AuthenticationException) { + authenticationState = AuthenticationState.FAILED_TO_JOINSERVER + } + if (e is HttpStatusCodeException && e.statusCode == 401) { + authenticationState = AuthenticationState.REJECTED + this.token = null + } request.consumer.completeExceptionally(e) } } @@ -179,6 +188,24 @@ class UrsaClient(val apiUtil: ApiUtil) { } } + + private var authenticationState = AuthenticationState.NOT_ATTEMPTED + + fun getAuthenticationState(): AuthenticationState { + if (authenticationState == AuthenticationState.SUCCEEDED && token?.isValid != true) { + return AuthenticationState.OUTDATED + } + return authenticationState + } + + enum class AuthenticationState { + NOT_ATTEMPTED, + FAILED_TO_JOINSERVER, + REJECTED, + SUCCEEDED, + OUTDATED, + } + companion object { @JvmStatic fun profiles(uuid: UUID) = KnownRequest("v1/hypixel/v2/profiles/${uuid}", JsonObject::class.java) @@ -193,7 +220,8 @@ class UrsaClient(val apiUtil: ApiUtil) { fun bingo(uuid: UUID) = KnownRequest("v1/hypixel/v2/bingo/${uuid}", JsonObject::class.java) @JvmStatic - fun museumForProfile(profileUuid: String) = KnownRequest("v1/hypixel/v2/museum/${profileUuid}", JsonObject::class.java) + fun museumForProfile(profileUuid: String) = + KnownRequest("v1/hypixel/v2/museum/${profileUuid}", JsonObject::class.java) @JvmStatic fun status(uuid: UUID) = KnownRequest("v1/hypixel/v2/status/${uuid}", JsonObject::class.java) |