blob: 3efa9a8e593c366da0b60e395f849d574ab672bf (
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
61
62
63
64
65
66
67
68
69
70
71
72
73
|
package at.hannibal2.skyhanni.features.inventory
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.features.misc.items.EstimatedItemValueCalculator
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName
import at.hannibal2.skyhanni.utils.InventoryUtils.getUpperItems
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.inventory.ContainerChest
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@SkyHanniModule
object AuctionsHighlighter {
private val config get() = SkyHanniMod.feature.inventory.auctions
private val patternGroup = RepoPattern.group("auctions.highlight")
val buyItNowPattern by patternGroup.pattern(
"buyitnow",
"§7Buy it now: §6(?<coins>.*) coins"
)
val auctionPattern by patternGroup.pattern(
"auction",
"§7(?:Starting bid|Top bid): §6(?<coins>.*) coins"
)
@SubscribeEvent
fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!config.highlightAuctions) return
if (event.gui !is GuiChest) return
val guiChest = event.gui
val chest = guiChest.inventorySlots as ContainerChest
if (chest.getInventoryName() != "Manage Auctions") return
for ((slot, stack) in chest.getUpperItems()) {
val lore = stack.getLore()
if (lore.any { it == "§7Status: §aSold!" }) {
slot highlight LorenzColor.GREEN
continue
}
if (lore.any { it == "§7Status: §cExpired!" }) {
slot highlight LorenzColor.RED
continue
}
if (config.highlightAuctionsUnderbid) {
lore.matchFirst(buyItNowPattern) {
val coins = group("coins").formatLong()
val totalPrice = EstimatedItemValueCalculator.getTotalPrice(stack)
if (coins > totalPrice) {
slot highlight LorenzColor.GOLD
}
}
}
}
}
@SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(25, "inventory.highlightAuctions", "inventory.auctions.highlightAuctions")
event.move(25, "inventory.highlightAuctionsUnderbid", "inventory.auctions.highlightAuctionsUnderbid")
}
}
|