diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-24 04:20:56 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-24 04:20:56 +0100 |
commit | b32344991743f53c94a48f8a0054d0126b15bbfd (patch) | |
tree | ac4b0ba7d95bb7d0dcc650c77d6e9272459bb8c1 /src | |
parent | 25efa3d4ee8c652a4d75b5357b7705b0267c08ae (diff) | |
download | skyhanni-b32344991743f53c94a48f8a0054d0126b15bbfd.tar.gz skyhanni-b32344991743f53c94a48f8a0054d0126b15bbfd.tar.bz2 skyhanni-b32344991743f53c94a48f8a0054d0126b15bbfd.zip |
Created and used ItemAddEvent, /shtrackcollection now supports sack messages.
Diffstat (limited to 'src')
7 files changed, 94 insertions, 79 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 34f7bfd3e..864761788 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -21,6 +21,7 @@ import at.hannibal2.skyhanni.data.GardenCropUpgrades import at.hannibal2.skyhanni.data.GuiEditManager import at.hannibal2.skyhanni.data.GuildAPI import at.hannibal2.skyhanni.data.HypixelData +import at.hannibal2.skyhanni.data.ItemAddManager import at.hannibal2.skyhanni.data.ItemClickData import at.hannibal2.skyhanni.data.ItemRenderBackground import at.hannibal2.skyhanni.data.ItemTipHelper @@ -387,6 +388,7 @@ class SkyHanniMod { loadModule(EntityOutlineRenderer) loadModule(KeyboardManager) loadModule(AdvancedPlayerList) + loadModule(ItemAddManager()) // APIs loadModule(BazaarApi()) diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt index 8698d9f28..ba9dc5327 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt @@ -2,8 +2,8 @@ package at.hannibal2.skyhanni.api import at.hannibal2.skyhanni.events.CollectionUpdateEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.events.ItemAddEvent import at.hannibal2.skyhanni.events.ProfileJoinEvent -import at.hannibal2.skyhanni.events.entity.ItemAddInInventoryEvent import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils @@ -69,7 +69,7 @@ class CollectionAPI { } @SubscribeEvent - fun onItemAdd(event: ItemAddInInventoryEvent) { + fun onItemAdd(event: ItemAddEvent) { val internalName = event.internalName val (_, amount) = NEUItems.getMultiplier(internalName) if (amount > 1) return diff --git a/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt new file mode 100644 index 000000000..a05d8398f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt @@ -0,0 +1,67 @@ +package at.hannibal2.skyhanni.data + +import at.hannibal2.skyhanni.events.ItemAddEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.SackChangeEvent +import at.hannibal2.skyhanni.events.entity.ItemAddInInventoryEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.StringUtils.matches +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.milliseconds + +class ItemAddManager { + enum class Source { + ITEM_ADD, + SACKS, + ; + } + + private val ARCHFIEND_DICE = "ARCHFIEND_DICE".asInternalName() + private val HIGH_CLASS_ARCHFIEND_DICE = "HIGH_CLASS_ARCHFIEND_DICE".asInternalName() + + private val diceRollChatPattern = + "§eYour §r§(5|6High Class )Archfiend Dice §r§erolled a §r§.(?<number>.)§r§e! Bonus: §r§.(?<hearts>.*)❤".toPattern() + + @SubscribeEvent + fun onSackChange(event: SackChangeEvent) { + if (!LorenzUtils.inSkyBlock) return + + for (sackChange in event.sackChanges) { + val change = sackChange.delta + if (change > 0) { + val internalName = sackChange.internalName + Source.SACKS.addItem(internalName, change) + } + } + } + + @SubscribeEvent + fun onItemAdd(event: ItemAddInInventoryEvent) { + if (!LorenzUtils.inSkyBlock) return + + val internalName = event.internalName + if (internalName == ARCHFIEND_DICE || internalName == HIGH_CLASS_ARCHFIEND_DICE) { + if (lastDiceRoll.passedSince() < 500.milliseconds) { + return + } + } + + Source.ITEM_ADD.addItem(internalName, event.amount) + } + + private fun Source.addItem(internalName: NEUInternalName, amount: Int) { + ItemAddEvent(internalName, amount, this).postAndCatch() + } + + private var lastDiceRoll = SimpleTimeMark.farPast() + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (diceRollChatPattern.matches(event.message)) { + lastDiceRoll = SimpleTimeMark.now() + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt index f3c04a0c6..9be617546 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt @@ -147,6 +147,5 @@ class OwnInventoryData { if (internalName.startsWith("MAP-")) return ItemAddInInventoryEvent(internalName, add).postAndCatch() - LorenzUtils.debug("added item internalName: $internalName") } } diff --git a/src/main/java/at/hannibal2/skyhanni/events/ItemAddEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/ItemAddEvent.kt new file mode 100644 index 000000000..ad0c6355d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/ItemAddEvent.kt @@ -0,0 +1,7 @@ +package at.hannibal2.skyhanni.events + +import at.hannibal2.skyhanni.data.ItemAddManager +import at.hannibal2.skyhanni.utils.NEUInternalName + +class ItemAddEvent(val internalName: NEUInternalName, val amount: Int, val source: ItemAddManager.Source) : + LorenzEvent() 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 4ee211310..69e6848a7 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 @@ -3,9 +3,8 @@ package at.hannibal2.skyhanni.features.fishing.tracker import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.FishingBobberCastEvent import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.ItemAddEvent import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.SackChangeEvent -import at.hannibal2.skyhanni.events.entity.ItemAddInInventoryEvent import at.hannibal2.skyhanni.features.bazaar.BazaarApi.Companion.getBazaarData import at.hannibal2.skyhanni.features.fishing.FishingAPI import at.hannibal2.skyhanni.test.PriceSource @@ -238,22 +237,8 @@ object FishingProfitTracker { } @SubscribeEvent - fun onSackChange(event: SackChangeEvent) { + fun onItemAdd(event: ItemAddEvent) { if (!isEnabled()) return - - for (sackChange in event.sackChanges) { - val change = sackChange.delta - if (change > 0) { - val internalName = sackChange.internalName - maybeAddItem(internalName, change) - } - } - } - - @SubscribeEvent - fun onItemAdd(event: ItemAddInInventoryEvent) { - if (!isEnabled()) return - DelayedRun.runDelayed(500.milliseconds) { maybeAddItem(event.internalName, event.amount) } 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 6ea38924b..2f101524a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt @@ -4,14 +4,12 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.Storage import at.hannibal2.skyhanni.data.SlayerAPI import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.ItemAddEvent import at.hannibal2.skyhanni.events.PurseChangeCause import at.hannibal2.skyhanni.events.PurseChangeEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent -import at.hannibal2.skyhanni.events.SackChangeEvent import at.hannibal2.skyhanni.events.SlayerChangeEvent import at.hannibal2.skyhanni.events.SlayerQuestCompleteEvent -import at.hannibal2.skyhanni.events.entity.ItemAddInInventoryEvent import at.hannibal2.skyhanni.features.bazaar.BazaarApi.Companion.getBazaarData import at.hannibal2.skyhanni.test.PriceSource import at.hannibal2.skyhanni.utils.KeyboardManager @@ -21,14 +19,10 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc import at.hannibal2.skyhanni.utils.NEUInternalName -import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.SimpleTimeMark -import at.hannibal2.skyhanni.utils.StringUtils -import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.jsonobjects.SlayerProfitTrackerItemsJson import at.hannibal2.skyhanni.utils.renderables.Renderable @@ -36,18 +30,11 @@ 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.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds object SlayerProfitTracker { private val config get() = SkyHanniMod.feature.slayer.itemProfitTracker - private val diceRollChatPattern = - "§eYour §r§(5|6High Class )Archfiend Dice §r§erolled a §r§.(?<number>.)§r§e! Bonus: §r§.(?<hearts>.*)❤".toPattern() - - private val ARCHFIEND_DICE = "ARCHFIEND_DICE".asInternalName() - private val HIGH_CLASS_ARCHFIEND_DICE = "HIGH_CLASS_ARCHFIEND_DICE".asInternalName() - private var itemLogCategory = "" private var baseSlayerType = "" private val logger = LorenzLogger("slayer/profit_tracker") @@ -88,19 +75,19 @@ object SlayerProfitTracker { var hidden = false override fun toString() = "SlayerItem{" + - "internalName='" + internalName + '\'' + - ", timesDropped=" + timesDropped + - ", totalAmount=" + totalAmount + - ", hidden=" + hidden + - '}' + "internalName='" + internalName + '\'' + + ", timesDropped=" + timesDropped + + ", totalAmount=" + totalAmount + + ", hidden=" + hidden + + '}' } override fun toString() = "SlayerProfitTracker.Data{" + - "items=" + items + - ", mobKillCoins=" + mobKillCoins + - ", slayerSpawnCost=" + slayerSpawnCost + - ", slayerCompletedCount=" + slayerCompletedCount + - '}' + "items=" + items + + ", mobKillCoins=" + mobKillCoins + + ", slayerSpawnCost=" + slayerSpawnCost + + ", slayerCompletedCount=" + slayerCompletedCount + + '}' } private fun addSlayerCosts(price: Int) { @@ -174,46 +161,14 @@ object SlayerProfitTracker { } @SubscribeEvent - fun onSackChange(event: SackChangeEvent) { - if (!isEnabled()) return - if (!SlayerAPI.isInCorrectArea) return - if (!SlayerAPI.hasActiveSlayerQuest()) return - - for (sackChange in event.sackChanges) { - val change = sackChange.delta - if (change > 0) { - val internalName = sackChange.internalName - addItem(internalName, change) - } - } - } - - @SubscribeEvent - fun onItemAdd(event: ItemAddInInventoryEvent) { + fun onItemAdd(event: ItemAddEvent) { if (!isEnabled()) return if (!SlayerAPI.isInCorrectArea) return if (!SlayerAPI.hasActiveSlayerQuest()) return val internalName = event.internalName - if (internalName == ARCHFIEND_DICE || internalName == HIGH_CLASS_ARCHFIEND_DICE) { - if (lastDiceRoll.passedSince() < 500.milliseconds) { - return - } - } - - addItem(internalName, event.amount) - } - - private var lastDiceRoll = SimpleTimeMark.farPast() - - @SubscribeEvent - fun onChat(event: LorenzChatEvent) { - if (diceRollChatPattern.matches(event.message)) { - lastDiceRoll = SimpleTimeMark.now() - } - } + val amount = event.amount - private fun addItem(internalName: NEUInternalName, amount: Int) { if (!isAllowedItem(internalName)) { LorenzUtils.debug("Ignored non-slayer item pickup: '$internalName' '$itemLogCategory'") return @@ -363,7 +318,7 @@ object SlayerProfitTracker { if (itemLogCategory == "") { LorenzUtils.userError( "No current slayer data found! " + - "§eGo to a slayer area and start the specific slayer type you want to reset the data of.", + "§eGo to a slayer area and start the specific slayer type you want to reset the data of.", ) return } |