diff options
author | Kaeso <24925519+ptlthg@users.noreply.github.com> | 2023-07-25 09:59:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-25 15:59:01 +0200 |
commit | 579a7bb51ce867ee15adea5a4c3dc823a7272b64 (patch) | |
tree | 4ecc90eeba088772a084021870f05ba098a9efcb /src/main/java/at/hannibal2/skyhanni/features/garden | |
parent | e83fef331c43b19342bdf4c2e173683163f45abf (diff) | |
download | skyhanni-579a7bb51ce867ee15adea5a4c3dc823a7272b64.tar.gz skyhanni-579a7bb51ce867ee15adea5a4c3dc823a7272b64.tar.bz2 skyhanni-579a7bb51ce867ee15adea5a4c3dc823a7272b64.zip |
Merge pull request #332
* Add bin folder to .gitignore
* Add ETA Goal config setting
* Display ETA Goal if a player hasn't reached it yet
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt index 51bb0af43..e2b5190c6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt @@ -44,6 +44,8 @@ class FarmingWeightDisplay { lastLeaderboardUpdate = 0 nextPlayers.clear() + rankGoal = -1 + localCounter.clear() } @@ -52,7 +54,9 @@ class FarmingWeightDisplay { display = emptyList() profileId = "" weight = -2.0 + nextPlayers.clear() + rankGoal = -1 } @SubscribeEvent @@ -77,6 +81,7 @@ class FarmingWeightDisplay { private var dirtyCropWeight = false private var isLoadingWeight = false private var isLoadingLeaderboard = false + private var rankGoal = -1 private var nextPlayers = mutableListOf<UpcomingPlayer>() private val nextPlayer get() = nextPlayers.firstOrNull() @@ -117,6 +122,8 @@ class FarmingWeightDisplay { } val weight = getWeight() + + if (rankGoal == -1) rankGoal = getRankGoal() val leaderboard = getLeaderboard() val list = mutableListOf<String>() @@ -133,14 +140,7 @@ class FarmingWeightDisplay { // Fetching new leaderboard position every 10.5 minutes if (System.currentTimeMillis() > lastLeaderboardUpdate + 630_000) { - if (!isLoadingLeaderboard) { - isLoadingLeaderboard = true - SkyHanniMod.coroutineScope.launch { - leaderboardPosition = loadLeaderboardPosition() - lastLeaderboardUpdate = System.currentTimeMillis() - isLoadingLeaderboard = false - } - } + loadLeaderboardIfAble() } return if (leaderboardPosition != -1) { @@ -166,11 +166,33 @@ class FarmingWeightDisplay { return "§e" + LorenzUtils.formatDouble(totalWeight, 2) } + private fun getRankGoal(): Int { + val value = config.eliteFarmingWeightETAGoalRank + var goal = 10000 + + // Check that the provided string is valid + val parsed = value.toIntOrNull() ?: 0 + if (parsed < 1 || parsed > goal) { + LorenzUtils.error("[SkyHanni] Invalid Farming Weight Overtake Goal!") + LorenzUtils.chat("§eEdit the Overtake Goal config value with a valid number [1-10000] to use this feature!") + config.eliteFarmingWeightETAGoalRank = goal.toString() + } else { + goal = parsed + } + + // Fetch the positions again if the goal was changed + if (rankGoal != goal) { + loadLeaderboardIfAble() + } + + return goal + } + private fun getETA(): String { if (weight < 0) return "" var nextPlayer = nextPlayer ?: return "" - var nextName = if (leaderboardPosition == -1) "#10000" else nextPlayer.name + var nextName = if (leaderboardPosition == -1 || leaderboardPosition > rankGoal) "#$rankGoal" else nextPlayer.name val totalWeight = (localWeight + weight) var weightUntilOvertake = nextPlayer.weight - totalWeight @@ -238,10 +260,25 @@ class FarmingWeightDisplay { } else 0.0 } + private fun loadLeaderboardIfAble() { + if (isLoadingLeaderboard) return + isLoadingLeaderboard = true + + SkyHanniMod.coroutineScope.launch { + leaderboardPosition = loadLeaderboardPosition() + lastLeaderboardUpdate = System.currentTimeMillis() + isLoadingLeaderboard = false + } + } + private suspend fun loadLeaderboardPosition() = try { val uuid = LorenzUtils.getPlayerUuid() + val includeUpcoming = if (isEtaEnabled()) "?includeUpcoming=true" else "" - val url = "https://api.elitebot.dev/leaderboard/rank/farmingweight/$uuid/$profileId$includeUpcoming" + val goalRank = getRankGoal() + 1 // API returns upcoming players as if you were at this rank already + val atRank = if (isEtaEnabled() && goalRank != 10001) "&atRank=$goalRank" else "" + + val url = "https://api.elitebot.dev/leaderboard/rank/farmingweight/$uuid/$profileId$includeUpcoming$atRank" val result = withContext(Dispatchers.IO) { APIUtil.getJSONResponse(url) }.asJsonObject if (isEtaEnabled()) { |