From 3708ea6a83c39badad3486143572949d1933dfe6 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Tue, 10 Sep 2024 20:40:01 +0200 Subject: Improvement: Add per election year diana trackers (#2487) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/data') diff --git a/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt index 2f89b340b..b4fb7eaa2 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt @@ -186,17 +186,21 @@ object MayorAPI { jerryExtraMayor = jerryMayor to expireTime } - private fun calculateNextMayorTime(): SimpleTimeMark { - val now = SkyBlockTime.now() - var mayorYear = now.year + fun SkyBlockTime.getElectionYear(): Int { + var mayorYear = year - // Check if either the month is already over or the day after 27th in the third month - if (now.month > ELECTION_END_MONTH || (now.day >= ELECTION_END_DAY && now.month == ELECTION_END_MONTH)) { - // If so, the next mayor will be in the next year - mayorYear++ + // Check if this year's election has not happened yet + if (month < ELECTION_END_MONTH || (day < ELECTION_END_DAY && month == ELECTION_END_MONTH)) { + // If so, the current mayor is still from last year's election + mayorYear-- } + return mayorYear + } + + private fun calculateNextMayorTime(): SimpleTimeMark { + val now = SkyBlockTime.now() - return SkyBlockTime(mayorYear, ELECTION_END_MONTH, day = ELECTION_END_DAY).asTimeMark() + return SkyBlockTime(now.getElectionYear() + 1, ELECTION_END_MONTH, day = ELECTION_END_DAY).asTimeMark() } private fun getTimeTillNextMayor() { -- cgit