aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Storage.java15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasureTracker.kt78
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt18
6 files changed, 74 insertions, 55 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index a509f3c88..b4a9a1c12 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -560,7 +560,7 @@ class SkyHanniMod {
loadModule(QuickModMenuSwitch)
loadModule(ArachneChatMessageHider())
loadModule(ShowItemUuid())
- loadModule(FrozenTreasureTracker())
+ loadModule(FrozenTreasureTracker)
loadModule(SlayerRngMeterDisplay())
loadModule(GhostCounter)
loadModule(RiftTimer())
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
index 26fdd365a..21a54735e 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
@@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.data.model.ComposterUpgrade;
import at.hannibal2.skyhanni.features.combat.endernodetracker.EnderNodeTracker;
import at.hannibal2.skyhanni.features.combat.ghostcounter.GhostData;
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI;
-import at.hannibal2.skyhanni.features.event.jerry.frozentreasure.FrozenTreasure;
+import at.hannibal2.skyhanni.features.event.jerry.frozentreasure.FrozenTreasureTracker;
import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity;
import at.hannibal2.skyhanni.features.garden.CropAccessory;
import at.hannibal2.skyhanni.features.garden.CropType;
@@ -307,18 +307,7 @@ public class Storage {
public PowderTracker.Data powderTracker = new PowderTracker.Data();
@Expose
- public FrozenTreasureTracker frozenTreasureTracker = new FrozenTreasureTracker();
-
- public static class FrozenTreasureTracker {
- @Expose
- public int treasuresMined = 0;
-
- @Expose
- public int compactProcs = 0;
-
- @Expose
- public Map<FrozenTreasure, Integer> treasureCount = new HashMap<>();
- }
+ public FrozenTreasureTracker.Data frozenTreasureTracker = new FrozenTreasureTracker.Data();
@Expose
public EnderNodeTracker.Data enderNodeTracker = new EnderNodeTracker.Data();
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 c96dbab65..89885ec4d 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.features.combat.ghostcounter.GhostUtil
import at.hannibal2.skyhanni.features.commands.PartyCommands
import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper
import at.hannibal2.skyhanni.features.event.diana.InquisitorWaypointShare
+import at.hannibal2.skyhanni.features.event.jerry.frozentreasure.FrozenTreasureTracker
import at.hannibal2.skyhanni.features.fame.AccountUpgradeReminder
import at.hannibal2.skyhanni.features.fame.CityProjectFeatures
import at.hannibal2.skyhanni.features.garden.GardenAPI
@@ -169,10 +170,8 @@ object Commands {
"shresetendernodetracker",
"Resets the Ender Node Tracker"
) { EnderNodeTracker.resetCommand(it) }
- registerCommand(
- "shresetarmordroptracker",
- "Resets the Armor Drop Tracker"
- ) { ArmorDropTracker.resetCommand(it) }
+ registerCommand("shresetarmordroptracker", "Resets the Armor Drop Tracker") { ArmorDropTracker.resetCommand(it) }
+ registerCommand("shresetfrozentreasuretracker", "Resets the Frozen Treasure Tracker") { FrozenTreasureTracker.resetCommand(it) }
registerCommand("shbingotoggle", "Toggle the bingo card display mode") { BingoCardDisplay.toggleCommand() }
registerCommand(
"shfarmingprofile",
diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt
index 802e593e9..1b10bf7eb 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt
@@ -215,9 +215,6 @@ object EnderNodeTracker {
if (!ProfileStorageData.loaded) return emptyList<List<Any>>()
addAsSingletonList("§5§lEnder Node Tracker")
-
- tracker.addDisplayModeToggle(this)
-
addAsSingletonList("§d${storage.totalNodesMined.addSeparators()} Ender Nodes mined")
addAsSingletonList("§6${format(lootProfit.values.sum())} Coins made")
addAsSingletonList(" ")
@@ -244,8 +241,6 @@ object EnderNodeTracker {
val (c, u, r, e, l) = EnderNode.entries.subList(16, 21).map { (storage.lootCount[it] ?: 0).addSeparators() }
val profit = format(EnderNode.entries.subList(16, 21).sumOf { lootProfit[it] ?: 0.0 })
addAsSingletonList("§f$c§7-§a$u§7-§9$r§7-§5$e§7-§6$l §fEnderman Pet §7(§6$profit§7)")
-
- tracker.addSessionResetButton(this)
}
private fun calculateEnderArmor(storage: Data) =
@@ -259,7 +254,11 @@ object EnderNodeTracker {
val newList = mutableListOf<List<Any>>()
for (index in config.textFormat.get()) {
newList.add(map[index])
+ if (newList.size == 1) {
+ tracker.addDisplayModeToggle(newList)
+ }
}
+ tracker.addSessionResetButton(newList)
return newList
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasureTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasureTracker.kt
index ee72bec69..fa10aa501 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasureTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/event/jerry/frozentreasure/FrozenTreasureTracker.kt
@@ -2,7 +2,6 @@ package at.hannibal2.skyhanni.features.event.jerry.frozentreasure
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
-import at.hannibal2.skyhanni.config.Storage
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.data.ScoreboardData
@@ -11,17 +10,19 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.PreProfileSwitchEvent
import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
-import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy
+import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
-import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
+import at.hannibal2.skyhanni.utils.tracker.TrackerData
+import com.google.gson.annotations.Expose
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.concurrent.fixedRateTimer
-class FrozenTreasureTracker {
+object FrozenTreasureTracker {
private val config get() = SkyHanniMod.feature.event.winter.frozenTreasureTracker
private var display = emptyList<List<Any>>()
private var estimatedIce = 0L
@@ -30,6 +31,8 @@ class FrozenTreasureTracker {
private var icePerHour = 0
private var stoppedChecks = 0
private var compactPattern = "COMPACT! You found an Enchanted Ice!".toPattern()
+ private val tracker = SkyHanniTracker("Frozen Treasure Tracker", { Data() }, { it.frozenTreasureTracker })
+ { saveAndUpdate() }
init {
fixedRateTimer(name = "skyhanni-frozen-treasure-tracker", period = 1000) {
@@ -38,6 +41,24 @@ class FrozenTreasureTracker {
}
}
+ class Data : TrackerData() {
+
+ override fun reset() {
+ treasureCount.clear()
+ treasuresMined = 0
+ compactProcs = 0
+ }
+
+ @Expose
+ var treasuresMined = 0
+
+ @Expose
+ var compactProcs = 0
+
+ @Expose
+ var treasureCount: MutableMap<FrozenTreasure, Int> = mutableMapOf()
+ }
+
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
icePerHour = 0
@@ -78,7 +99,11 @@ class FrozenTreasureTracker {
val newList = mutableListOf<List<Any>>()
for (index in config.textFormat) {
newList.add(map[index])
+ if (newList.size == 1) {
+ tracker.addDisplayModeToggle(newList)
+ }
}
+ tracker.addSessionResetButton(newList)
return newList
}
@@ -88,19 +113,21 @@ class FrozenTreasureTracker {
if (!onJerryWorkshop()) return
val message = event.message.removeColor().trim()
- val storage = ProfileStorageData.profileSpecific?.frozenTreasureTracker ?: return
compactPattern.matchMatcher(message) {
- storage.compactProcs += 1
+ tracker.modify {
+ it.compactProcs += 1
+ }
saveAndUpdate()
if (config.hideMessages) event.blockedReason = "frozen treasure tracker"
}
for (treasure in FrozenTreasure.entries) {
if ("FROZEN TREASURE! You found ${treasure.displayName.removeColor()}!".toRegex().matches(message)) {
- storage.treasuresMined += 1
- val old = storage.treasureCount[treasure] ?: 0
- storage.treasureCount = storage.treasureCount.editCopy { this[treasure] = old + 1 }
+ tracker.modify {
+ it.treasuresMined += 1
+ it.treasureCount.addOrPut(treasure, 1)
+ }
saveAndUpdate()
if (config.hideMessages) event.blockedReason = "frozen treasure tracker"
}
@@ -112,16 +139,16 @@ class FrozenTreasureTracker {
display = emptyList()
}
- private fun drawTreasureDisplay(storage: Storage.ProfileSpecific.FrozenTreasureTracker) = buildList<List<Any>> {
+ private fun drawTreasureDisplay(data: Data) = buildList<List<Any>> {
addAsSingletonList("§1§lFrozen Treasure Tracker")
- addAsSingletonList("§6${formatNumber(storage.treasuresMined)} Treasures Mined")
+ addAsSingletonList("§6${formatNumber(data.treasuresMined)} Treasures Mined")
addAsSingletonList("§3${formatNumber(estimatedIce)} Total Ice")
addAsSingletonList("§3${formatNumber(icePerHour)} Ice/hr")
- addAsSingletonList("§8${formatNumber(storage.treasuresMined)} Compact Procs")
+ addAsSingletonList("§8${formatNumber(data.treasuresMined)} Compact Procs")
addAsSingletonList("")
for (treasure in FrozenTreasure.entries) {
- val count = (storage.treasureCount[treasure] ?: 0) * if (config.showAsDrops) treasure.defaultAmount else 1
+ val count = (data.treasureCount[treasure] ?: 0) * if (config.showAsDrops) treasure.defaultAmount else 1
addAsSingletonList("§b${formatNumber(count)} ${treasure.displayName}")
}
addAsSingletonList("")
@@ -134,26 +161,26 @@ class FrozenTreasureTracker {
}
private fun saveAndUpdate() {
- val storage = ProfileStorageData.profileSpecific?.frozenTreasureTracker ?: return
- calculateIce(storage)
- display = formatDisplay(drawTreasureDisplay(storage))
+ val data = tracker.currentDisplay() ?: return
+ calculateIce(data)
+ display = formatDisplay(drawTreasureDisplay(data))
}
- private fun calculateIce(storage: Storage.ProfileSpecific.FrozenTreasureTracker) {
- estimatedIce = 0
- estimatedIce += storage.compactProcs * 160
+ private fun calculateIce(data: Data) {
+ estimatedIce = data.compactProcs * 160L
for (treasure in FrozenTreasure.entries) {
- val amount = storage.treasureCount[treasure] ?: 0
+ val amount = data.treasureCount[treasure] ?: 0
estimatedIce += amount * treasure.defaultAmount * treasure.iceMultiplier
}
}
@SubscribeEvent
- fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
+ fun onRenderOverlay(event: GuiRenderEvent) {
if (!config.enabled) return
if (!onJerryWorkshop()) return
if (config.onlyInCave && !inGlacialCave()) return
- config.position.renderStringsAndItems(display, posLabel = "Frozen Treasure Tracker")
+
+ tracker.renderDisplay(config.position, display)
}
@SubscribeEvent
@@ -163,5 +190,10 @@ class FrozenTreasureTracker {
private fun onJerryWorkshop() = IslandType.WINTER.isInIsland()
- private fun inGlacialCave() = onJerryWorkshop() && ScoreboardData.sidebarLinesFormatted.contains(" §7⏣ §3Glacial Cave")
+ private fun inGlacialCave() =
+ onJerryWorkshop() && ScoreboardData.sidebarLinesFormatted.contains(" §7⏣ §3Glacial Cave")
+
+ fun resetCommand(args: Array<String>) {
+ tracker.resetCommand(args, "shresetfrozentreasuretracker")
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
index 4cf1f8e5f..ec0fc4848 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
@@ -23,14 +23,6 @@ class SkyHanniTracker<Data : TrackerData>(
fun isInventoryOpen() = inventoryOpen
- private fun getSharedTracker(): SharedTracker<Data>? {
- val profileSpecific = ProfileStorageData.profileSpecific ?: return null
- return SharedTracker(getStorage(profileSpecific), getCurrentSession(profileSpecific))
- }
-
- private fun getCurrentSession(profileSpecific: Storage.ProfileSpecific) =
- currentSessions.getOrPut(profileSpecific) { createNewSession() }
-
fun addSessionResetButton(list: MutableList<List<Any>>) {
if (!inventoryOpen || displayMode != DisplayMode.SESSION) return
@@ -89,6 +81,14 @@ class SkyHanniTracker<Data : TrackerData>(
position.renderStringsAndItems(display, posLabel = name)
}
+ private fun getSharedTracker(): SharedTracker<Data>? {
+ val profileSpecific = ProfileStorageData.profileSpecific ?: return null
+ return SharedTracker(getStorage(profileSpecific), getCurrentSession(profileSpecific))
+ }
+
+ private fun getCurrentSession(profileSpecific: Storage.ProfileSpecific) =
+ currentSessions.getOrPut(profileSpecific) { createNewSession() }
+
private fun reset(displayMode: DisplayMode, message: String) {
getSharedTracker()?.get(displayMode)?.let {
it.reset()
@@ -97,7 +97,7 @@ class SkyHanniTracker<Data : TrackerData>(
}
}
- class SharedTracker<Data : TrackerData>(private val total: Data, private val currentSession: Data, ) {
+ class SharedTracker<Data : TrackerData>(private val total: Data, private val currentSession: Data) {
fun modify(modifyFunction: (Data) -> Unit) {
modifyFunction(total)
modifyFunction(currentSession)