aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/TrackerManager.kt31
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaProfitTracker.kt24
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt32
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestProfitTracker.kt35
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt20
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt32
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt23
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt24
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/ItemTrackerData.kt11
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt38
13 files changed, 202 insertions, 76 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
index 3e7e1f7bf..1f5adacf7 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.api
+import at.hannibal2.skyhanni.data.ItemAddManager
import at.hannibal2.skyhanni.events.CollectionUpdateEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.ItemAddEvent
@@ -88,6 +89,7 @@ object CollectionAPI {
@SubscribeEvent
fun onItemAdd(event: ItemAddEvent) {
+ if (event.source == ItemAddManager.Source.COMMAND) return
val internalName = event.internalName
val amount = NEUItems.getPrimitiveMultiplier(internalName).amount
if (amount > 1) return
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 f7101cd4b..edfdb2d7a 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.data.PartyAPI
import at.hannibal2.skyhanni.data.SackAPI
import at.hannibal2.skyhanni.data.ScoreboardData
import at.hannibal2.skyhanni.data.TitleManager
+import at.hannibal2.skyhanni.data.TrackerManager
import at.hannibal2.skyhanni.data.bazaar.HypixelBazaarFetcher
import at.hannibal2.skyhanni.features.bingo.card.BingoCardDisplay
import at.hannibal2.skyhanni.features.bingo.card.nextstephelper.BingoNextStepHelper
@@ -438,6 +439,10 @@ object Commands {
"shresetpunchcard",
"Resets the Rift Punchcard Artifact player list.",
) { PunchcardHighlight.clearList() }
+ registerCommand(
+ "shedittracker",
+ "Changes the tracked item amount for Diana, Fishing, Pest, Excavator, and Slayer Item Trackers.",
+ ) { TrackerManager.commandEditTracker(it) }
}
private fun developersDebugFeatures() {
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt
index 26658eee7..4906f5f80 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt
@@ -25,6 +25,7 @@ object ItemAddManager {
enum class Source {
ITEM_ADD,
SACKS,
+ COMMAND,
}
private val ARCHFIEND_DICE = "ARCHFIEND_DICE".asInternalName()
diff --git a/src/main/java/at/hannibal2/skyhanni/data/TrackerManager.kt b/src/main/java/at/hannibal2/skyhanni/data/TrackerManager.kt
index 71b60d76e..c1a7a60c3 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/TrackerManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/TrackerManager.kt
@@ -3,8 +3,12 @@ package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.ItemAddEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
+import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.ConditionalUtils
+import at.hannibal2.skyhanni.utils.NEUInternalName
+import at.hannibal2.skyhanni.utils.NumberUtil.formatIntOrUserError
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -13,6 +17,7 @@ object TrackerManager {
private var hasChanged = false
var dirty = false
+ var commandEditTrackerSuccess = false
@SubscribeEvent
fun onConfigLoad(event: ConfigLoadEvent) {
@@ -36,4 +41,30 @@ object TrackerManager {
hasChanged = false
}
}
+
+ fun commandEditTracker(args: Array<String>) {
+ if (args.size < 2) {
+ ChatUtils.userError("Usage: /shedittracker <item name> <amount>")
+ return
+ }
+
+ val amount = args.last().formatIntOrUserError() ?: return
+ if (amount == 0) {
+ ChatUtils.userError("Amount can not be zero!")
+ return
+ }
+
+ val rawName = args.dropLast(1).joinToString(" ")
+ val internalName = NEUInternalName.fromItemNameOrInternalName(rawName)
+ if (!internalName.isKnownItem()) {
+ ChatUtils.chat("No item found for '$rawName'!")
+ return
+ }
+
+ commandEditTrackerSuccess = false
+ ItemAddEvent(internalName, amount, ItemAddManager.Source.COMMAND).postAndCatch()
+ if (!commandEditTrackerSuccess) {
+ ChatUtils.userError("Could not edit the Item Tracker! Does this item belong to this tracker? Is the tracker active right now?")
+ }
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaProfitTracker.kt
index 1ba2724c3..01d2c1d2e 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaProfitTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaProfitTracker.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.features.event.diana
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.ItemAddManager
import at.hannibal2.skyhanni.data.jsonobjects.repo.DianaDropsJson
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.ItemAddEvent
@@ -33,17 +34,18 @@ object DianaProfitTracker {
private val patternGroup = RepoPattern.group("diana.chat")
private val chatDugOutPattern by patternGroup.pattern(
"burrow.dug",
- "(§eYou dug out a Griffin Burrow!|§eYou finished the Griffin burrow chain!) .*"
+ "(§eYou dug out a Griffin Burrow!|§eYou finished the Griffin burrow chain!) .*",
)
private val chatDugOutCoinsPattern by patternGroup.pattern(
"coins",
- "§6§lWow! §r§eYou dug out §r§6(?<coins>.*) coins§r§e!"
+ "§6§lWow! §r§eYou dug out §r§6(?<coins>.*) coins§r§e!",
)
private val tracker = SkyHanniItemTracker(
"Diana Profit Tracker",
{ Data() },
- { it.diana.dianaProfitTracker }) { drawDisplay(it) }
+ { it.diana.dianaProfitTracker },
+ ) { drawDisplay(it) }
class Data : ItemTrackerData() {
@@ -70,7 +72,7 @@ object DianaProfitTracker {
val burrowDugCoinsFormat = item.totalAmount.shortFormat()
return listOf(
"§7Digging treasures gave you",
- "§6$burrowDugCoinsFormat coins §7in total."
+ "§6$burrowDugCoinsFormat coins §7in total.",
)
}
}
@@ -84,8 +86,8 @@ object DianaProfitTracker {
addAsSingletonList(
Renderable.hoverTips(
"§7Burrows dug: §e${treasureCoins.addSeparators()}",
- listOf("§7You dug out griffin burrows §e${treasureCoins.addSeparators()} §7times.")
- )
+ listOf("§7You dug out griffin burrows §e${treasureCoins.addSeparators()} §7times."),
+ ),
)
addAsSingletonList(tracker.addTotalProfit(profit, data.burrowsDug, "burrow"))
@@ -97,14 +99,16 @@ object DianaProfitTracker {
fun onItemAdd(event: ItemAddEvent) {
if (!isEnabled()) return
- val internalName = event.internalName
+ tryAddItem(event.internalName, event.amount, event.source == ItemAddManager.Source.COMMAND)
+ }
- if (!isAllowedItem(internalName)) {
+ private fun tryAddItem(internalName: NEUInternalName, amount: Int, command: Boolean) {
+ if (!isAllowedItem(internalName) && internalName != NEUInternalName.SKYBLOCK_COIN) {
ChatUtils.debug("Ignored non-diana item pickup: '$internalName'")
return
}
- tracker.addItem(internalName, event.amount)
+ tracker.addItem(internalName, amount, command)
}
@SubscribeEvent
@@ -119,7 +123,7 @@ object DianaProfitTracker {
}
chatDugOutCoinsPattern.matchMatcher(message) {
BurrowAPI.lastBurrowRelatedChatMessage = SimpleTimeMark.now()
- tracker.addCoins(group("coins").formatInt())
+ tryAddItem(NEUInternalName.SKYBLOCK_COIN, group("coins").formatInt(), command = false)
tryHide(event)
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt
index b99c03ff5..a0590816e 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/tracker/FishingProfitTracker.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.features.fishing.tracker
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.ItemAddManager
import at.hannibal2.skyhanni.data.jsonobjects.repo.FishingProfitItemsJson
import at.hannibal2.skyhanni.events.FishingBobberCastEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
@@ -43,14 +44,15 @@ object FishingProfitTracker {
private val coinsChatPattern by RepoPattern.pattern(
"fishing.tracker.chat.coins",
- ".* CATCH! §r§bYou found §r§6(?<coins>.*) Coins§r§b\\."
+ ".* CATCH! §r§bYou found §r§6(?<coins>.*) Coins§r§b\\.",
)
private var lastCatchTime = SimpleTimeMark.farPast()
private val tracker = SkyHanniItemTracker(
"Fishing Profit Tracker",
{ Data() },
- { it.fishing.fishingProfitTracker }) { drawDisplay(it) }
+ { it.fishing.fishingProfitTracker },
+ ) { drawDisplay(it) }
class Data : ItemTrackerData() {
@@ -64,7 +66,7 @@ object FishingProfitTracker {
return listOf(
"§7Caught §e${timesCaught.addSeparators()} §7times.",
- "§7Your catch rate: §c$catchRate"
+ "§7Your catch rate: §c$catchRate",
)
}
@@ -73,7 +75,7 @@ object FishingProfitTracker {
override fun getCoinDescription(item: TrackedItem): List<String> {
val mobKillCoinsFormat = item.totalAmount.shortFormat()
return listOf(
- "§7You fished up §6$mobKillCoinsFormat coins §7already."
+ "§7You fished up §6$mobKillCoinsFormat coins §7already.",
)
}
@@ -127,8 +129,8 @@ object FishingProfitTracker {
addAsSingletonList(
Renderable.hoverTips(
"§7Times fished: §e${fishedCount.addSeparators()}",
- listOf("§7You've reeled in §e${fishedCount.addSeparators()} §7catches.")
- )
+ listOf("§7You've reeled in §e${fishedCount.addSeparators()} §7catches."),
+ ),
)
addAsSingletonList(tracker.addTotalProfit(profit, data.totalCatchAmount, "catch"))
@@ -152,7 +154,7 @@ object FishingProfitTracker {
val id = list.indexOf(currentCategory)
currentCategory = list[(id + 1) % list.size]
tracker.update()
- }
+ },
)
}
@@ -178,7 +180,7 @@ object FishingProfitTracker {
"Loaded $label not in a fishing category",
"Found items missing in itemCategories",
"missingItems" to missingItems,
- noStackTrace = true
+ noStackTrace = true,
)
}
}
@@ -186,15 +188,21 @@ object FishingProfitTracker {
@SubscribeEvent
fun onItemAdd(event: ItemAddEvent) {
if (!isEnabled()) return
+
+ if (event.source == ItemAddManager.Source.COMMAND) {
+ tryAddItem(event.internalName, event.amount, command = true)
+ return
+ }
+
DelayedRun.runDelayed(500.milliseconds) {
- maybeAddItem(event.internalName, event.amount)
+ tryAddItem(event.internalName, event.amount, command = false)
}
}
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
coinsChatPattern.matchMatcher(event.message) {
- tracker.addCoins(group("coins").formatInt())
+ tryAddItem(NEUInternalName.SKYBLOCK_COIN, group("coins").formatInt(), command = false)
addCatch()
}
}
@@ -221,14 +229,14 @@ object FishingProfitTracker {
lastCatchTime = SimpleTimeMark.farPast()
}
- private fun maybeAddItem(internalName: NEUInternalName, amount: Int) {
+ private fun tryAddItem(internalName: NEUInternalName, amount: Int, command: Boolean) {
if (!FishingAPI.isFishing(checkRodInHand = false)) return
if (!isAllowedItem(internalName)) {
ChatUtils.debug("Ignored non-fishing item pickup: $internalName'")
return
}
- tracker.addItem(internalName, amount)
+ tracker.addItem(internalName, amount, command)
addCatch()
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestProfitTracker.kt
index 5f630335b..1d2710c7c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestProfitTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestProfitTracker.kt
@@ -2,8 +2,10 @@ package at.hannibal2.skyhanni.features.garden.pests
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.IslandType
+import at.hannibal2.skyhanni.data.ItemAddManager
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.IslandChangeEvent
+import at.hannibal2.skyhanni.events.ItemAddEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.PurseChangeCause
import at.hannibal2.skyhanni.events.PurseChangeEvent
@@ -37,14 +39,15 @@ object PestProfitTracker {
*/
private val pestRareDropPattern by patternGroup.pattern(
"raredrop",
- "§6§l(?:RARE|PET) DROP! (?:§r)?(?<item>.+) §6\\(§6\\+.*☘\\)"
+ "§6§l(?:RARE|PET) DROP! (?:§r)?(?<item>.+) §6\\(§6\\+.*☘\\)",
)
private var lastPestKillTime = SimpleTimeMark.farPast()
private val tracker = SkyHanniItemTracker(
"Pest Profit Tracker",
{ Data() },
- { it.garden.pestProfitTracker }) { drawDisplay(it) }
+ { it.garden.pestProfitTracker },
+ ) { drawDisplay(it) }
class Data : ItemTrackerData() {
override fun resetItems() {
@@ -56,7 +59,7 @@ object PestProfitTracker {
val dropRate = LorenzUtils.formatPercentage(percentage.coerceAtMost(1.0))
return listOf(
"§7Dropped §e${timesGained.addSeparators()} §7times.",
- "§7Your drop rate: §c$dropRate."
+ "§7Your drop rate: §c$dropRate.",
)
}
@@ -66,7 +69,7 @@ object PestProfitTracker {
val pestsCoinsFormat = item.totalAmount.shortFormat()
return listOf(
"§7Killing pests gives you coins.",
- "§7You got §6$pestsCoinsFormat coins §7that way."
+ "§7You got §6$pestsCoinsFormat coins §7that way.",
)
}
@@ -75,24 +78,38 @@ object PestProfitTracker {
}
@SubscribeEvent
+ fun onItemAdd(event: ItemAddEvent) {
+ if (!isEnabled()) return
+
+ val internalName = event.internalName
+ if (event.source == ItemAddManager.Source.COMMAND) {
+ tryAddItem(internalName, event.amount, command = true)
+ }
+ }
+
+ @SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (!isEnabled()) return
PestAPI.pestDeathChatPattern.matchMatcher(event.message) {
val amount = group("amount").toInt()
val internalName = NEUInternalName.fromItemNameOrNull(group("item")) ?: return
- tracker.addItem(internalName, amount)
+ tryAddItem(internalName, amount, command = false)
addKill()
if (config.hideChat) event.blockedReason = "pest_drop"
}
pestRareDropPattern.matchMatcher(event.message) {
val internalName = NEUInternalName.fromItemNameOrNull(group("item")) ?: return
- tracker.addItem(internalName, 1)
+ tryAddItem(internalName, 1, command = false)
// pests always have guaranteed loot, therefore there's no need to add kill here
}
}
+ private fun tryAddItem(internalName: NEUInternalName, amount: Int, command: Boolean) {
+ tracker.addItem(internalName, amount, command)
+ }
+
private fun addKill() {
tracker.modify {
it.totalPestsKills++
@@ -108,8 +125,8 @@ object PestProfitTracker {
addAsSingletonList(
Renderable.hoverTips(
"§7Pests killed: §e${pestsKilled.addSeparators()}",
- listOf("§7You killed pests §e${pestsKilled.addSeparators()} §7times.")
- )
+ listOf("§7You killed pests §e${pestsKilled.addSeparators()} §7times."),
+ ),
)
addAsSingletonList(tracker.addTotalProfit(profit, data.totalPestsKills, "kill"))
@@ -131,7 +148,7 @@ object PestProfitTracker {
val coins = event.coins
if (coins > 1000) return
if (event.reason == PurseChangeCause.GAIN_MOB_KILL && lastPestKillTime.passedSince() < 2.seconds) {
- tracker.addCoins(coins.toInt())
+ tryAddItem(NEUInternalName.SKYBLOCK_COIN, coins.toInt(), command = false)
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt
index dcf9b8c4d..ef3b780b7 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt
@@ -2,8 +2,10 @@ package at.hannibal2.skyhanni.features.mining.fossilexcavator
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.IslandType
+import at.hannibal2.skyhanni.data.ItemAddManager
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.IslandChangeEvent
+import at.hannibal2.skyhanni.events.ItemAddEvent
import at.hannibal2.skyhanni.events.mining.FossilExcavationEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
@@ -155,6 +157,20 @@ object ExcavatorProfitTracker {
}
@SubscribeEvent
+ fun onItemAdd(event: ItemAddEvent) {
+ if (!isEnabled()) return
+
+ val internalName = event.internalName
+ if (event.source == ItemAddManager.Source.COMMAND) {
+ tryAddItem(internalName, event.amount, command = true)
+ }
+ }
+
+ private fun tryAddItem(internalName: NEUInternalName, amount: Int, command: Boolean) {
+ tracker.addItem(internalName, amount, command)
+ }
+
+ @SubscribeEvent
fun onFossilExcavation(event: FossilExcavationEvent) {
if (!isEnabled()) return
for ((name, amount) in event.loot) {
@@ -185,11 +201,11 @@ object ExcavatorProfitTracker {
val internalName = NEUInternalName.fromItemNameOrNull(name)
if (internalName == null) {
- ChatUtils.debug("no price for exavator profit: '$name'")
+ ChatUtils.debug("no price for excavator profit: '$name'")
return
}
// TODO use primitive item stacks in trackers
- tracker.addItem(internalName, amount)
+ tryAddItem(internalName, amount, command = false)
}
@SubscribeEvent
diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt
index 372c7daa9..d2f50358d 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.slayer
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage
+import at.hannibal2.skyhanni.data.ItemAddManager
import at.hannibal2.skyhanni.data.SlayerAPI
import at.hannibal2.skyhanni.data.jsonobjects.repo.SlayerProfitTrackerItemsJson
import at.hannibal2.skyhanni.events.GuiRenderEvent
@@ -46,7 +47,7 @@ object SlayerProfitTracker {
*/
private val autoSlayerBankPattern by RepoPattern.pattern(
"slayer.autoslayer.bank.chat",
- "§7Took (?<coins>.+) coins from your bank for auto-slayer\\.\\.\\."
+ "§7Took (?<coins>.+) coins from your bank for auto-slayer\\.\\.\\.",
)
class Data : ItemTrackerData() {
@@ -78,7 +79,7 @@ object SlayerProfitTracker {
val mobKillCoinsFormat = item.totalAmount.shortFormat()
return listOf(
"§7Killing mobs gives you coins (more with scavenger).",
- "§7You got §6$mobKillCoinsFormat coins §7that way."
+ "§7You got §6$mobKillCoinsFormat coins §7that way.",
)
}
}
@@ -104,7 +105,7 @@ object SlayerProfitTracker {
if (!isEnabled()) return
val coins = event.coins
if (event.reason == PurseChangeCause.GAIN_MOB_KILL && SlayerAPI.isInCorrectArea) {
- getTracker()?.addCoins(coins.toInt())
+ tryAddItem(NEUInternalName.SKYBLOCK_COIN, coins.toInt(), command = false)
}
if (event.reason == PurseChangeCause.LOSE_SLAYER_QUEST_STARTED) {
addSlayerCosts(coins)
@@ -133,7 +134,7 @@ object SlayerProfitTracker {
return trackers.getOrPut(itemLogCategory) {
val getStorage: (ProfileSpecificStorage) -> Data = {
it.slayerProfitData.getOrPut(
- itemLogCategory
+ itemLogCategory,
) { Data() }
}
SkyHanniItemTracker("$itemLogCategory Profit Tracker", { Data() }, getStorage) { drawDisplay(it) }
@@ -153,15 +154,16 @@ object SlayerProfitTracker {
if (!SlayerAPI.isInCorrectArea) return
if (!SlayerAPI.hasActiveSlayerQuest()) return
- val internalName = event.internalName
- val amount = event.amount
+ tryAddItem(event.internalName, event.amount, event.source == ItemAddManager.Source.COMMAND)
+ }
- if (!isAllowedItem(internalName)) {
+ private fun tryAddItem(internalName: NEUInternalName, amount: Int, command: Boolean) {
+ if (!isAllowedItem(internalName) && internalName != NEUInternalName.SKYBLOCK_COIN) {
ChatUtils.debug("Ignored non-slayer item pickup: '$internalName' '$itemLogCategory'")
return
}
- getTracker()?.addItem(internalName, amount)
+ getTracker()?.addItem(internalName, amount, command)
}
private fun isAllowedItem(internalName: NEUInternalName): Boolean {
@@ -176,12 +178,12 @@ object SlayerProfitTracker {
var profit = tracker.drawItems(data, { true }, this)
val slayerSpawnCost = data.slayerSpawnCost
if (slayerSpawnCost != 0L) {
- val mobKillCoinsFormat = slayerSpawnCost.shortFormat()
+ val slayerSpawnCostFormat = slayerSpawnCost.shortFormat()
addAsSingletonList(
Renderable.hoverTips(
- " §7Slayer Spawn Costs: §c$mobKillCoinsFormat",
- listOf("§7You paid §c$mobKillCoinsFormat §7in total", "§7for starting the slayer quests.")
- )
+ " §7Slayer Spawn Costs: §c$slayerSpawnCostFormat",
+ listOf("§7You paid §c$slayerSpawnCostFormat §7in total", "§7for starting the slayer quests."),
+ ),
)
profit += slayerSpawnCost
}
@@ -190,8 +192,8 @@ object SlayerProfitTracker {
addAsSingletonList(
Renderable.hoverTips(
"§7Bosses killed: §e${slayerCompletedCount.addSeparators()}",
- listOf("§7You killed the $itemLogCategory boss", "§e${slayerCompletedCount.addSeparators()} §7times.")
- )
+ listOf("§7You killed the $itemLogCategory boss", "§e${slayerCompletedCount.addSeparators()} §7times."),
+ ),
)
addAsSingletonList(tracker.addTotalProfit(profit, data.slayerCompletedCount, "boss"))
@@ -204,7 +206,7 @@ object SlayerProfitTracker {
val text = " §6Mob kill coins§7: §6$mobKillCoinsFormat"
val lore = listOf(
"§7Killing mobs gives you coins (more with scavenger)",
- "§7You got §e$mobKillCoinsFormat §7coins in total this way"
+ "§7You got §e$mobKillCoinsFormat §7coins in total this way",
)
text to lore
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
index 612f048de..1a75b4cbc 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
@@ -68,10 +68,9 @@ object ItemUtils {
}
// TODO change else janni is sad
- fun ItemStack.isCoopSoulBound(): Boolean =
- getLore().any {
- it == "§8§l* §8Co-op Soulbound §8§l*" || it == "§8§l* §8Soulbound §8§l*"
- }
+ fun ItemStack.isCoopSoulBound(): Boolean = getLore().any {
+ it == "§8§l* §8Co-op Soulbound §8§l*" || it == "§8§l* §8Soulbound §8§l*"
+ }
// TODO change else janni is sad
fun ItemStack.isSoulBound(): Boolean = getLore().any { it == "§8§l* §8Soulbound §8§l*" }
@@ -82,8 +81,7 @@ object ItemUtils {
fun getItemsInInventory(withCursorItem: Boolean = false): List<ItemStack> {
val list: LinkedList<ItemStack> = LinkedList()
- val player = Minecraft.getMinecraft().thePlayer
- ?: ErrorManager.skyHanniError("getItemsInInventoryWithSlots: player is null!")
+ val player = Minecraft.getMinecraft().thePlayer ?: ErrorManager.skyHanniError("getItemsInInventoryWithSlots: player is null!")
for (slot in player.openContainer.inventorySlots) {
if (slot.hasStack) {
@@ -138,8 +136,8 @@ object ItemUtils {
if (tagCompound == null) return null
val nbt = tagCompound
if (!nbt.hasKey("SkullOwner")) return null
- return nbt.getCompoundTag("SkullOwner").getCompoundTag("Properties")
- .getTagList("textures", Constants.NBT.TAG_COMPOUND).getCompoundTagAt(0).getString("Value")
+ return nbt.getCompoundTag("SkullOwner").getCompoundTag("Properties").getTagList("textures", Constants.NBT.TAG_COMPOUND)
+ .getCompoundTagAt(0).getString("Value")
}
fun ItemStack.getSkullOwner(): String? {
@@ -208,8 +206,7 @@ object ItemUtils {
for (line in this.getLore().reversed()) {
val (category, rarity) = UtilsPatterns.rarityLoreLinePattern.matchMatcher(line) {
- group("itemCategory").replace(" ", "_") to
- group("rarity").replace(" ", "_")
+ group("itemCategory").replace(" ", "_") to group("rarity").replace(" ", "_")
} ?: continue
val itemCategory = getItemCategory(category, name, cleanName)
@@ -290,8 +287,7 @@ object ItemUtils {
return data.itemRarity
}
- private fun itemRarityLastCheck(data: CachedItemData) =
- data.itemRarityLastCheck.passedSince() > 10.seconds
+ private fun itemRarityLastCheck(data: CachedItemData) = data.itemRarityLastCheck.passedSince() > 10.seconds
/**
* Use when comparing the name (e.g. regex), not for showing to the user
@@ -391,6 +387,9 @@ object ItemUtils {
val NEUInternalName.itemNameWithoutColor: String get() = itemName.removeColor()
+ val NEUInternalName.readableInternalName: String
+ get() = asString().replace("_", " ").lowercase()
+
private fun NEUInternalName.grabItemName(): String {
if (this == NEUInternalName.WISP_POTION) {
return "§fWisp's Ice-Flavored Water"
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt
index 18568869a..6d0eb33e5 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt
@@ -1,5 +1,7 @@
package at.hannibal2.skyhanni.utils
+import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
+
class NEUInternalName private constructor(private val internalName: String) {
companion object {
@@ -20,7 +22,25 @@ class NEUInternalName private constructor(private val internalName: String) {
}
fun fromItemNameOrNull(itemName: String): NEUInternalName? =
- ItemNameResolver.getInternalNameOrNull(itemName.removeSuffix(" Pet"))
+ ItemNameResolver.getInternalNameOrNull(itemName.removeSuffix(" Pet")) ?: getCoins(itemName)
+
+ fun fromItemNameOrInternalName(itemName: String): NEUInternalName =
+ fromItemNameOrNull(itemName) ?: itemName.asInternalName()
+
+ private fun getCoins(itemName: String): NEUInternalName? = if (isCoins(itemName)) SKYBLOCK_COIN else null
+
+ private fun isCoins(itemName: String): Boolean =
+ itemName.lowercase().let {
+ when (it) {
+ "coin", "coins",
+ "skyblock coin", "skyblock coins",
+ "skyblock_coin", "skyblock_coins",
+ -> true
+
+ else -> false
+ }
+ }
+
fun fromItemName(itemName: String): NEUInternalName = fromItemNameOrNull(itemName) ?: run {
val name = "itemName:$itemName"
@@ -52,4 +72,6 @@ class NEUInternalName private constructor(private val internalName: String) {
fun replace(oldValue: String, newValue: String) =
internalName.replace(oldValue.uppercase(), newValue.uppercase()).asInternalName()
+
+ fun isKnownItem(): Boolean = getItemStackOrNull() != null || this == SKYBLOCK_COIN
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/ItemTrackerData.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/ItemTrackerData.kt
index 4b871377b..bce63e2d1 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/ItemTrackerData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/ItemTrackerData.kt
@@ -24,12 +24,17 @@ abstract class ItemTrackerData : TrackerData() {
resetItems()
}
- fun addItem(internalName: NEUInternalName, stackSize: Int) {
+ fun addItem(internalName: NEUInternalName, amount: Int, command: Boolean) {
val item = items.getOrPut(internalName) { TrackedItem() }
- item.timesGained++
- item.totalAmount += stackSize
+ if (!command) {
+ item.timesGained++
+ }
+ item.totalAmount += amount
item.lastTimeUpdated = SimpleTimeMark.now()
+ if (command && item.totalAmount <= 0) {
+ items.remove(internalName)
+ }
}
@Expose
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt
index 684a7eb00..e7af81cea 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt
@@ -3,11 +3,13 @@ package at.hannibal2.skyhanni.utils.tracker
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage
import at.hannibal2.skyhanni.data.SlayerAPI
+import at.hannibal2.skyhanni.data.TrackerManager
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc
import at.hannibal2.skyhanni.utils.ItemPriceSource
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
+import at.hannibal2.skyhanni.utils.ItemUtils.readableInternalName
import at.hannibal2.skyhanni.utils.KeyboardManager
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector
@@ -26,23 +28,29 @@ class SkyHanniItemTracker<Data : ItemTrackerData>(
) : SkyHanniTracker<Data>(name, createNewSession, getStorage, drawDisplay) {
companion object {
-
val SKYBLOCK_COIN = NEUInternalName.SKYBLOCK_COIN
}
- fun addCoins(coins: Int) {
- addItem(SKYBLOCK_COIN, coins)
- }
-
- fun addItem(internalName: NEUInternalName, amount: Int) {
+ fun addItem(internalName: NEUInternalName, amount: Int, command: Boolean) {
modify {
- it.addItem(internalName, amount)
+ it.addItem(internalName, amount, command)
}
- getSharedTracker()?.let {
- val hidden = it.get(DisplayMode.TOTAL).items[internalName]!!.hidden
- it.get(DisplayMode.SESSION).items[internalName]!!.hidden = hidden
+ getSharedTracker()?.let { sharedData ->
+ sharedData.get(DisplayMode.TOTAL).items[internalName]?.let { data ->
+ sharedData.get(DisplayMode.SESSION).items[internalName]!!.hidden = data.hidden
+ }
}
+ if (command) {
+ TrackerManager.commandEditTrackerSuccess = true
+ val displayName = internalName.itemName
+ if (amount > 0) {
+ ChatUtils.chat("Manually added to $name: §r$displayName §7(${amount}x§7)")
+ } else {
+ ChatUtils.chat("Manually removed from $name: §r$displayName §7(${-amount}x§7)")
+ }
+ return
+ }
// TODO move the function to common
val (itemName, price) = SlayerAPI.getItemNameAndPrice(internalName, amount)
if (config.warnings.chat && price >= config.warnings.minimumChat) {
@@ -62,7 +70,7 @@ class SkyHanniItemTracker<Data : ItemTrackerData>(
onChange = {
config.priceSource = ItemPriceSource.entries[it.ordinal] // todo avoid ordinal
update()
- }
+ },
)
}
}
@@ -140,7 +148,7 @@ class SkyHanniItemTracker<Data : ItemTrackerData>(
}
update()
- }
+ },
) else Renderable.string(displayName)
lists.addAsSingletonList(renderable)
@@ -172,6 +180,12 @@ class SkyHanniItemTracker<Data : ItemTrackerData>(
}
add("§eClick to " + (if (hidden) "show" else "hide") + "!")
add("§eControl + Click to remove this item!")
+
+ add("")
+ add("§7Use §e/shedittracker ${internalName.readableInternalName} <amount>")
+ add("§7to edit the number.")
+ add("§7Use negative numbers to remove items.")
+
if (SkyHanniMod.feature.dev.debug.enabled) {
add("")
add("§7${internalName}")