diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-04-15 20:19:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-15 20:19:08 +0200 |
commit | 95632704c8a90569578a92ed01e98644e4a9b97e (patch) | |
tree | 7f2abea59060f8491c488724525d53216250cc98 /src/main/java/at/hannibal2 | |
parent | e20838c25789e82ad89e35d753efd43209b15447 (diff) | |
download | skyhanni-95632704c8a90569578a92ed01e98644e4a9b97e.tar.gz skyhanni-95632704c8a90569578a92ed01e98644e4a9b97e.tar.bz2 skyhanni-95632704c8a90569578a92ed01e98644e4a9b97e.zip |
Fix: Bazaar Copy null (#1452)
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/bazaar/BazaarCancelledBuyOrderClipboard.kt | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt index ba0d4278b..3e55f93ac 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/bazaar/BazaarCancelledBuyOrderClipboard.kt @@ -7,6 +7,8 @@ import at.hannibal2.skyhanni.utils.ChatUtils 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.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher @@ -16,16 +18,20 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class BazaarCancelledBuyOrderClipboard { private val patternGroup = RepoPattern.group("bazaar.cancelledorder") + + /** + * REGEX-TEST: §6§7from §a59§7x §7missing items. + */ private val lastAmountPattern by patternGroup.pattern( "lastamount", - "§a(?<amount>.*)§7x" + "§6§7from §a(?<amount>.*)§7x §7missing items\\." ) private val cancelledMessagePattern by patternGroup.pattern( "cancelledmessage", "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?<coins>.*) coins §r§7from cancelling Buy Order!" ) - private var latestAmount: String? = null + private var latestAmount: Int? = null @SubscribeEvent fun onTooltip(event: LorenzToolTipEvent) { @@ -35,22 +41,22 @@ class BazaarCancelledBuyOrderClipboard { if (!stack.name.contains("Cancel Order")) return stack.getLore().matchFirst(lastAmountPattern) { - latestAmount = group("amount") + latestAmount = group("amount").formatInt() } } @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!isEnabled()) return - - cancelledMessagePattern.matchMatcher(event.message) { - event.blockedReason = "bazaar cancelled buy order clipboard" - val coins = group("coins") - ChatUtils.chat("Bazaar buy order cancelled. $latestAmount saved to clipboard. ($coins coins)") - - latestAmount?.let { OSUtils.copyToClipboard(it.replace(",", "")) } - latestAmount = null - } + val coins = cancelledMessagePattern.matchMatcher(event.message) { + group("coins") + } ?: return + + val latestAmount = latestAmount ?: error("latest amount is null") + event.blockedReason = "bazaar cancelled buy order clipboard" + ChatUtils.chat("Bazaar buy order cancelled. ${latestAmount.addSeparators()} saved to clipboard. ($coins coins)") + OSUtils.copyToClipboard(latestAmount.toString()) + this.latestAmount = null } fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.inventory.bazaar.cancelledBuyOrderClipboard |