diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-12-29 23:08:53 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-12-29 23:08:53 +0100 |
commit | e50d8d3b7d3f2682744b5b9ee98d248ea5f0ce5b (patch) | |
tree | f9c0cca9a01e8e50615173721f6e73a46e6cd3f3 /src/main/java/at/hannibal2/skyhanni/features/bazaar | |
parent | f175e24a431d67bae406ffcd45e88c82f93ec8fd (diff) | |
download | skyhanni-e50d8d3b7d3f2682744b5b9ee98d248ea5f0ce5b.tar.gz skyhanni-e50d8d3b7d3f2682744b5b9ee98d248ea5f0ce5b.tar.bz2 skyhanni-e50d8d3b7d3f2682744b5b9ee98d248ea5f0ce5b.zip |
Saves missing items from cancelled buy orders to clipboard for faster re-entry.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/bazaar')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt | 58 |
1 files changed, 58 insertions, 0 deletions
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 |