aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/fame
diff options
context:
space:
mode:
authorappable <16139460+appable0@users.noreply.github.com>2024-06-08 01:07:25 -0700
committerGitHub <noreply@github.com>2024-06-08 10:07:25 +0200
commitb649c903a5feab9fd92c5a9119514e2a4f7508c1 (patch)
tree958396a486ba599725a7da6849e2af7a806db9ed /src/main/java/at/hannibal2/skyhanni/features/fame
parent5b3ee9de1856d9989e20cc4d534cac17089ce0e5 (diff)
downloadskyhanni-b649c903a5feab9fd92c5a9119514e2a4f7508c1.tar.gz
skyhanni-b649c903a5feab9fd92c5a9119514e2a4f7508c1.tar.bz2
skyhanni-b649c903a5feab9fd92c5a9119514e2a4f7508c1.zip
Fix: Account Upgrade Reminders with simultaneous profile and account upgrades (#2007)
Co-authored-by: Cal <cwolfson58@gmail.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/fame')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fame/AccountUpgradeReminder.kt120
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fame/UpgradeReminder.kt199
2 files changed, 199 insertions, 120 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/AccountUpgradeReminder.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/AccountUpgradeReminder.kt
deleted file mode 100644
index b1001fe52..000000000
--- a/src/main/java/at/hannibal2/skyhanni/features/fame/AccountUpgradeReminder.kt
+++ /dev/null
@@ -1,120 +0,0 @@
-package at.hannibal2.skyhanni.features.fame
-
-import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.data.ProfileStorageData
-import at.hannibal2.skyhanni.events.GuiContainerEvent
-import at.hannibal2.skyhanni.events.InventoryCloseEvent
-import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
-import at.hannibal2.skyhanni.events.LorenzChatEvent
-import at.hannibal2.skyhanni.events.SecondPassedEvent
-import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
-import at.hannibal2.skyhanni.utils.ChatUtils
-import at.hannibal2.skyhanni.utils.ItemUtils.getLore
-import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.SimpleTimeMark
-import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import kotlin.time.Duration
-import kotlin.time.Duration.Companion.days
-import kotlin.time.Duration.Companion.seconds
-
-@SkyHanniModule
-object AccountUpgradeReminder {
-
- private var inInventory = false
- private var duration: Duration? = null
- private var lastReminderSend = SimpleTimeMark.farPast()
-
- // TODO repo patterns
- 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()
-
- // TODO: find a way to save SimpleTimeMark directly in the config
- private var nextCompletionTime: SimpleTimeMark?
- get() = ProfileStorageData.playerSpecific?.nextAccountUpgradeCompletionTime?.asTimeMark()
- set(value) {
- value?.let {
- ProfileStorageData.playerSpecific?.nextAccountUpgradeCompletionTime = it.toMillis()
- }
- }
-
- // TODO: Merge this logic with CityProjectFeatures reminder to reduce duplication
- @SubscribeEvent
- fun onSecondPassed(event: SecondPassedEvent) {
- if (!LorenzUtils.inSkyBlock) return
-
- if (!isEnabled()) return
- val playerSpecific = ProfileStorageData.playerSpecific ?: return
- if (ReminderUtils.isBusy()) return
- if (LorenzUtils.skyBlockArea == "Community Center") return
-
- val upgrade = playerSpecific.currentAccountUpgrade ?: return
- val nextCompletionTime = nextCompletionTime ?: return
- if (!nextCompletionTime.isInPast()) return
- if (lastReminderSend.passedSince() < 30.seconds) return
- lastReminderSend = SimpleTimeMark.now()
-
- ChatUtils.clickableChat(
- "The §a$upgrade §eupgrade has completed! §c(Click to disable these reminders)",
- onClick = {
- disable()
- },
- oneTimeClick = true
- )
- }
-
- @SubscribeEvent
- fun onInventoryOpen(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
- val result = clickedItemLore.firstNotNullOfOrNull {
- durationRegex.matchEntire(it)
- } ?: return
- duration = result.groups[1]!!.value.toInt().days
- }
-
- @SubscribeEvent
- fun onChat(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) {
- val duration = duration ?: return
- val playerSpecific = ProfileStorageData.playerSpecific ?: return
- playerSpecific.currentAccountUpgrade = upgrade
-
- nextCompletionTime = SimpleTimeMark.now() + duration
- }
-
- private fun clearUpgrade() {
- val playerSpecific = ProfileStorageData.playerSpecific ?: return
- playerSpecific.currentAccountUpgrade = null
- nextCompletionTime = SimpleTimeMark.farPast()
- }
-
- private fun isEnabled() = SkyHanniMod.feature.misc.accountUpgradeReminder
-
- fun disable() {
- SkyHanniMod.feature.misc.accountUpgradeReminder = false
- ChatUtils.chat("Disabled account upgrade reminder.")
- }
-}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/UpgradeReminder.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/UpgradeReminder.kt
new file mode 100644
index 000000000..22171ed3b
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/fame/UpgradeReminder.kt
@@ -0,0 +1,199 @@
+package at.hannibal2.skyhanni.features.fame
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
+import at.hannibal2.skyhanni.data.ProfileStorageData
+import at.hannibal2.skyhanni.events.GuiContainerEvent
+import at.hannibal2.skyhanni.events.InventoryCloseEvent
+import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
+import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.events.SecondPassedEvent
+import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
+import at.hannibal2.skyhanni.utils.ChatUtils
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.RegexUtils.anyMatches
+import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst
+import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.RegexUtils.matches
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+import com.google.gson.annotations.Expose
+import net.minecraft.item.ItemStack
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration
+import kotlin.time.Duration.Companion.seconds
+
+@SkyHanniModule
+object UpgradeReminder {
+ private val patternGroup = RepoPattern.group("fame.upgrades")
+
+ private val accountUpgradePattern by patternGroup.pattern(
+ "account",
+ "§8Account Upgrade"
+ )
+ private val profileUpgradePattern by patternGroup.pattern(
+ "profile",
+ "§8Profile Upgrade"
+ )
+ private val upgradeDurationPattern by patternGroup.pattern(
+ "duration",
+ "§8Duration: (?<duration>.+)"
+ )
+ private val upgradeStartedPattern by patternGroup.pattern(
+ "started",
+ "§eYou started the §r§a(?<upgrade>.+) §r§eupgrade!"
+ )
+ private val upgradeClaimedPattern by patternGroup.pattern(
+ "claimed",
+ "§eYou claimed the §r§a(?<upgrade>.+) §r§eupgrade!"
+ )
+ private val upgradePattern by patternGroup.pattern(
+ "upgrade",
+ "§eClick to start upgrade!"
+ )
+
+ private var currentProfileUpgrade: CommunityShopUpgrade?
+ get() = ProfileStorageData.profileSpecific?.communityShopProfileUpgrade
+ set(value) {
+ ProfileStorageData.profileSpecific?.communityShopProfileUpgrade = value
+ }
+
+ private var currentAccountUpgrade: CommunityShopUpgrade?
+ get() = ProfileStorageData.playerSpecific?.communityShopAccountUpgrade
+ set(value) {
+ ProfileStorageData.playerSpecific?.communityShopAccountUpgrade = value
+ }
+
+ private var inInventory = false
+ private var clickedUpgradeType: UpgradeType? = null
+ private var clickedUpgrade: CommunityShopUpgrade? = null
+ private var lastReminderSend = SimpleTimeMark.farPast()
+
+ // TODO: (for 0.27) merge this logic with reminder manager
+ @SubscribeEvent
+ fun onSecondPassed(event: SecondPassedEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (!isEnabled()) return
+ if (ReminderUtils.isBusy()) return
+ if (inInventory || LorenzUtils.skyBlockArea == "Community Center") return
+ if (lastReminderSend.passedSince() < 30.seconds) return
+
+ currentProfileUpgrade?.sendReminderIfClaimable()
+ currentAccountUpgrade?.sendReminderIfClaimable()
+
+ lastReminderSend = SimpleTimeMark.now()
+ }
+
+ @SubscribeEvent
+ fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ inInventory = event.inventoryName == "Community Shop"
+ }
+
+ @SubscribeEvent
+ fun onInventoryClose(event: InventoryCloseEvent) {
+ inInventory = false
+ }
+
+ @SubscribeEvent
+ fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) {
+ if (!inInventory) return
+ val item = event.item ?: return
+ clickedUpgradeType = UpgradeType.fromItem(item) ?: return
+ clickedUpgrade = CommunityShopUpgrade.fromItem(item) ?: return
+ }
+
+ @SubscribeEvent
+ fun onChat(event: LorenzChatEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (upgradeStartedPattern.matches(event.message)) {
+ clickedUpgrade?.start()
+ when (clickedUpgradeType) {
+ UpgradeType.PROFILE -> currentProfileUpgrade = clickedUpgrade
+ UpgradeType.ACCOUNT -> currentAccountUpgrade = clickedUpgrade
+ null -> {}
+ }
+ return
+ }
+
+ upgradeClaimedPattern.matchMatcher(event.message) {
+ val claimedUpgradeName = group("upgrade")
+ when (claimedUpgradeName) {
+ currentProfileUpgrade?.name -> currentProfileUpgrade = null
+ currentAccountUpgrade?.name -> currentAccountUpgrade = null
+ }
+ }
+ }
+
+ private fun isEnabled() = SkyHanniMod.feature.misc.accountUpgradeReminder
+
+ fun disable() {
+ SkyHanniMod.feature.misc.accountUpgradeReminder = false
+ }
+
+ @SubscribeEvent
+ fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
+ event.move(49,
+ "#player.currentAccountUpgrade",
+ "#player.communityShopAccountUpgrade.name"
+ )
+
+ event.move(49,
+ "#player.nextAccountUpgradeCompletionTime",
+ "#player.communityShopAccountUpgrade.completionTime"
+ )
+ }
+
+ class CommunityShopUpgrade(
+ @Expose val name: String?,
+ @Expose var completionTime: SimpleTimeMark = SimpleTimeMark.farFuture()
+ ) {
+ private var duration: Duration = Duration.ZERO
+
+ fun start() {
+ this.completionTime = SimpleTimeMark.now() + duration
+ }
+
+ fun sendReminderIfClaimable() {
+ if (this.name == null || this.completionTime.isInFuture()) return
+ ChatUtils.clickableChat(
+ "The §a$name §eupgrade has completed! §c(Click to disable these reminders)", onClick = {
+ disable()
+ }, oneTimeClick = true
+ )
+ }
+
+ companion object {
+ fun fromItem(item: ItemStack): CommunityShopUpgrade? {
+ val name = item.displayName
+ val lore = item.getLore()
+ val upgrade = CommunityShopUpgrade(name)
+ upgrade.duration = lore.matchFirst(upgradeDurationPattern) {
+ val durationStr = group("duration")
+ if (durationStr == "Instant!") return null
+ TimeUtils.getDuration(durationStr)
+ } ?: Duration.ZERO
+ return upgrade
+ }
+ }
+ }
+
+ enum class UpgradeType {
+ PROFILE,
+ ACCOUNT,
+ ;
+
+ companion object {
+ fun fromItem(item: ItemStack): UpgradeType? {
+ val lore = item.getLore()
+ return when {
+ accountUpgradePattern.anyMatches(lore) -> ACCOUNT
+ profileUpgradePattern.anyMatches(lore) -> PROFILE
+ else -> null
+ }
+ }
+ }
+ }
+}