blob: 3c5403309bc794ed5f0443719c053a4f4b0fdff5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
package at.hannibal2.skyhanni.features.bazaar
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
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.OSUtils
import at.hannibal2.skyhanni.utils.StringUtils.findMatcher
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class BazaarCancelledBuyOrderClipboard {
private val patternGroup = RepoPattern.group("bazaar.cancelledorder")
private val lastAmountPattern by patternGroup.pattern(
"lastamount",
"§a(?<amount>.*)§7x"
)
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
@SubscribeEvent
fun onTooltip(event: LorenzToolTipEvent) {
if (!isEnabled()) return
val stack = event.itemStack
val name = stack.name ?: return
if (!name.contains("Cancel Order")) return
for (line in stack.getLore()) {
lastAmountPattern.findMatcher(line) {
latestAmount = group("amount")
}
}
}
@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
}
}
fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.bazaar.cancelledBuyOrderClipboard
}
|