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/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt | |
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/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt | 67 |
1 files changed, 67 insertions, 0 deletions
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() + } + } +} |