From e50d8d3b7d3f2682744b5b9ee98d248ea5f0ce5b Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 29 Dec 2022 23:08:53 +0100 Subject: Saves missing items from cancelled buy orders to clipboard for faster re-entry. --- .../bazaar/BazaarCancelledBuyOrderClipboard.kt | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features/bazaar') diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt new file mode 100644 index 000000000..3943e7d44 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt @@ -0,0 +1,58 @@ +package at.hannibal2.skyhanni.features.bazaar + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzChatEvent +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.OSUtils +import net.minecraftforge.event.entity.player.ItemTooltipEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.regex.Pattern + +class BazaarCancelledBuyOrderClipboard { + + private val patternLastAmount = Pattern.compile("§a(.*)§7x") + private val patternCancelledMessage = + Pattern.compile("§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(.*) coins §r§7from cancelling Buy Order!") + + private var latestAmount: String? = null + + @SubscribeEvent + fun onTooltip(event: ItemTooltipEvent) { + if (!isEnabled()) return + + val stack = event.itemStack ?: return + val name = stack.name ?: return + if (!name.contains("Cancel Order")) return + + for (line in stack.getLore()) { + val matcher = patternLastAmount.matcher(line) + if (matcher.find()) { + latestAmount = matcher.group(1) + } + } + } + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!isEnabled()) return + + val message = event.message + + val matcher = patternCancelledMessage.matcher(message) + if (matcher.matches()) { + event.blockedReason = "bazaar cancelled buy order clipbaord" + val coins = matcher.group(1) + + LorenzUtils.chat("§e[SkyHanni] Bazaar buy order cancelled. $latestAmount saved to clipboard. ($coins coins)") + + latestAmount?.let { OSUtils.copyToClipboard(it.replace(",", "")) } + latestAmount = null + } + } + + fun isEnabled(): Boolean { + return LorenzUtils.inSkyblock && SkyHanniMod.feature.bazaar.cancelledBuyOrderClipboard + } +} \ No newline at end of file -- cgit