summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorappable <enzospiacitelli@gmail.com>2023-08-15 03:17:04 -0700
committerGitHub <noreply@github.com>2023-08-15 12:17:04 +0200
commit75a80664c2034fc4a68a115a1b686676a53949d5 (patch)
tree76e90f7330ac156272575b6f4b6c1683ab801196 /src/main/java/at/hannibal2/skyhanni/features
parentd4ef6a6e3e1bee596ccbb38fef8abcce7290615e (diff)
downloadskyhanni-75a80664c2034fc4a68a115a1b686676a53949d5.tar.gz
skyhanni-75a80664c2034fc4a68a115a1b686676a53949d5.tar.bz2
skyhanni-75a80664c2034fc4a68a115a1b686676a53949d5.zip
Merge pull request #380
* account upgrade reminder
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fame/AccountUpgradeReminder.kt99
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/misc/CityProjectFeatures.kt)6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fame/ReminderUtils.kt9
3 files changed, 110 insertions, 4 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
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/misc/CityProjectFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt
index e8d453066..8e2c2e13a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/CityProjectFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fame/CityProjectFeatures.kt
@@ -1,4 +1,4 @@
-package at.hannibal2.skyhanni.features.misc
+package at.hannibal2.skyhanni.features.fame
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.ProfileStorageData
@@ -46,9 +46,7 @@ class CityProjectFeatures {
private fun checkDailyReminder() {
if (!config.dailyReminder) return
val playerSpecific = ProfileStorageData.playerSpecific ?: return
- if (LorenzUtils.inDungeons) return
- if (LorenzUtils.inKuudraFight) return
- if (FarmingContestAPI.inContest) return
+ if (ReminderUtils.isBusy()) return
if (LorenzUtils.skyBlockArea == "Community Center") return
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fame/ReminderUtils.kt b/src/main/java/at/hannibal2/skyhanni/features/fame/ReminderUtils.kt
new file mode 100644
index 000000000..6d1ab94e1
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/fame/ReminderUtils.kt
@@ -0,0 +1,9 @@
+package at.hannibal2.skyhanni.features.fame
+
+import at.hannibal2.skyhanni.features.garden.contest.FarmingContestAPI
+import at.hannibal2.skyhanni.utils.LorenzUtils
+
+object ReminderUtils {
+ fun isBusy(): Boolean =
+ LorenzUtils.inDungeons || LorenzUtils.inKuudraFight || FarmingContestAPI.inContest
+} \ No newline at end of file