diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-08-13 18:19:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-13 18:19:40 +0200 |
commit | 67dd38b9d76eab01f0359b6c9d627618111be07f (patch) | |
tree | d82edb2646e5f30288128927db8cded83bddeffe /src/main/java/at/hannibal2 | |
parent | 4b2935b538b4a7b7816ac581fa184340557e66e7 (diff) | |
download | skyhanni-67dd38b9d76eab01f0359b6c9d627618111be07f.tar.gz skyhanni-67dd38b9d76eab01f0359b6c9d627618111be07f.tar.bz2 skyhanni-67dd38b9d76eab01f0359b6c9d627618111be07f.zip |
Improvement + Fix: Custom CF Reminder (#2334)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryCustomReminder.kt | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryCustomReminder.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryCustomReminder.kt index 1f7de017c..109db545c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryCustomReminder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryCustomReminder.kt @@ -11,14 +11,20 @@ import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NumberUtil.formatLong +import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat +import at.hannibal2.skyhanni.utils.RegexUtils.matchAll +import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.TimeUtils.format import at.hannibal2.skyhanni.utils.TimeUtils.minutes import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @SkyHanniModule @@ -43,11 +49,36 @@ object ChocolateFactoryCustomReminder { private var lastUpgradeWarning = SimpleTimeMark.farPast() + private val patternGroup = RepoPattern.group("inventory.chocolate.factory") + + /** + * REGEX-TEST: §cRequires 400B all-time Chocolate! + */ + private val milestoneCostLorePattern by patternGroup.pattern( + "milestone.cost", + "§cRequires (?<amount>.*) all-time Chocolate!", + ) + + /** + * REGEX-TEST: §cYou don't have enough Chocolate! + */ + private val chatMessagePattern by patternGroup.list( + "chat.hide", + "§cYou don't have enough Chocolate!", + "§cYou don't have the required items!", + "§cYou must collect (.*) all-time Chocolate!", + ) + @SubscribeEvent fun onChat(event: SystemMessageEvent) { if (!isEnabled()) return + if (!ChocolateFactoryAPI.inChocolateFactory) return if (configReminder.hideChat) { - if (event.message == "§cYou don't have enough Chocolate!") { + + if (chatMessagePattern.matches(event.message)) { + //§cYou don't have the required items! + //§cYou must collect 300B all-time Chocolate! +// if (event.message == "§cYou don't have enough Chocolate!") { event.blockedReason = "custom_reminder" } } @@ -64,17 +95,37 @@ object ChocolateFactoryCustomReminder { if (!isEnabled()) return val item = event.item ?: return if (event.clickedButton != 0) return - // TODO add support for prestige and for Chocolate Milestone - val cost = ChocolateFactoryAPI.getChocolateBuyCost(item.getLore()) ?: return + val (cost, name) = getCostAndName(item) ?: return val duration = ChocolateAmount.CURRENT.timeUntilGoal(cost) - val nextLevelName = ChocolateFactoryAPI.getNextLevelName(item) ?: return // the user has enough chocolate, and just bought something if (duration.isNegative()) { reset() return } - setReminder(cost, nextLevelName) + setReminder(cost, name) + } + + // TODO add support for prestige + private fun getCostAndName(item: ItemStack): Pair<Long, String>? { + val list = item.getLore() + val cost = ChocolateFactoryAPI.getChocolateBuyCost(list) + if (cost == null) { + milestoneCostLorePattern.matchAll(list) { + // math needed to get from "time until current chocolate" to "time until all time chocolate" + val amount = group("amount").formatLong() + val allTime = ChocolateAmount.ALL_TIME.chocolate() + val missingAllTime = amount - allTime + val current = ChocolateAmount.CURRENT.chocolate() + val missing = missingAllTime + current + + return missing to "§6${amount.shortFormat()} Chocolate Milestone" + } + return null + } + + val nextLevelName = ChocolateFactoryAPI.getNextLevelName(item) ?: item.name + return cost to nextLevelName } @SubscribeEvent |