aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Garden.java6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt57
3 files changed, 54 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
index 735978e1b..486bb480e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
.vscode/
run/
build/
+bin/
# gradle
build
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
index 3091e4f85..9dc56b9fc 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
@@ -768,6 +768,12 @@ public class Garden {
public boolean eliteFarmingWeightOvertakeETAAlways = true;
@Expose
+ @ConfigOption(name = "ETA Goal", desc = "Override the Overtake ETA to show when you'll reach the specified rank (if not there yet). (Default: \"10000\")")
+ @ConfigEditorText
+ @ConfigAccordionId(id = 11)
+ public String eliteFarmingWeightETAGoalRank = "10000";
+
+ @Expose
@ConfigOption(name = "Dicer Counter", desc = "")
@ConfigEditorAccordion(id = 12)
public boolean dicerCounter = false;
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()) {