diff options
author | Eric W <42985687+ericpretzel@users.noreply.github.com> | 2023-08-29 08:07:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-29 17:07:46 +0200 |
commit | e34960c5ef84807d7f610641e4ff6b9a58f4d714 (patch) | |
tree | f18e9e4e7fcd4374a5cdd4d814f77edaaeba4a5d /src/main/java/at/hannibal2 | |
parent | a2167bc4e6a428b45f1ca7859b7690853012ef0e (diff) | |
download | skyhanni-e34960c5ef84807d7f610641e4ff6b9a58f4d714.tar.gz skyhanni-e34960c5ef84807d7f610641e4ff6b9a58f4d714.tar.bz2 skyhanni-e34960c5ef84807d7f610641e4ff6b9a58f4d714.zip |
Sack change event (#403)
Create SackChangeEvent #403
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 1 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt | 49 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/events/SackChangeEvent.kt | 7 |
3 files changed, 57 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index ee3244d4d..2c58985e8 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -179,6 +179,7 @@ class SkyHanniMod { loadModule(SlayerAPI) loadModule(PurseAPI()) loadModule(RiftAPI) + loadModule(SackAPI()) // features loadModule(BazaarOrderHelper()) diff --git a/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt new file mode 100644 index 000000000..4efb30727 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt @@ -0,0 +1,49 @@ +package at.hannibal2.skyhanni.data + +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.SackChangeEvent +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + + +class SackAPI { + + data class SackChange(val delta: Int, val internalName: NEUInternalName, val sacks: List<String>) + + private val sackChangeRegex = Regex("""([+-][\d,]+) (.+) \((.+)\)""") + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!event.message.removeColor().startsWith("[Sacks]")) return + + val sackChanges = ArrayList<SackChange>() + + val sackAddText = event.chatComponent.siblings.firstNotNullOfOrNull { sibling -> + sibling.chatStyle?.chatHoverEvent?.value?.formattedText?.removeColor()?.takeIf { + it.startsWith("Added") + } + } ?: "" + val sackRemoveText = event.chatComponent.siblings.firstNotNullOfOrNull { sibling -> + sibling.chatStyle?.chatHoverEvent?.value?.formattedText?.removeColor()?.takeIf { + it.startsWith("Removed") + } + } ?: "" + + val sackChangeText = sackAddText + sackRemoveText + if (sackChangeText.isEmpty()) return + + val otherItemsAdded = sackAddText.contains("other items") + val otherItemsRemoved = sackRemoveText.contains("other items") + + for (match in sackChangeRegex.findAll(sackChangeText)) { + val delta = match.groups[1]!!.value.replace(",", "").toInt() + val item = match.groups[2]!!.value + val sacks = match.groups[3]!!.value.split(", ") + + val internalName = NEUInternalName.fromItemName(item) + sackChanges.add(SackChange(delta, internalName, sacks)) + } + SackChangeEvent(sackChanges, otherItemsAdded, otherItemsRemoved).postAndCatch() + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/events/SackChangeEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/SackChangeEvent.kt new file mode 100644 index 000000000..797605e80 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/SackChangeEvent.kt @@ -0,0 +1,7 @@ +package at.hannibal2.skyhanni.events + +import at.hannibal2.skyhanni.data.SackAPI + +class SackChangeEvent(val sackChanges: List<SackAPI.SackChange>, + val otherItemsAdded: Boolean, + val otherItemsRemoved: Boolean) : LorenzEvent() |