aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
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
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')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/storage/PlayerSpecificStorage.java6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java4
-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
6 files changed, 207 insertions, 126 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
index fdedfdbab..b674c382a 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
@@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive
object ConfigUpdaterMigrator {
val logger = LorenzLogger("ConfigMigration")
- const val CONFIG_VERSION = 48
+ const val CONFIG_VERSION = 49
fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java
index c390e7feb..bd96bb425 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java
@@ -199,7 +199,7 @@ public class MiscConfig {
public boolean restorePieceOfWizardPortalLore = true;
@Expose
- @ConfigOption(name = "Account Upgrade Reminder", desc = "Remind you to claim account upgrades when complete.")
+ @ConfigOption(name = "Account Upgrade Reminder", desc = "Remind you to claim community shop account and profile upgrades when complete.")
@ConfigEditorBoolean
@FeatureToggle
public boolean accountUpgradeReminder = true;
diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/PlayerSpecificStorage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/PlayerSpecificStorage.java
index e30f62946..a03928745 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/storage/PlayerSpecificStorage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/storage/PlayerSpecificStorage.java
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.config.storage;
import at.hannibal2.skyhanni.features.bingo.card.goals.BingoGoal;
+import at.hannibal2.skyhanni.features.fame.UpgradeReminder;
import at.hannibal2.skyhanni.utils.NEUInternalName;
import com.google.gson.annotations.Expose;
@@ -26,10 +27,7 @@ public class PlayerSpecificStorage {
public long nextCityProjectParticipationTime = 0L;
@Expose
- public String currentAccountUpgrade = null;
-
- @Expose
- public long nextAccountUpgradeCompletionTime = -1L;
+ public UpgradeReminder.CommunityShopUpgrade communityShopAccountUpgrade = null;
@Expose
public List<String> guildMembers = new ArrayList<>();
diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java
index cc0503f37..074d4cc19 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java
@@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.features.dungeon.DungeonFloor;
import at.hannibal2.skyhanni.features.event.diana.DianaProfitTracker;
import at.hannibal2.skyhanni.features.event.diana.MythologicalCreatureTracker;
import at.hannibal2.skyhanni.features.event.jerry.frozentreasure.FrozenTreasureTracker;
+import at.hannibal2.skyhanni.features.fame.UpgradeReminder;
import at.hannibal2.skyhanni.features.fishing.tracker.FishingProfitTracker;
import at.hannibal2.skyhanni.features.fishing.tracker.SeaCreatureTracker;
import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity;
@@ -609,4 +610,7 @@ public class ProfileSpecificStorage {
@Expose
public Map<SkillType, SkillAPI.SkillInfo> skillData = new HashMap<>();
+
+ @Expose
+ public UpgradeReminder.CommunityShopUpgrade communityShopProfileUpgrade = null;
}
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
+ }
+ }
+ }
+ }
+}