From 75a80664c2034fc4a68a115a1b686676a53949d5 Mon Sep 17 00:00:00 2001 From: appable Date: Tue, 15 Aug 2023 03:17:04 -0700 Subject: Merge pull request #380 * account upgrade reminder --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 3 + .../java/at/hannibal2/skyhanni/config/Storage.java | 6 + .../hannibal2/skyhanni/config/commands/Commands.kt | 5 +- .../skyhanni/config/features/MiscConfig.java | 5 + .../features/fame/AccountUpgradeReminder.kt | 99 +++++++++++ .../skyhanni/features/fame/CityProjectFeatures.kt | 194 ++++++++++++++++++++ .../skyhanni/features/fame/ReminderUtils.kt | 9 + .../skyhanni/features/misc/CityProjectFeatures.kt | 196 --------------------- 8 files changed, 320 insertions(+), 197 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/fame/AccountUpgradeReminder.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/fame/ReminderUtils.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/CityProjectFeatures.kt (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index df33eaa2a..03032cc7c 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -23,6 +23,8 @@ import at.hannibal2.skyhanni.features.commands.WikiCommand import at.hannibal2.skyhanni.features.damageindicator.DamageIndicatorManager import at.hannibal2.skyhanni.features.dungeon.* import at.hannibal2.skyhanni.features.event.diana.* +import at.hannibal2.skyhanni.features.fame.AccountUpgradeReminder +import at.hannibal2.skyhanni.features.fame.CityProjectFeatures import at.hannibal2.skyhanni.features.fishing.* import at.hannibal2.skyhanni.features.fishing.trophy.OdgerWaypoint import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishFillet @@ -378,6 +380,7 @@ class SkyHanniMod { loadModule(EnderNodeTracker()) loadModule(CompactBestiaryChatMessage()) loadModule(WatchdogHider()) + loadModule(AccountUpgradeReminder()) init() diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java index 21ebef73b..19322e15c 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java @@ -39,6 +39,12 @@ public class Storage { @Expose public long nextCityProjectParticipationTime = 0L; + + @Expose + public String currentAccountUpgrade = null; + + @Expose + public long nextAccountUpgradeCompletionTime = -1L; } public static class ProfileSpecific { diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index db1ebe161..6dc3ed238 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.features.bingo.BingoCardDisplay import at.hannibal2.skyhanni.features.bingo.BingoNextStepHelper import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper import at.hannibal2.skyhanni.features.event.diana.InquisitorWaypointShare +import at.hannibal2.skyhanni.features.fame.AccountUpgradeReminder import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.GardenCropTimeCommand import at.hannibal2.skyhanni.features.garden.composter.ComposterOverlay @@ -19,7 +20,7 @@ import at.hannibal2.skyhanni.features.garden.farming.GardenStartLocation import at.hannibal2.skyhanni.features.garden.fortuneguide.CaptureFarmingGear import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI import at.hannibal2.skyhanni.features.minion.MinionFeatures -import at.hannibal2.skyhanni.features.misc.CityProjectFeatures +import at.hannibal2.skyhanni.features.fame.CityProjectFeatures import at.hannibal2.skyhanni.features.misc.CollectionTracker import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager import at.hannibal2.skyhanni.features.misc.discordrpc.DiscordRPCManager @@ -229,6 +230,8 @@ object Commands { registerCommand("shshareinquis", "") { InquisitorWaypointShare.sendInquisitor() } registerCommand("shcopyerror", "") { CopyErrorCommand.command(it) } registerCommand("shstopcityprojectreminder", "") { CityProjectFeatures.disable() } + registerCommand("shstopaccountupgradereminder", "") { AccountUpgradeReminder.disable() } + } private fun commandHelp(args: Array) { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java index 353d99b59..588a52345 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java @@ -808,6 +808,11 @@ public class MiscConfig { @ConfigEditorBoolean public boolean harpNumbers = false; + @Expose + @ConfigOption(name = "Account Upgrade Reminder", desc = "Remind you to claim account upgrades when complete.") + @ConfigEditorBoolean + public boolean accountUpgradeReminder = true; + @Expose @ConfigOption(name = "Config Button", desc = "Add a button to the pause menu to configure SkyHanni.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/AccountUpgradeReminder.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/AccountUpgradeReminder.kt new file mode 100644 index 000000000..91efb365e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fame/AccountUpgradeReminder.kt @@ -0,0 +1,99 @@ +package at.hannibal2.skyhanni.features.fame + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.events.* +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class AccountUpgradeReminder { + private var inInventory = false + private var durationDays = -1 + private var lastReminderSend = 0L + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!LorenzUtils.inSkyBlock) return + if (event.repeatSeconds(1)) { + checkReminder() + } + } + + // TODO: Merge this logic with CityProjectFeatures reminder to reduce duplication + private fun checkReminder() { + if (!isEnabled()) return + val playerSpecific = ProfileStorageData.playerSpecific ?: return + if (ReminderUtils.isBusy()) return + if (LorenzUtils.skyBlockArea == "Community Center") return + + val upgrade = playerSpecific.currentAccountUpgrade ?: return + if (System.currentTimeMillis() <= playerSpecific.nextAccountUpgradeCompletionTime ) return + + if (lastReminderSend + 30_000 > System.currentTimeMillis()) return + lastReminderSend = System.currentTimeMillis() + + LorenzUtils.clickableChat( + "§e[SkyHanni] The §a$upgrade §eupgrade has completed! §c(Click to disable these reminders)", + "shstopaccountupgradereminder" + ) + } + + @SubscribeEvent + fun onInventoryLoad(event: InventoryFullyOpenedEvent) { + if (!LorenzUtils.inSkyBlock) return + inInventory = event.inventoryName == "Community Shop" + } + + @SubscribeEvent + @Suppress("UNUSED_PARAMETER") + fun onInventoryClose(event: InventoryCloseEvent) { + inInventory = false + } + + @SubscribeEvent + fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + if (!inInventory) return + val clickedItemLore = event.slot?.stack?.getLore() ?: return + if (clickedItemLore.getOrNull(0) != "§8Account Upgrade") return + durationDays = clickedItemLore.firstNotNullOf { + durationRegex.matchEntire(it) + }.groups[1]!!.value.toInt() + } + + @SubscribeEvent + fun onUpgradeStarted(event: LorenzChatEvent) { + if (claimedRegex.matches(event.message)) { + clearUpgrade() + } else { + val upgrade = startedRegex.matchEntire(event.message)?.groups?.get(1)?.value ?: return + startUpgrade(upgrade) + } + } + + private fun startUpgrade(upgrade: String) { + if (durationDays == -1) return + val playerSpecific = ProfileStorageData.playerSpecific ?: return + playerSpecific.currentAccountUpgrade = upgrade + playerSpecific.nextAccountUpgradeCompletionTime = System.currentTimeMillis() + durationDays.toLong() * MILLIS_IN_DAY + } + + private fun clearUpgrade() { + val playerSpecific = ProfileStorageData.playerSpecific ?: return + playerSpecific.currentAccountUpgrade = null + playerSpecific.nextAccountUpgradeCompletionTime = -1L + } + + companion object { + private val durationRegex = "§8Duration: (\\d{1,3})d".toRegex() + private val startedRegex = "§eYou started the §r§a(.+) §r§eupgrade!".toRegex() + private val claimedRegex = "§eYou claimed the §r§a.+ §r§eupgrade!".toRegex() + private const val MILLIS_IN_DAY = 1000 * 60 * 60 * 24L + + private fun isEnabled() = SkyHanniMod.feature.misc.accountUpgradeReminder + + fun disable() { + SkyHanniMod.feature.misc.accountUpgradeReminder = false + } + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt new file mode 100644 index 000000000..8e2c2e13a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt @@ -0,0 +1,194 @@ +package at.hannibal2.skyhanni.features.fame + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.events.* +import at.hannibal2.skyhanni.features.bazaar.BazaarApi +import at.hannibal2.skyhanni.features.garden.contest.FarmingContestAPI +import at.hannibal2.skyhanni.utils.* +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.RenderUtils.highlight +import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.renderables.Renderable +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.client.gui.inventory.GuiEditSign +import net.minecraft.inventory.ContainerChest +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class CityProjectFeatures { + private var display = emptyList>() + private var inInventory = false + private var lastReminderSend = 0L + private val contributeAgainPattern = "§7Contribute again: §e(?