diff options
author | HiZe <super@hize.be> | 2024-04-04 21:29:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-04 21:29:44 +0200 |
commit | 52691f7a79adc3f661f82a0833fe1ca132c6412d (patch) | |
tree | 9a31957d0f070e0b03f5f790d59595b589e2f9cf /src/main/java/at/hannibal2/skyhanni | |
parent | aa9bbeaf75c571b88f02874f480da04f8424d78d (diff) | |
download | skyhanni-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')
3 files changed, 133 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 31ebf5420..22b0da2f6 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -204,6 +204,7 @@ import at.hannibal2.skyhanni.features.garden.fortuneguide.CaptureFarmingGear import at.hannibal2.skyhanni.features.garden.inventory.AnitaExtraFarmingFortune import at.hannibal2.skyhanni.features.garden.inventory.GardenCropMilestoneInventory import at.hannibal2.skyhanni.features.garden.inventory.GardenInventoryNumbers +import at.hannibal2.skyhanni.features.garden.inventory.LogBookStats import at.hannibal2.skyhanni.features.garden.inventory.SkyMartCopperPrice import at.hannibal2.skyhanni.features.garden.inventory.plots.GardenNextPlotPrice import at.hannibal2.skyhanni.features.garden.inventory.plots.GardenPlotIcon @@ -709,6 +710,8 @@ class SkyHanniMod { loadModule(ServerRestartTitle()) loadModule(CityProjectFeatures()) loadModule(GardenPlotIcon) + loadModule(GardenPlotBorders) + loadModule(LogBookStats()) loadModule(PocketSackInASackDisplay()) loadModule(ShowFishingItemName()) loadModule(WarpTabComplete) @@ -766,7 +769,6 @@ class SkyHanniMod { loadModule(AccountUpgradeReminder()) loadModule(PetExpTooltip()) loadModule(Translator()) - loadModule(GardenPlotBorders) loadModule(CosmeticFollowingLine()) loadModule(SuperpairsClicksAlert()) loadModule(PowderTracker) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java index 9d941c095..b19a706f0 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java @@ -233,4 +233,13 @@ public class GardenConfig { @ConfigEditorBoolean @FeatureToggle public boolean copyMilestoneData = true; + + @Expose + @ConfigOption(name = "Log Book Stats", desc = "Show total visited/accepted/denied visitors stats.") + @ConfigEditorBoolean + @FeatureToggle + public boolean showLogBookStats = true; + + @Expose + public Position logBookStatsPos = new Position(427, 92, false, true); } 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, + ) +} |