diff options
-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 |