aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorHiZe <super@hize.be>2024-04-04 21:29:44 +0200
committerGitHub <noreply@github.com>2024-04-04 21:29:44 +0200
commit52691f7a79adc3f661f82a0833fe1ca132c6412d (patch)
tree9a31957d0f070e0b03f5f790d59595b589e2f9cf /src/main/java/at/hannibal2/skyhanni/features
parentaa9bbeaf75c571b88f02874f480da04f8424d78d (diff)
downloadskyhanni-52691f7a79adc3f661f82a0833fe1ca132c6412d.tar.gz
skyhanni-52691f7a79adc3f661f82a0833fe1ca132c6412d.tar.bz2
skyhanni-52691f7a79adc3f661f82a0833fe1ca132c6412d.zip
Add: Visitor's Logbook stats (#1287)
Co-authored-by: superhize <superhize@gmail.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/inventory/LogBookStats.kt121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/LogBookStats.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/LogBookStats.kt
new file mode 100644
index 000000000..cb409afdb
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/LogBookStats.kt
@@ -0,0 +1,121 @@
+package at.hannibal2.skyhanni.features.garden.inventory
+
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.InventoryCloseEvent
+import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
+import at.hannibal2.skyhanni.events.ProfileJoinEvent
+import at.hannibal2.skyhanni.features.garden.GardenAPI
+import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.NumberUtil.formatLong
+import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
+import at.hannibal2.skyhanni.utils.StringUtils.matchFirst
+import at.hannibal2.skyhanni.utils.renderables.Renderable
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+import net.minecraft.init.Items
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class LogBookStats {
+
+ private val groupPattern = RepoPattern.group("garden.inventory.logbook")
+ private val visitedPattern by groupPattern.pattern(
+ "visited",
+ "§7Times Visited: §a(?<timesVisited>[0-9,.]+)"
+ )
+ private val acceptedPattern by groupPattern.pattern(
+ "accepted",
+ "§7Offers Accepted: §a(?<timesAccepted>[0-9,.]+)"
+ )
+ private val pagePattern by groupPattern.pattern(
+ "page.current",
+ "§ePage (?<page>\\d)"
+ )
+
+ private val config get() = GardenAPI.config
+ private var display = emptyList<Renderable>()
+ private val loggedVisitors = mutableMapOf<Int, List<VisitorInfo>>()
+ private var inInventory = false
+ private var currentPage = 0
+
+ @SubscribeEvent
+ fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
+ val inventoryName = event.inventoryName
+ if (inventoryName != "Visitor's Logbook") return
+
+ inInventory = true
+ checkPages(event)
+ val list = mutableListOf<VisitorInfo>()
+
+ for ((index, item) in event.inventoryItems) {
+ val visitorName = item.displayName ?: continue
+ var timesVisited = 0L
+ var timesAccepted = 0L
+ val lore = item.getLore()
+ lore.matchFirst(visitedPattern) {
+ timesVisited += group("timesVisited").formatLong()
+ }
+ lore.matchFirst(acceptedPattern) {
+ timesAccepted += group("timesAccepted").formatLong()
+ }
+
+ val visitor = VisitorInfo(index, visitorName, timesVisited, timesAccepted)
+ list.add(visitor)
+ }
+ loggedVisitors[currentPage] = list
+ display = buildList {
+ val visited = loggedVisitors.values.sumOf { it.sumOf { visitor -> visitor.timesVisited } }
+ val accepted = loggedVisitors.values.sumOf { it.sumOf { visitor -> visitor.timesAccepted } }
+ val visitingNow = VisitorAPI.getVisitors().size
+ val denied = visited - accepted - visitingNow
+ add(Renderable.string("§6Times Visited: §b${visited.addSeparators()}"))
+ add(Renderable.string("§6Times Accepted: §a${accepted.addSeparators()}"))
+ add(Renderable.string("§6Times Denied: §c${denied.addSeparators()}"))
+ }
+ }
+
+ @SubscribeEvent
+ fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) {
+ if (inInventory && config.showLogBookStats) {
+ config.logBookStatsPos.renderRenderables(
+ display,
+ extraSpace = 5,
+ posLabel = "Visitor's LogBook Stats"
+ )
+ }
+ }
+
+ @SubscribeEvent
+ fun onProfileChange(event: ProfileJoinEvent) {
+ display = emptyList()
+ loggedVisitors.clear()
+ currentPage = 0
+ inInventory = false
+ }
+
+ @SubscribeEvent
+ fun onInventoryClosed(event: InventoryCloseEvent) {
+ inInventory = false
+ }
+
+ private fun checkPages(event: InventoryFullyOpenedEvent) {
+ val next = event.inventoryItems[53]
+ if (next?.item != Items.arrow) {
+ currentPage++
+ return
+ }
+ for (item in event.inventoryItems.values) {
+ if (item.displayName != "§aNext Page") continue
+ item.getLore().matchFirst(pagePattern) {
+ currentPage = group("page").toInt() - 1
+ }
+ }
+ }
+
+ data class VisitorInfo(
+ var index: Int = -1,
+ var displayName: String = "",
+ var timesVisited: Long = 0,
+ var timesAccepted: Long = 0,
+ )
+}