blob: 4a4ef95ec84d938b05c40faa05119c8612f40080 (
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
74
75
76
77
78
79
|
package at.hannibal2.skyhanni.features.event.winter
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.data.WinterAPI
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.IslandChangeEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@SkyHanniModule
object UniqueGiftCounter {
private val config get() = SkyHanniMod.feature.event.winter.uniqueGiftCounter
private val storage get() = ProfileStorageData.playerSpecific?.winter
private val giftedAmountPattern by RepoPattern.pattern(
"event.winter.uniqugifts.counter.amount",
"§7Unique Players Gifted: §a(?<amount>.*)"
)
private var display = ""
@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (event.inventoryName != "Generow") return
val item = event.inventoryItems[40] ?: return
val storage = storage ?: return
item.getLore().matchFirst(giftedAmountPattern) {
val amount = group("amount").formatInt()
storage.amountGifted = amount
update()
}
}
@SubscribeEvent
fun onIslandChange(event: IslandChangeEvent) {
update()
}
fun addUniqueGift() {
val storage = storage ?: return
storage.amountGifted++
update()
}
private fun update() {
val storage = storage ?: return
val amountGifted = storage.amountGifted
val max = 600
val hasMax = amountGifted >= max
val color = if (hasMax) "§a" else "§e"
display = "§7Unique Players Gifted: $color$amountGifted/$max"
}
@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
if (!isEnabled()) return
config.position.renderString(
display,
posLabel = "Unique Gift Counter"
)
}
private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled && WinterAPI.isDecember() &&
InventoryUtils.itemInHandId.endsWith("_GIFT")
}
|