aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-08-19 13:02:29 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-08-19 13:02:29 +0200
commita9cfc1db8d5a9436a0c3def82492fcf0d66240c4 (patch)
tree06bf1a45800d4577800baf656f1bbf0ac176c55d
parent3c9a36985344f748628c763c1898452727a8d4cc (diff)
downloadskyhanni-a9cfc1db8d5a9436a0c3def82492fcf0d66240c4.tar.gz
skyhanni-a9cfc1db8d5a9436a0c3def82492fcf0d66240c4.tar.bz2
skyhanni-a9cfc1db8d5a9436a0c3def82492fcf0d66240c4.zip
off-screen farming weight lb change and /shfarmingprofile
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Storage.java9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt66
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt3
4 files changed, 73 insertions, 10 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
index 871238831..79731f069 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
@@ -224,6 +224,15 @@ public class Storage {
@Expose
public long lastComposterEmptyWarningTime = 0;
+
+ @Expose
+ public FarmingWeightConfig faramingWeight = new FarmingWeightConfig();
+
+ public static class FarmingWeightConfig {
+
+ @Expose
+ public int lastFarmingWeightLeaderboard = -1;
+ }
}
@Expose
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
index 478eb4a4b..118af32e7 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -16,6 +16,7 @@ import at.hannibal2.skyhanni.features.garden.GardenCropTimeCommand
import at.hannibal2.skyhanni.features.garden.composter.ComposterOverlay
import at.hannibal2.skyhanni.features.garden.farming.CropMoneyDisplay
import at.hannibal2.skyhanni.features.garden.farming.CropSpeedMeter
+import at.hannibal2.skyhanni.features.garden.farming.FarmingWeightDisplay
import at.hannibal2.skyhanni.features.garden.farming.GardenStartLocation
import at.hannibal2.skyhanni.features.garden.fortuneguide.CaptureFarmingGear
import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI
@@ -136,6 +137,10 @@ object Commands {
) { clearFarmingItems() }
registerCommand("shresetghostcounter", "Resets the ghost counter stats") { GhostUtil.reset() }
registerCommand("shbingotoggle", "Toggle the bingo card display mode") { BingoCardDisplay.toggleCommand() }
+ registerCommand(
+ "shfarmingprofile",
+ "Look up the farming profile from yourself or another player on elitebot.dev"
+ ) { FarmingWeightDisplay.lookUpCommand(it) }
}
private fun usersBugFix() {
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 cbf4596c4..2878da5b8 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
@@ -2,14 +2,14 @@ package at.hannibal2.skyhanni.features.garden.farming
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.HypixelData
+import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.events.*
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.getSpeed
-import at.hannibal2.skyhanni.utils.APIUtil
-import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.*
+import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
-import at.hannibal2.skyhanni.utils.TimeUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@@ -147,9 +147,7 @@ class FarmingWeightDisplay {
val format = LorenzUtils.formatInteger(leaderboardPosition)
" §7[§b#$format§7]"
} else {
- if (isLoadingLeaderboard) {
- " §7[§b#?§7]"
- } else ""
+ if (isLoadingLeaderboard) " §7[§b#?§7]" else ""
}
}
@@ -192,15 +190,15 @@ class FarmingWeightDisplay {
if (weight < 0) return ""
var nextPlayer = nextPlayer ?: return ""
- var nextName = if (leaderboardPosition == -1 || leaderboardPosition > rankGoal) "#$rankGoal" else nextPlayer.name
+ var nextName =
+ if (leaderboardPosition == -1 || leaderboardPosition > rankGoal) "#$rankGoal" else nextPlayer.name
val totalWeight = (localWeight + weight)
var weightUntilOvertake = nextPlayer.weight - totalWeight
if (weightUntilOvertake < 0) {
if (weightPerSecond > 0) {
- LorenzUtils.debug("weightPerSecond: '$weightPerSecond'")
- LorenzUtils.chat("§e[SkyHanni] You passed §b$nextName §ein the Farming Weight Leaderboard!")
+ farmingChatMessage("§e[SkyHanni] You passed §b$nextName §ein the Farming Weight Leaderboard!")
}
// Lower leaderboard position
@@ -209,6 +207,8 @@ class FarmingWeightDisplay {
} else {
leaderboardPosition--
}
+ ProfileStorageData.profileSpecific?.garden?.faramingWeight?.lastFarmingWeightLeaderboard =
+ leaderboardPosition
// Remove passed player to present the next one
nextPlayers.removeFirst()
@@ -234,6 +234,17 @@ class FarmingWeightDisplay {
return "§e$weightFormat$timeFormat §7behind §b$nextName"
}
+ private fun farmingChatMessage(message: String) {
+ LorenzUtils.hoverableChat(
+ message,
+ listOf(
+ "§eClick to open your Farming Weight",
+ "§eprofile on §celitebot.dev",
+ ),
+ "shfarmingprofile ${LorenzUtils.getPlayerName()}"
+ )
+ }
+
private fun isEnabled() = GardenAPI.inGarden() && config.eliteFarmingWeightDisplay
private fun isEtaEnabled() = config.eliteFarmingWeightOvertakeETA
@@ -265,12 +276,41 @@ class FarmingWeightDisplay {
isLoadingLeaderboard = true
SkyHanniMod.coroutineScope.launch {
+ val wasNotLoaded = leaderboardPosition == -1
leaderboardPosition = loadLeaderboardPosition()
+ if (wasNotLoaded) {
+ checkOffScreenLeaderboardChanges()
+ }
+ ProfileStorageData.profileSpecific?.garden?.faramingWeight?.lastFarmingWeightLeaderboard =
+ leaderboardPosition
lastLeaderboardUpdate = System.currentTimeMillis()
isLoadingLeaderboard = false
}
}
+ private fun checkOffScreenLeaderboardChanges() {
+ val profileSpecific = ProfileStorageData.profileSpecific ?: return
+ val oldPosition = profileSpecific.garden.faramingWeight.lastFarmingWeightLeaderboard
+ if (oldPosition == -1) return
+
+ val diff = leaderboardPosition - oldPosition
+ if (diff == 0) return
+
+ if (diff > 0) {
+ chatOffScreenChange("§cdropped ${StringUtils.optionalPlural(diff, "place", "places")}", oldPosition)
+ } else {
+ chatOffScreenChange("§arisen ${StringUtils.optionalPlural(-diff, "place", "places")}", oldPosition)
+ }
+ }
+
+ private fun chatOffScreenChange(direction: String, oldPosition: Int) {
+ farmingChatMessage(
+ "§e[SkyHanni] §7Since your last visit to the §aGarden§7, " +
+ "you have $direction §7on the §dFarming Leaderboard§7. " +
+ "§7(§e#${oldPosition.addSeparators()} §7-> §e#${leaderboardPosition.addSeparators()}§7)"
+ )
+ }
+
private suspend fun loadLeaderboardPosition() = try {
val uuid = LorenzUtils.getPlayerUuid()
@@ -331,7 +371,7 @@ class FarmingWeightDisplay {
private fun error() {
apiError = true
LorenzUtils.error("[SkyHanni] Loading the farming weight data from elitebot.dev failed!")
- LorenzUtils.chat("§eYou can re-enter the garden to try to fix the problem. If this message repeats itself, please report it on Discord!")
+ LorenzUtils.chat("§eYou can re-enter the garden to try to fix the problem. If this message repeats, please report it on Discord!")
}
private fun calculateCollectionWeight(): MutableMap<CropType, Double> {
@@ -363,6 +403,12 @@ class FarmingWeightDisplay {
private fun CropType.getFactor() = factorPerCrop[this]!!
+ fun lookUpCommand(it: Array<String>) {
+ val name = if (it.size == 1) it[0] else LorenzUtils.getPlayerName()
+ OSUtils.openBrowser("https://elitebot.dev/@$name/")
+ LorenzUtils.chat("§e[SkyHanni] Opening Farming Profile from §b$name")
+ }
+
private val factorPerCrop by lazy {
mapOf(
CropType.WHEAT to 100_000.0,
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
index 15cab32f4..b4d3d106a 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
@@ -124,4 +124,7 @@ object StringUtils {
} ?: text
}
}
+
+ fun optionalPlural(number: Int, singular: String, plural: String) =
+ "$number " + if (number == 1) singular else plural
} \ No newline at end of file