From 5bd6a4cd3807d128ba55c336946531a8838c51c7 Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Fri, 14 Jun 2024 05:49:38 +1000 Subject: Backend: Apply annotations to everything (#1983) * add plugin Co-authored-by: ThatGravyBoat * data and apis done * other stuff done * fix merge * Backend: Classes -> Objects with annotation * Backend: Apply annotations to everything * fix test * fix merge * fix merge * use annotation * use annotation * fix version number * fix space * bring back fix * work on companion again now that they are all done * oop * fixed merge conflicts --------- Co-authored-by: ThatGravyBoat Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .idea/dictionaries/default_user.xml | 1 + .live-plugins/module/plugin.kts | 3 - src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 19 +- .../at/hannibal2/skyhanni/data/GuiEditManager.kt | 1 + .../java/at/hannibal2/skyhanni/data/HypixelData.kt | 308 ++++---- .../at/hannibal2/skyhanni/data/ScoreboardData.kt | 2 + .../at/hannibal2/skyhanni/data/SkillExperience.kt | 178 ++--- .../java/at/hannibal2/skyhanni/data/mob/MobData.kt | 1 - .../at/hannibal2/skyhanni/data/mob/MobDetection.kt | 5 +- .../hannibal2/skyhanni/features/chat/Translator.kt | 185 +++-- .../damageindicator/DamageIndicatorManager.kt | 1 + .../features/event/diana/BurrowWarpHelper.kt | 1 + .../garden/farming/FarmingWeightDisplay.kt | 780 ++++++++++----------- .../gui/customscoreboard/ScoreboardElements.kt | 4 +- .../skyhanni/features/misc/CollectionTracker.kt | 251 ++++--- .../skyhanni/test/SkyHanniDebugsAndTests.kt | 527 +++++++------- 16 files changed, 1122 insertions(+), 1145 deletions(-) diff --git a/.idea/dictionaries/default_user.xml b/.idea/dictionaries/default_user.xml index a1b1f01c3..846fd6b43 100644 --- a/.idea/dictionaries/default_user.xml +++ b/.idea/dictionaries/default_user.xml @@ -172,6 +172,7 @@ skytils's soopy soopy's + soulsand soulweaver sprayonator stillgore diff --git a/.live-plugins/module/plugin.kts b/.live-plugins/module/plugin.kts index 286160a9b..c0a65d3f4 100644 --- a/.live-plugins/module/plugin.kts +++ b/.live-plugins/module/plugin.kts @@ -5,7 +5,6 @@ import com.intellij.codeInspection.ProblemsHolder import com.intellij.openapi.project.Project import com.intellij.psi.PsiElementVisitor import liveplugin.registerInspection -import liveplugin.show import org.jetbrains.kotlin.idea.base.utils.fqname.fqName import org.jetbrains.kotlin.idea.codeinsight.api.classic.inspections.AbstractKotlinInspection import org.jetbrains.kotlin.idea.util.AnnotationModificationHelper @@ -55,7 +54,6 @@ class ModuleInspectionKotlin : AbstractKotlinInspection() { } override fun visitObjectDeclaration(declaration: KtObjectDeclaration) { - if (declaration.isCompanion()) return val hasAnnotation = declaration.annotationEntries.any { it.shortName?.asString() == skyHanniModule } if (hasAnnotation) return @@ -92,7 +90,6 @@ class ModuleQuickFix : LocalQuickFix { " ", null ) - show("Annotation applied, make sure SkyHanniMod isn't still loading this module") } override fun getName() = "Annotate with @SkyHanniModule" diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index bb3faa278..28a8aa318 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -6,9 +6,7 @@ import at.hannibal2.skyhanni.config.ConfigManager import at.hannibal2.skyhanni.config.Features import at.hannibal2.skyhanni.config.SackData import at.hannibal2.skyhanni.config.commands.Commands -import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.data.OtherInventoryData -import at.hannibal2.skyhanni.data.SkillExperience import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson import at.hannibal2.skyhanni.data.jsonobjects.local.JacobContestsJson import at.hannibal2.skyhanni.data.jsonobjects.local.KnownFeaturesJson @@ -16,12 +14,8 @@ import at.hannibal2.skyhanni.data.jsonobjects.local.VisualWordsJson import at.hannibal2.skyhanni.data.repo.RepoManager import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.utils.PreInitFinishedEvent -import at.hannibal2.skyhanni.features.chat.Translator -import at.hannibal2.skyhanni.features.garden.farming.FarmingWeightDisplay -import at.hannibal2.skyhanni.features.misc.CollectionTracker import at.hannibal2.skyhanni.features.nether.reputationhelper.CrimsonIsleReputationHelper import at.hannibal2.skyhanni.skyhannimodule.LoadedModules -import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.test.hotswap.HotswapSupport import at.hannibal2.skyhanni.utils.MinecraftConsoleFilter.Companion.initLogging @@ -48,7 +42,7 @@ import org.apache.logging.log4j.Logger clientSideOnly = true, useMetadata = true, guiFactory = "at.hannibal2.skyhanni.config.ConfigGuiForgeInterop", - version = "0.26.Beta.9", + version = "0.26.Beta.7", ) class SkyHanniMod { @@ -61,18 +55,7 @@ class SkyHanniMod { loadModule(this) LoadedModules.modules.forEach { loadModule(it) } - // data - loadModule(HypixelData()) - loadModule(SkillExperience()) - - // features - loadModule(CollectionTracker()) loadModule(CrimsonIsleReputationHelper(this)) - loadModule(FarmingWeightDisplay()) - loadModule(Translator()) - - // test stuff - loadModule(SkyHanniDebugsAndTests()) SkyHanniEvents.init(modules) diff --git a/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt b/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt index 9f249ee7a..a7e09b3f0 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt @@ -144,4 +144,5 @@ object GuiEditManager { } } +// TODO remove class Vector2i(val x: Int, val y: Int) diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index d4a14679a..8ade8f55e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -16,6 +16,7 @@ import at.hannibal2.skyhanni.events.minecraft.ClientDisconnectEvent import at.hannibal2.skyhanni.features.bingo.BingoAPI import at.hannibal2.skyhanni.features.dungeon.DungeonAPI import at.hannibal2.skyhanni.features.rift.RiftAPI +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzLogger @@ -35,7 +36,8 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.concurrent.thread import kotlin.time.Duration.Companion.seconds -class HypixelData { +@SkyHanniModule +object HypixelData { private val patternGroup = RepoPattern.group("data.hypixeldata") // TODO add regex tests @@ -51,124 +53,121 @@ class HypixelData { "islandname", "(?:§.)*(Area|Dungeon): (?:§.)*(?.*)", ) + private val serverIdScoreboardPattern by patternGroup.pattern( + "serverid.scoreboard", + "§7\\d+/\\d+/\\d+ §8(?[mM])(?\\S+).*", + ) + private val serverIdTablistPattern by patternGroup.pattern( + "serverid.tablist", + " Server: §r§8(?\\S+)", + ) + private val lobbyTypePattern by patternGroup.pattern( + "lobbytype", + "(?.*lobby)\\d+", + ) + private val playerAmountPattern by patternGroup.pattern( + "playeramount", + "^\\s*(?:§.)+Players (?:§.)+\\((?\\d+)\\)\\s*$", + ) + private val playerAmountCoopPattern by patternGroup.pattern( + "playeramount.coop", + "^\\s*(?:§.)*Coop (?:§.)*\\((?\\d+)\\)\\s*$", + ) + private val playerAmountGuestingPattern by patternGroup.pattern( + "playeramount.guesting", + "^\\s*(?:§.)*Guests (?:§.)*\\((?\\d+)\\)\\s*$", + ) - private var lastLocRaw = SimpleTimeMark.farPast() - - companion object { - private val patternGroup = RepoPattern.group("data.hypixeldata") - private val serverIdScoreboardPattern by patternGroup.pattern( - "serverid.scoreboard", - "§7\\d+/\\d+/\\d+ §8(?[mM])(?\\S+).*", - ) - private val serverIdTablistPattern by patternGroup.pattern( - "serverid.tablist", - " Server: §r§8(?\\S+)", - ) - private val lobbyTypePattern by patternGroup.pattern( - "lobbytype", - "(?.*lobby)\\d+", - ) - private val playerAmountPattern by patternGroup.pattern( - "playeramount", - "^\\s*(?:§.)+Players (?:§.)+\\((?\\d+)\\)\\s*$", - ) - private val playerAmountCoopPattern by patternGroup.pattern( - "playeramount.coop", - "^\\s*(?:§.)*Coop (?:§.)*\\((?\\d+)\\)\\s*$", - ) - private val playerAmountGuestingPattern by patternGroup.pattern( - "playeramount.guesting", - "^\\s*(?:§.)*Guests (?:§.)*\\((?\\d+)\\)\\s*$", - ) + /** + * REGEX-TEST: §r§b§lParty §r§f(4) + */ + private val dungeonPartyAmountPattern by patternGroup.pattern( + "playeramount.dungeonparty", + "^\\s*(?:§.)+Party (?:§.)+\\((?\\d+)\\)\\s*$", + ) + private val soloProfileAmountPattern by patternGroup.pattern( + "solo.profile.amount", + "^\\s*(?:§.)*Island\\s*$", + ) + private val scoreboardVisitingAmoutPattern by patternGroup.pattern( + "scoreboard.visiting.amount", + "\\s+§.✌ §.\\(§.(?\\d+)§./(?\\d+)\\)", + ) + private val guestPattern by patternGroup.pattern( + "guesting.scoreboard", + "SKYBLOCK GUEST", + ) + private val scoreboardTitlePattern by patternGroup.pattern( + "scoreboard.title", + "SK[YI]BLOCK(?: CO-OP| GUEST)?", + ) - /** - * REGEX-TEST: §r§b§lParty §r§f(4) - */ - private val dungeonPartyAmountPattern by patternGroup.pattern( - "playeramount.dungeonparty", - "^\\s*(?:§.)+Party (?:§.)+\\((?\\d+)\\)\\s*$", - ) - private val soloProfileAmountPattern by patternGroup.pattern( - "solo.profile.amount", - "^\\s*(?:§.)*Island\\s*$", - ) - private val scoreboardVisitingAmoutPattern by patternGroup.pattern( - "scoreboard.visiting.amount", - "\\s+§.✌ §.\\(§.(?\\d+)§./(?\\d+)\\)", - ) - private val guestPattern by patternGroup.pattern( - "guesting.scoreboard", - "SKYBLOCK GUEST", - ) - private val scoreboardTitlePattern by patternGroup.pattern( - "scoreboard.title", - "SK[YI]BLOCK(?: CO-OP| GUEST)?", - ) + /** + * REGEX-TEST: §7⏣ §bVillage + * REGEX-TEST: §5ф §dWizard Tower + */ + private val skyblockAreaPattern by patternGroup.pattern( + "skyblock.area", + "\\s*§(?7⏣|5ф) §(?.)(?.*)", + ) - /** - * REGEX-TEST: §7⏣ §bVillage - * REGEX-TEST: §5ф §dWizard Tower - */ - private val skyblockAreaPattern by patternGroup.pattern( - "skyblock.area", - "\\s*§(?7⏣|5ф) §(?.)(?.*)", - ) + private var lastLocRaw = SimpleTimeMark.farPast() - var hypixelLive = false - var hypixelAlpha = false - var inLobby = false - var inLimbo = false - var skyBlock = false - var skyBlockIsland = IslandType.UNKNOWN - var serverId: String? = null + var hypixelLive = false + var hypixelAlpha = false + var inLobby = false + var inLimbo = false + var skyBlock = false + var skyBlockIsland = IslandType.UNKNOWN + var serverId: String? = null - // Ironman, Stranded and Bingo - var noTrade = false + // Ironman, Stranded and Bingo + var noTrade = false - var ironman = false - var stranded = false - var bingo = false + var ironman = false + var stranded = false + var bingo = false - var profileName = "" - var joinedWorld = SimpleTimeMark.farPast() + var profileName = "" + var joinedWorld = SimpleTimeMark.farPast() - var skyBlockArea: String? = null - var skyBlockAreaWithSymbol: String? = null + var skyBlockArea: String? = null + var skyBlockAreaWithSymbol: String? = null // Data from locraw var locrawData: JsonObject? = null - private var locraw: MutableMap = listOf( - "server", + private var locraw: MutableMap = listOf( + "server", "gametype", "lobbyname", "lobbytype", "mode", "map", - ).associateWith { "" }.toMutableMap() - - val server get() = locraw["server"] ?: "" - val gameType get() = locraw["gametype"] ?: "" - val lobbyName get() = locraw["lobbyname"] ?: "" - val lobbyType get() = locraw["lobbytype"] ?: "" - val mode get() = locraw["mode"] ?: "" - val map get() = locraw["map"] ?: "" - - fun checkCurrentServerId() { - if (!LorenzUtils.inSkyBlock) return - if (serverId != null) return - if (LorenzUtils.lastWorldSwitch.passedSince() < 1.seconds) return - if (!TabListData.fullyLoaded) return - - ScoreboardData.sidebarLinesFormatted.matchFirst(serverIdScoreboardPattern) { - val serverType = if (group("servertype") == "M") "mega" else "mini" - serverId = "$serverType${group("serverid")}" - return - } + ).associateWith { "" }.toMutableMap() + + val server get() = locraw["server"] ?: "" + val gameType get() = locraw["gametype"] ?: "" + val lobbyName get() = locraw["lobbyname"] ?: "" + val lobbyType get() = locraw["lobbytype"] ?: "" + val mode get() = locraw["mode"] ?: "" + val map get() = locraw["map"] ?: "" + + fun checkCurrentServerId() { + if (!LorenzUtils.inSkyBlock) return + if (serverId != null) return + if (LorenzUtils.lastWorldSwitch.passedSince() < 1.seconds) return + if (!TabListData.fullyLoaded) return + + ScoreboardData.sidebarLinesFormatted.matchFirst(serverIdScoreboardPattern) { + val serverType = if (group("servertype") == "M") "mega" else "mini" + serverId = "$serverType${group("serverid")}" + return + } - TabListData.getTabList().matchFirst(serverIdTablistPattern) { - serverId = group("serverid") - return - } + TabListData.getTabList().matchFirst(serverIdTablistPattern) { + serverId = group("serverid") + return + } ErrorManager.logErrorWithData( Exception("NoServerId"), @@ -179,71 +178,70 @@ class HypixelData { ) } - fun getPlayersOnCurrentServer(): Int { - var amount = 0 - val playerPatternList = mutableListOf( - playerAmountPattern, - playerAmountCoopPattern, - playerAmountGuestingPattern, - ) - if (DungeonAPI.inDungeon()) { - playerPatternList.add(dungeonPartyAmountPattern) - } + fun getPlayersOnCurrentServer(): Int { + var amount = 0 + val playerPatternList = mutableListOf( + playerAmountPattern, + playerAmountCoopPattern, + playerAmountGuestingPattern, + ) + if (DungeonAPI.inDungeon()) { + playerPatternList.add(dungeonPartyAmountPattern) + } - out@ for (pattern in playerPatternList) { - for (line in TabListData.getTabList()) { - pattern.matchMatcher(line) { - amount += group("amount").toInt() - continue@out - } + out@ for (pattern in playerPatternList) { + for (line in TabListData.getTabList()) { + pattern.matchMatcher(line) { + amount += group("amount").toInt() + continue@out } } - amount += TabListData.getTabList().count { soloProfileAmountPattern.matches(it) } - - return amount } + amount += TabListData.getTabList().count { soloProfileAmountPattern.matches(it) } - fun getMaxPlayersForCurrentServer(): Int { - ScoreboardData.sidebarLinesFormatted.matchFirst(scoreboardVisitingAmoutPattern) { - return group("maxamount").toInt() - } + return amount + } - return when (skyBlockIsland) { - IslandType.MINESHAFT -> 4 - IslandType.CATACOMBS -> 5 - IslandType.CRYSTAL_HOLLOWS -> 24 - IslandType.CRIMSON_ISLE -> 24 - else -> if (serverId?.startsWith("mega") == true) 80 else 26 - } + fun getMaxPlayersForCurrentServer(): Int { + ScoreboardData.sidebarLinesFormatted.matchFirst(scoreboardVisitingAmoutPattern) { + return group("maxamount").toInt() } - // This code is modified from NEU, and depends on NEU (or another mod) sending /locraw. - private val jsonBracketPattern = "^\\{.+}".toPattern() - - //todo convert to proper json object - fun checkForLocraw(message: String) { - jsonBracketPattern.matchMatcher(message.removeColor()) { - try { - val obj: JsonObject = gson.fromJson(group(), JsonObject::class.java) - if (obj.has("server")) { - locrawData = obj - locraw.keys.forEach { key -> - locraw[key] = obj[key]?.asString ?: "" - } - inLimbo = locraw["server"] == "limbo" - inLobby = locraw["lobbyname"] != "" - - if (inLobby) { - locraw["lobbyname"]?.let { - lobbyTypePattern.matchMatcher(it) { - locraw["lobbytype"] = group("lobbyType") - } + return when (skyBlockIsland) { + IslandType.MINESHAFT -> 4 + IslandType.CATACOMBS -> 5 + IslandType.CRYSTAL_HOLLOWS -> 24 + IslandType.CRIMSON_ISLE -> 24 + else -> if (serverId?.startsWith("mega") == true) 80 else 26 + } + } + + // This code is modified from NEU, and depends on NEU (or another mod) sending /locraw. + private val jsonBracketPattern = "^\\{.+}".toPattern() + + //todo convert to proper json object + fun checkForLocraw(message: String) { + jsonBracketPattern.matchMatcher(message.removeColor()) { + try { + val obj: JsonObject = gson.fromJson(group(), JsonObject::class.java) + if (obj.has("server")) { + locrawData = obj + locraw.keys.forEach { key -> + locraw[key] = obj[key]?.asString ?: "" + } + inLimbo = locraw["server"] == "limbo" + inLobby = locraw["lobbyname"] != "" + + if (inLobby) { + locraw["lobbyname"]?.let { + lobbyTypePattern.matchMatcher(it) { + locraw["lobbytype"] = group("lobbyType") } } } - } catch (e: Exception) { - ErrorManager.logErrorWithData(e, "Failed to parse locraw data") } + } catch (e: Exception) { + ErrorManager.logErrorWithData(e, "Failed to parse locraw data") } } } diff --git a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt index 72abf6bab..31499adb1 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt @@ -28,6 +28,8 @@ object ScoreboardData { private val minecraftColorCodesPattern = "(?i)[0-9a-fkmolnr]".toPattern() + + fun formatLines(rawList: List): List { val list = mutableListOf() for (line in rawList) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt index 25d48a525..367c3794e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.events.ActionBarUpdateEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.ProfileJoinEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils @@ -13,7 +14,8 @@ import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -class SkillExperience { +@SkyHanniModule +object SkillExperience { private val patternGroup = RepoPattern.group("data.skill") private val actionBarPattern by patternGroup.pattern( "actionbar", @@ -77,102 +79,100 @@ class SkillExperience { if (skillExp.isNotEmpty()) return } - companion object { - private val skillExp = mutableMapOf() + private val skillExp = mutableMapOf() - private fun getLevelForExpExactly(experience: Long): Int { - var level = 1 - for (levelXp in levelingExp) { - if (levelXp.toLong() == experience) { - return level - } - level++ + private fun getLevelForExpExactly(experience: Long): Int { + var level = 1 + for (levelXp in levelingExp) { + if (levelXp.toLong() == experience) { + return level } - - return 0 + level++ } - fun getExpForNextLevel(requestedLevel: Int) = levelingExp[requestedLevel] + return 0 + } - fun getExpForLevel(requestedLevel: Int): Long { - var total = 0L - var level = 0 - for (levelXp in levelingExp) { - total += levelXp - level++ - if (level == requestedLevel) { - return total - } - } + fun getExpForNextLevel(requestedLevel: Int) = levelingExp[requestedLevel] - return 0 + fun getExpForLevel(requestedLevel: Int): Long { + var total = 0L + var level = 0 + for (levelXp in levelingExp) { + total += levelXp + level++ + if (level == requestedLevel) { + return total + } } - // TODO create additional event - fun getExpForSkill(skillName: String) = skillExp[skillName.lowercase()] ?: 0 - - private val levelingExp = listOf( - 50, - 125, - 200, - 300, - 500, - 750, - 1000, - 1500, - 2000, - 3500, - 5000, - 7500, - 10000, - 15000, - 20000, - 30000, - 50000, - 75000, - 100000, - 200000, - 300000, - 400000, - 500000, - 600000, - 700000, - 800000, - 900000, - 1000000, - 1100000, - 1200000, - 1300000, - 1400000, - 1500000, - 1600000, - 1700000, - 1800000, - 1900000, - 2000000, - 2100000, - 2200000, - 2300000, - 2400000, - 2500000, - 2600000, - 2750000, - 2900000, - 3100000, - 3400000, - 3700000, - 4000000, - 4300000, - 4600000, - 4900000, - 5200000, - 5500000, - 5800000, - 6100000, - 6400000, - 6700000, - 7000000 - ) + return 0 } + + // TODO create additional event + fun getExpForSkill(skillName: String) = skillExp[skillName.lowercase()] ?: 0 + + private val levelingExp = listOf( + 50, + 125, + 200, + 300, + 500, + 750, + 1000, + 1500, + 2000, + 3500, + 5000, + 7500, + 10000, + 15000, + 20000, + 30000, + 50000, + 75000, + 100000, + 200000, + 300000, + 400000, + 500000, + 600000, + 700000, + 800000, + 900000, + 1000000, + 1100000, + 1200000, + 1300000, + 1400000, + 1500000, + 1600000, + 1700000, + 1800000, + 1900000, + 2000000, + 2100000, + 2200000, + 2300000, + 2400000, + 2500000, + 2600000, + 2750000, + 2900000, + 3100000, + 3400000, + 3700000, + 4000000, + 4300000, + 4600000, + 4900000, + 5200000, + 5500000, + 5800000, + 6100000, + 6400000, + 6700000, + 7000000 + ) } diff --git a/src/main/java/at/hannibal2/skyhanni/data/mob/MobData.kt b/src/main/java/at/hannibal2/skyhanni/data/mob/MobData.kt index 59cacde87..4eb79d6de 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/mob/MobData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/mob/MobData.kt @@ -19,7 +19,6 @@ object MobData { val entityList get() = this.flatMap { listOf(it.baseEntity) + (it.extraEntities) } } - val players = MobSet() val displayNPCs = MobSet() val skyblockMobs = MobSet() diff --git a/src/main/java/at/hannibal2/skyhanni/data/mob/MobDetection.kt b/src/main/java/at/hannibal2/skyhanni/data/mob/MobDetection.kt index 0c59a72ac..c1e17f06b 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/mob/MobDetection.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/mob/MobDetection.kt @@ -3,7 +3,6 @@ package at.hannibal2.skyhanni.data.mob import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.data.IslandType -import at.hannibal2.skyhanni.data.mob.MobData.logger import at.hannibal2.skyhanni.data.mob.MobFilter.isDisplayNPC import at.hannibal2.skyhanni.data.mob.MobFilter.isRealPlayer import at.hannibal2.skyhanni.data.mob.MobFilter.isSkyBlockMob @@ -133,7 +132,7 @@ object MobDetection { private fun getRetry(entity: EntityLivingBase) = MobData.retries[entity.entityId] /** @return always true */ - private fun mobDetectionError(string: String) = logger.log(string).let { true } + private fun mobDetectionError(string: String) = MobData.logger.log(string).let { true } /**@return a false means that it should try again (later)*/ private fun entitySpawn(entity: EntityLivingBase, roughType: Mob.Type): Boolean { @@ -267,7 +266,7 @@ object MobDetection { val entity = retry.entity if (retry.times == MAX_RETRIES) { - logger.log( + MobData.logger.log( "`${retry.entity.name}`${retry.entity.entityId} missed {\n " + "is already Found: ${MobData.entityToMob[retry.entity] != null})." + "\n Position: ${retry.entity.getLorenzVec()}\n " diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt index 683fe1857..2d3f3aa85 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.chat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.SkyHanniMod.Companion.coroutineScope import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.APIUtil import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ConditionalUtils.transformIf @@ -21,7 +22,8 @@ import java.net.URLDecoder import java.net.URLEncoder // TODO split into two classes: TranslatorCommand and GoogleTranslator. only communicates via getTranslationFromEnglish and getTranslationToEnglish -class Translator { +@SkyHanniModule +object Translator { private val messageContentRegex = Regex(".*: (.*)") @@ -49,108 +51,105 @@ class Translator { return style } - companion object { - - private val config get() = SkyHanniMod.feature.chat - - /* - * Simplified version of the JSON response: - * [ - * [ - * [ - * 'translated sentence one with a space after the punctuation. ' - * 'original sentence one without a space after the punctuation.' - * ], - * [ - * 'translated sentence two without punctuation bc it's last' - * 'original sentence two without punctuation' - * ] - * ], - * null, - * '"target language as a two-letter code following ISO 639-1"', - * ] - */ - - private fun getJSONResponse(urlString: String) = - APIUtil.getJSONResponseAsElement(urlString, false, "Google Translate API") - - private fun getTranslationToEnglish(message: String): String { - val url = - "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=" + - URLEncoder.encode(message, "UTF-8") - - var messageToSend = "" - val layer1 = getJSONResponse(url).asJsonArray - if (layer1.size() <= 2) return "Error!" - - val language = layer1[2].toString() - if (language == "\"en\"") return "Unable to translate!" - if (language.length != 4) return "Error!" - - val layer2 = try { - layer1[0] as JsonArray - } catch (_: Exception) { - return "Error!" - } + private val config get() = SkyHanniMod.feature.chat + + /* + * Simplified version of the JSON response: + * [ + * [ + * [ + * 'translated sentence one with a space after the punctuation. ' + * 'original sentence one without a space after the punctuation.' + * ], + * [ + * 'translated sentence two without punctuation bc it's last' + * 'original sentence two without punctuation' + * ] + * ], + * null, + * '"target language as a two-letter code following ISO 639-1"', + * ] + */ + + private fun getJSONResponse(urlString: String) = + APIUtil.getJSONResponseAsElement(urlString, false, "Google Translate API") + + private fun getTranslationToEnglish(message: String): String { + val url = + "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=" + + URLEncoder.encode(message, "UTF-8") + + var messageToSend = "" + val layer1 = getJSONResponse(url).asJsonArray + if (layer1.size() <= 2) return "Error!" + + val language = layer1[2].toString() + if (language == "\"en\"") return "Unable to translate!" + if (language.length != 4) return "Error!" + + val layer2 = try { + layer1[0] as JsonArray + } catch (_: Exception) { + return "Error!" + } - for (layer3 in layer2) { - val arrayLayer3 = layer3 as? JsonArray ?: continue - val sentence = arrayLayer3[0].toString() + for (layer3 in layer2) { + val arrayLayer3 = layer3 as? JsonArray ?: continue + val sentence = arrayLayer3[0].toString() + val sentenceWithoutQuotes = sentence.substring(1, sentence.length - 1) + messageToSend = "$messageToSend$sentenceWithoutQuotes" + } + messageToSend = "$messageToSend §7(Language: $language)" + + return URLDecoder.decode(messageToSend, "UTF-8").replace("\\", "") + } + + private fun getTranslationFromEnglish(message: String, lang: String): String { + val url = + "https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=$lang&dt=t&q=" + + URLEncoder.encode(message, "UTF-8") + + val layer1 = getJSONResponse(url).asJsonArray + if (layer1.size() < 1) return "Error!" + val layer2 = layer1[0] as? JsonArray + + val firstSentence = (layer2?.get(0) as? JsonArray)?.get(0).toString() + var messageToSend = firstSentence.substring(0, firstSentence.length - 1) + if (layer2 != null) { + for (sentenceIndex in 1..) { + val message = args.joinToString(" ").removeColor() - private fun getTranslationFromEnglish(message: String, lang: String): String { - val url = - "https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=$lang&dt=t&q=" + - URLEncoder.encode(message, "UTF-8") - - val layer1 = getJSONResponse(url).asJsonArray - if (layer1.size() < 1) return "Error!" - val layer2 = layer1[0] as? JsonArray - - val firstSentence = (layer2?.get(0) as? JsonArray)?.get(0).toString() - var messageToSend = firstSentence.substring(0, firstSentence.length - 1) - if (layer2 != null) { - for (sentenceIndex in 1..) { - val message = args.joinToString(" ").removeColor() - - coroutineScope.launch { - val translation = getTranslationToEnglish(message) - if (translation == "Unable to translate!") ChatUtils.userError("Unable to translate message :( (is it in English?)") - else ChatUtils.chat("Found translation: §f$translation") - } + fun fromEnglish(args: Array) { + if (args.size < 2 || args[0].length != 2) { // args[0] is the language code + ChatUtils.userError("Usage: /shcopytranslation ") + return } + val language = args[0] + val message = args.drop(1).joinToString(" ") - fun fromEnglish(args: Array) { - if (args.size < 2 || args[0].length != 2) { // args[0] is the language code - ChatUtils.userError("Usage: /shcopytranslation ") - return - } - val language = args[0] - val message = args.drop(1).joinToString(" ") - - coroutineScope.launch { - val translation = getTranslationFromEnglish(message, language) - ChatUtils.chat("Copied translation to clipboard: §f$translation") - OSUtils.copyToClipboard(translation) - } + coroutineScope.launch { + val translation = getTranslationFromEnglish(message, language) + ChatUtils.chat("Copied translation to clipboard: §f$translation") + OSUtils.copyToClipboard(translation) } - - fun isEnabled() = config.translator } + + fun isEnabled() = config.translator } diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt index 33bb20a52..d41431726 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt @@ -74,6 +74,7 @@ object DamageIndicatorManager { private val enderSlayerHitsNumberPattern = ".* §[5fd]§l(?\\d+) Hits?".toPattern() + private var data = mapOf() private val damagePattern = "[✧✯]?(\\d+[⚔+✧❤♞☄✷ﬗ✯]*)".toPattern() diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt index be8d77a6a..bf362d918 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt @@ -23,6 +23,7 @@ import kotlin.time.Duration.Companion.seconds object BurrowWarpHelper { private val config get() = SkyHanniMod.feature.event.diana + var currentWarp: WarpPoint? = null private var lastWarpTime = SimpleTimeMark.farPast() 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 0aac3e747..03c35ce27 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 @@ -18,6 +18,7 @@ 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.features.garden.pests.PestType +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.APIUtil import at.hannibal2.skyhanni.utils.ChatUtils @@ -39,7 +40,8 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds -class FarmingWeightDisplay { +@SkyHanniModule +object FarmingWeightDisplay { @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent) { @@ -102,491 +104,487 @@ class FarmingWeightDisplay { event.move(34, "garden.eliteFarmingWeights.ETAGoalRank", "garden.eliteFarmingWeights.etaGoalRank") } - companion object { - - private val config get() = GardenAPI.config.eliteFarmingWeights - private val localCounter = mutableMapOf() - - private var display = emptyList() - private var profileId = "" - private var lastLeaderboardUpdate = SimpleTimeMark.farPast() - private var apiError = false - private var leaderboardPosition = -1 - private var weight = -1.0 - private var localWeight = 0.0 - private var weightPerSecond = -1.0 - private var weightNeedsRecalculating = false - private var isLoadingWeight = false - private var isLoadingLeaderboard = false - private var rankGoal = -1 + private val config get() = GardenAPI.config.eliteFarmingWeights + private val localCounter = mutableMapOf() + + private var display = emptyList() + private var profileId = "" + private var lastLeaderboardUpdate = SimpleTimeMark.farPast() + private var apiError = false + private var leaderboardPosition = -1 + private var weight = -1.0 + private var localWeight = 0.0 + private var weightPerSecond = -1.0 + private var weightNeedsRecalculating = false + private var isLoadingWeight = false + private var isLoadingLeaderboard = false + private var rankGoal = -1 + + private var nextPlayers = mutableListOf() + private val nextPlayer get() = nextPlayers.firstOrNull() + + private val recalculate by lazy { + ({ + resetData() + }) + } - private var nextPlayers = mutableListOf() - private val nextPlayer get() = nextPlayers.firstOrNull() + private val eliteWeightApiGson by lazy { + BaseGsonBuilder.gson() + .registerTypeAdapter(CropType::class.java, SkyHanniTypeAdapters.CROP_TYPE.nullSafe()) + .registerTypeAdapter(PestType::class.java, SkyHanniTypeAdapters.PEST_TYPE.nullSafe()) + .create() + } - private val recalculate by lazy { - ({ - resetData() - }) - } + private val errorMessage by lazy { + listOf( + Renderable.clickAndHover( + "§cFarming Weight error: Cannot load", + listOf("§eClick here to reload the data right now!"), + onClick = recalculate + ), Renderable.clickAndHover( + "§cdata from Elite Farmers!", + listOf("§eClick here to reload the data right now!"), + onClick = recalculate + ), Renderable.clickAndHover( + "§eRejoin the garden or", + listOf("§eClick here to reload the data right now!"), + onClick = recalculate + ), Renderable.clickAndHover( + "§eclick here to fix it.", + listOf("§eClick here to reload the data right now!"), + onClick = recalculate + ) + ) + } - private val eliteWeightApiGson by lazy { - BaseGsonBuilder.gson() - .registerTypeAdapter(CropType::class.java, SkyHanniTypeAdapters.CROP_TYPE.nullSafe()) - .registerTypeAdapter(PestType::class.java, SkyHanniTypeAdapters.PEST_TYPE.nullSafe()) - .create() - } + private var lastOpenWebsite = SimpleTimeMark.farPast() - private val errorMessage by lazy { - listOf( - Renderable.clickAndHover( - "§cFarming Weight error: Cannot load", - listOf("§eClick here to reload the data right now!"), - onClick = recalculate - ), Renderable.clickAndHover( - "§cdata from Elite Farmers!", - listOf("§eClick here to reload the data right now!"), - onClick = recalculate - ), Renderable.clickAndHover( - "§eRejoin the garden or", - listOf("§eClick here to reload the data right now!"), - onClick = recalculate - ), Renderable.clickAndHover( - "§eclick here to fix it.", - listOf("§eClick here to reload the data right now!"), - onClick = recalculate - ) - ) + private fun update() { + if (!isEnabled()) return + if (apiError) { + display = errorMessage + return } - private var lastOpenWebsite = SimpleTimeMark.farPast() - - private fun update() { - if (!isEnabled()) return - if (apiError) { - display = errorMessage - return - } + if (weight == -1.0) { + if (!isLoadingWeight) { + val localProfile = HypixelData.profileName - if (weight == -1.0) { - if (!isLoadingWeight) { - val localProfile = HypixelData.profileName - - isLoadingWeight = true - if (display.isEmpty()) { - display = Renderable.singeltonString("§6Farming Weight§7: §eLoading..") - } - SkyHanniMod.coroutineScope.launch { - loadWeight(localProfile) - isLoadingWeight = false - } + isLoadingWeight = true + if (display.isEmpty()) { + display = Renderable.singeltonString("§6Farming Weight§7: §eLoading..") + } + SkyHanniMod.coroutineScope.launch { + loadWeight(localProfile) + isLoadingWeight = false } - return } + return + } - val weight = getWeight() + val weight = getWeight() - if (rankGoal == -1) rankGoal = getRankGoal() - val leaderboard = getLeaderboard() + if (rankGoal == -1) rankGoal = getRankGoal() + val leaderboard = getLeaderboard() - val list = mutableListOf() - list.add( - Renderable.clickAndHover( - "§6Farming Weight§7: $weight$leaderboard", - listOf("§eClick to open your Farming Profile."), onClick = { - openWebsite(LorenzUtils.getPlayerName()) - } - ) + val list = mutableListOf() + list.add( + Renderable.clickAndHover( + "§6Farming Weight§7: $weight$leaderboard", + listOf("§eClick to open your Farming Profile."), + onClick = { openWebsite(LorenzUtils.getPlayerName()) } ) + ) - if (isEtaEnabled() && (weightPerSecond != -1.0 || config.overtakeETAAlways)) { - getETA()?.let { - list.add(it) - } + if (isEtaEnabled() && (weightPerSecond != -1.0 || config.overtakeETAAlways)) { + getETA()?.let { + list.add(it) } - display = list } + display = list + } - private fun getLeaderboard(): String { - if (!config.leaderboard) return "" - - // Fetching new leaderboard position every 10.5 minutes - if (lastLeaderboardUpdate.passedSince() > 10.5.minutes) { - loadLeaderboardIfAble() - } + private fun getLeaderboard(): String { + if (!config.leaderboard) return "" - return if (leaderboardPosition != -1) { - val format = leaderboardPosition.addSeparators() - " §7[§b#$format§7]" - } else { - if (isLoadingLeaderboard) " §7[§b#?§7]" else "" - } + // Fetching new leaderboard position every 10.5 minutes + if (lastLeaderboardUpdate.passedSince() > 10.5.minutes) { + loadLeaderboardIfAble() } - private fun getWeight(): String { - if (weightNeedsRecalculating) { - val values = calculateCollectionWeight().values - if (values.isNotEmpty()) { - localWeight = values.sum() - weightNeedsRecalculating = false - } - } - - val totalWeight = (localWeight + weight) - return "§e" + totalWeight.round(2).addSeparators() + return if (leaderboardPosition != -1) { + val format = leaderboardPosition.addSeparators() + " §7[§b#$format§7]" + } else { + if (isLoadingLeaderboard) " §7[§b#?§7]" else "" } + } - private fun getRankGoal(): Int { - val value = config.etaGoalRank - var goal = 10000 - - // Check that the provided string is valid - val parsed = value.toIntOrNull() ?: 0 - if (parsed < 1 || parsed > goal) { - ChatUtils.chatAndOpenConfig( - "Invalid Farming Weight Overtake Goal! Click here to edit the Overtake Goal config value " + - "to a valid number [1-10000] to use this feature!", - GardenAPI.config.eliteFarmingWeights::etaGoalRank - ) - config.etaGoalRank = goal.toString() - } else { - goal = parsed - } - - // Fetch the positions again if the goal was changed - if (rankGoal != goal) { - loadLeaderboardIfAble() + private fun getWeight(): String { + if (weightNeedsRecalculating) { + val values = calculateCollectionWeight().values + if (values.isNotEmpty()) { + localWeight = values.sum() + weightNeedsRecalculating = false } - - return goal } - private fun getETA(): Renderable? { - if (weight < 0) return null + val totalWeight = (localWeight + weight) + return "§e" + totalWeight.round(2).addSeparators() + } - val nextPlayer = nextPlayer ?: return Renderable.clickAndHover( - "§cWaiting for leaderboard update...", - listOf("§eClick here to load new data right now!"), - onClick = recalculate + private fun getRankGoal(): Int { + val value = config.etaGoalRank + var goal = 10000 + + // Check that the provided string is valid + val parsed = value.toIntOrNull() ?: 0 + if (parsed < 1 || parsed > goal) { + ChatUtils.chatAndOpenConfig( + "Invalid Farming Weight Overtake Goal! Click here to edit the Overtake Goal config value " + + "to a valid number [1-10000] to use this feature!", + GardenAPI.config.eliteFarmingWeights::etaGoalRank ) - val showRankGoal = leaderboardPosition == -1 || leaderboardPosition > rankGoal - var nextName = - if (showRankGoal) "#$rankGoal" else nextPlayer.name + config.etaGoalRank = goal.toString() + } else { + goal = parsed + } - val totalWeight = (localWeight + weight) - var weightUntilOvertake = nextPlayer.weight - totalWeight + // Fetch the positions again if the goal was changed + if (rankGoal != goal) { + loadLeaderboardIfAble() + } - if (weightUntilOvertake < 0) { - if (weightPerSecond > 0) { - farmingChatMessage("You passed §b$nextName §ein the Farming Weight Leaderboard!") - } + return goal + } - // Lower leaderboard position - if (leaderboardPosition == -1) { - leaderboardPosition = 10000 - } else { - leaderboardPosition-- - } - GardenAPI.storage?.farmingWeight?.lastFarmingWeightLeaderboard = - leaderboardPosition + private fun getETA(): Renderable? { + if (weight < 0) return null - // Remove passed player to present the next one - nextPlayers.removeFirst() + val nextPlayer = nextPlayer ?: return Renderable.clickAndHover( + "§cWaiting for leaderboard update...", + listOf("§eClick here to load new data right now!"), + onClick = recalculate + ) + val showRankGoal = leaderboardPosition == -1 || leaderboardPosition > rankGoal + var nextName = + if (showRankGoal) "#$rankGoal" else nextPlayer.name - // Display waiting message if nextPlayers list is empty - // Update values to next player - nextName = nextPlayer.name - weightUntilOvertake = nextPlayer.weight - totalWeight - } + val totalWeight = (localWeight + weight) + var weightUntilOvertake = nextPlayer.weight - totalWeight - if (nextPlayer.weight == 0.0) { - return Renderable.clickAndHover( - "§cRejoin the garden to show ETA!", - listOf("Click here to calculate the data right now!"), - onClick = recalculate - ) + if (weightUntilOvertake < 0) { + if (weightPerSecond > 0) { + farmingChatMessage("You passed §b$nextName §ein the Farming Weight Leaderboard!") } - val timeFormat = if (weightPerSecond != -1.0) { - val timeTillOvertake = (weightUntilOvertake / weightPerSecond) * 1000 - val format = TimeUtils.formatDuration(timeTillOvertake.toLong()) - " §7(§b$format§7)" - } else "" - - val weightFormat = weightUntilOvertake.round(2).addSeparators() - val text = "§e$weightFormat$timeFormat §7behind §b$nextName" - return if (showRankGoal) { - Renderable.string(text) + // Lower leaderboard position + if (leaderboardPosition == -1) { + leaderboardPosition = 10000 } else { - Renderable.clickAndHover( - text, - listOf("§eClick to open the Farming Profile of §b$nextName."), - onClick = { openWebsite(nextName) } - ) + leaderboardPosition-- } - } + GardenAPI.storage?.farmingWeight?.lastFarmingWeightLeaderboard = + leaderboardPosition - private fun resetData() { - apiError = false - // We ask both api endpoints after every world switch - weight = -1.0 - weightPerSecond = -1.0 + // Remove passed player to present the next one + nextPlayers.removeFirst() - leaderboardPosition = -1 - weightNeedsRecalculating = true - lastLeaderboardUpdate = SimpleTimeMark.farPast() - - nextPlayers.clear() - rankGoal = -1 + // Display waiting message if nextPlayers list is empty + // Update values to next player + nextName = nextPlayer.name + weightUntilOvertake = nextPlayer.weight - totalWeight + } - localCounter.clear() + if (nextPlayer.weight == 0.0) { + return Renderable.clickAndHover( + "§cRejoin the garden to show ETA!", + listOf("Click here to calculate the data right now!"), + onClick = recalculate + ) } - private fun farmingChatMessage(message: String) { - ChatUtils.hoverableChat( - message, - listOf( - "§eClick to open your Farming Weight", - "§eprofile on §celitebot.dev", - ), - "shfarmingprofile ${LorenzUtils.getPlayerName()}" + val timeFormat = if (weightPerSecond != -1.0) { + val timeTillOvertake = (weightUntilOvertake / weightPerSecond) * 1000 + val format = TimeUtils.formatDuration(timeTillOvertake.toLong()) + " §7(§b$format§7)" + } else "" + + val weightFormat = weightUntilOvertake.round(2).addSeparators() + val text = "§e$weightFormat$timeFormat §7behind §b$nextName" + return if (showRankGoal) { + Renderable.string(text) + } else { + Renderable.clickAndHover( + text, + listOf("§eClick to open the Farming Profile of §b$nextName."), + onClick = { openWebsite(nextName) } ) } + } - private fun isEnabled() = ((OutsideSbFeature.FARMING_WEIGHT.isSelected() && !LorenzUtils.inSkyBlock) || - (LorenzUtils.inSkyBlock && (GardenAPI.inGarden() || config.showOutsideGarden))) && config.display + private fun resetData() { + apiError = false + // We ask both api endpoints after every world switch + weight = -1.0 + weightPerSecond = -1.0 - private fun isEtaEnabled() = config.overtakeETA + leaderboardPosition = -1 + weightNeedsRecalculating = true + lastLeaderboardUpdate = SimpleTimeMark.farPast() + + nextPlayers.clear() + rankGoal = -1 - fun addCrop(crop: CropType, addedCounter: Int) { - val before = getExactWeight() - localCounter[crop] = crop.getLocalCounter() + addedCounter - val after = getExactWeight() + localCounter.clear() + } - updateWeightPerSecond(crop, before, after, addedCounter) + private fun farmingChatMessage(message: String) { + ChatUtils.hoverableChat( + message, + listOf( + "§eClick to open your Farming Weight", + "§eprofile on §celitebot.dev", + ), + "shfarmingprofile ${LorenzUtils.getPlayerName()}" + ) + } - weightNeedsRecalculating = true - } + private fun isEnabled() = ((OutsideSbFeature.FARMING_WEIGHT.isSelected() && !LorenzUtils.inSkyBlock) || + (LorenzUtils.inSkyBlock && (GardenAPI.inGarden() || config.showOutsideGarden))) && config.display - private fun updateWeightPerSecond(crop: CropType, before: Double, after: Double, diff: Int) { - val speed = crop.getSpeed() ?: return - val weightDiff = (after - before) * 1000 - weightPerSecond = weightDiff / diff * speed / 1000 - } + private fun isEtaEnabled() = config.overtakeETA - private fun getExactWeight(): Double { - val values = calculateCollectionWeight().values - return if (values.isNotEmpty()) { - values.sum() - } else 0.0 - } + fun addCrop(crop: CropType, addedCounter: Int) { + val before = getExactWeight() + localCounter[crop] = crop.getLocalCounter() + addedCounter + val after = getExactWeight() - private fun loadLeaderboardIfAble() { - if (isLoadingLeaderboard) return - isLoadingLeaderboard = true + updateWeightPerSecond(crop, before, after, addedCounter) - SkyHanniMod.coroutineScope.launch { - val wasNotLoaded = leaderboardPosition == -1 - leaderboardPosition = loadLeaderboardPosition() - if (wasNotLoaded && config.showLbChange) { - checkOffScreenLeaderboardChanges() - } - GardenAPI.storage?.farmingWeight?.lastFarmingWeightLeaderboard = - leaderboardPosition - lastLeaderboardUpdate = SimpleTimeMark.now() - isLoadingLeaderboard = false - } - } + weightNeedsRecalculating = true + } - private fun checkOffScreenLeaderboardChanges() { - val profileSpecific = ProfileStorageData.profileSpecific ?: return - val oldPosition = profileSpecific.garden.farmingWeight.lastFarmingWeightLeaderboard + private fun updateWeightPerSecond(crop: CropType, before: Double, after: Double, diff: Int) { + val speed = crop.getSpeed() ?: return + val weightDiff = (after - before) * 1000 + weightPerSecond = weightDiff / diff * speed / 1000 + } - if (oldPosition <= 0) return - if (leaderboardPosition <= 0) return + private fun getExactWeight(): Double { + val values = calculateCollectionWeight().values + return if (values.isNotEmpty()) { + values.sum() + } else 0.0 + } - val diff = leaderboardPosition - oldPosition - if (diff == 0) return + private fun loadLeaderboardIfAble() { + if (isLoadingLeaderboard) return + isLoadingLeaderboard = true - if (diff > 0) { - showLbChange("§cdropped ${StringUtils.pluralize(diff, "place", withNumber = true)}", oldPosition) - } else { - showLbChange("§arisen ${StringUtils.pluralize(-diff, "place", withNumber = true)}", oldPosition) + SkyHanniMod.coroutineScope.launch { + val wasNotLoaded = leaderboardPosition == -1 + leaderboardPosition = loadLeaderboardPosition() + if (wasNotLoaded && config.showLbChange) { + checkOffScreenLeaderboardChanges() } + GardenAPI.storage?.farmingWeight?.lastFarmingWeightLeaderboard = + leaderboardPosition + lastLeaderboardUpdate = SimpleTimeMark.now() + isLoadingLeaderboard = false } + } - private fun showLbChange(direction: String, oldPosition: Int) { - farmingChatMessage( - "§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 fun checkOffScreenLeaderboardChanges() { + val profileSpecific = ProfileStorageData.profileSpecific ?: return + val oldPosition = profileSpecific.garden.farmingWeight.lastFarmingWeightLeaderboard + + if (oldPosition <= 0) return + if (leaderboardPosition <= 0) return + + val diff = leaderboardPosition - oldPosition + if (diff == 0) return + + if (diff > 0) { + showLbChange("§cdropped ${StringUtils.pluralize(diff, "place", withNumber = true)}", oldPosition) + } else { + showLbChange("§arisen ${StringUtils.pluralize(-diff, "place", withNumber = true)}", oldPosition) } + } - private fun loadLeaderboardPosition(): Int { - val uuid = LorenzUtils.getPlayerUuid() + private fun showLbChange(direction: String, oldPosition: Int) { + farmingChatMessage( + "§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)" + ) + } - val includeUpcoming = if (isEtaEnabled()) "?includeUpcomi