aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJ10a1n15 <45315647+j10a1n15@users.noreply.github.com>2024-07-30 11:18:57 +0200
committerGitHub <noreply@github.com>2024-07-30 11:18:57 +0200
commit9edcf44987a1ef394d170f1980dd005fca1c1693 (patch)
tree6192d1bcde65b0f7653ca7435c39d50c81a7d6e0 /src
parent47c059081aa202b45d84f02e0b85a3579142fdac (diff)
downloadskyhanni-9edcf44987a1ef394d170f1980dd005fca1c1693.tar.gz
skyhanni-9edcf44987a1ef394d170f1980dd005fca1c1693.tar.bz2
skyhanni-9edcf44987a1ef394d170f1980dd005fca1c1693.zip
Backend: Updated getting active Mayor from API (#2227)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt40
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/Mayors.kt24
2 files changed, 29 insertions, 35 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt
index 1c759a17d..c484f4071 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt
@@ -2,8 +2,8 @@ package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigManager
+import at.hannibal2.skyhanni.data.Mayor.Companion.addPerks
import at.hannibal2.skyhanni.data.Mayor.Companion.getMayorFromPerk
-import at.hannibal2.skyhanni.data.Mayor.Companion.setAssumeMayor
import at.hannibal2.skyhanni.data.Mayor.Companion.setAssumeMayorJson
import at.hannibal2.skyhanni.data.Perk.Companion.getPerkFromName
import at.hannibal2.skyhanni.data.jsonobjects.other.MayorCandidate
@@ -105,13 +105,13 @@ object MayorAPI {
/**
* @param input: The name of the mayor
- * @return: The neu color of the mayor; If no mayor was found, it will return "§c"
+ * @return: The NotEnoughUpdates color of the mayor; If no mayor was found, it will return "§c"
*/
fun mayorNameToColorCode(input: String): String = Mayor.getMayorFromName(input)?.color ?: "§c"
/**
* @param input: The name of the mayor
- * @return: The neu color of the mayor + the name of the mayor; If no mayor was found, it will return "§c[input]"
+ * @return: The NotEnoughUpdates color of the mayor + the name of the mayor; If no mayor was found, it will return "§c[input]"
*/
fun mayorNameWithColorCode(input: String) = mayorNameToColorCode(input) + input
@@ -159,15 +159,14 @@ object MayorAPI {
if (!calendarGuiPattern.matches(event.inventoryName)) return
- val stack: ItemStack =
- event.inventoryItems.values.firstOrNull { jerryHeadPattern.matches(it.displayName) } ?: return
+ val stack: ItemStack = event.inventoryItems.values.firstOrNull { jerryHeadPattern.matches(it.displayName) } ?: return
val perk = stack.getLore().nextAfter({ perkpocalypsePerksPattern.matches(it) }) ?: return
- // This is one Perk of the Perkpocalypse Mayor
+ // This is the first Perk of the Perkpocalypse Mayor
val jerryMayor = getMayorFromPerk(getPerkFromName(perk.removeColor()) ?: return)?.addAllPerks() ?: return
val lastMayorTimestamp = nextMayorTimestamp - SKYBLOCK_YEAR_MILLIS.milliseconds
-
+
val expireTime = (1..21)
.map { lastMayorTimestamp + (6.hours * it) }
.firstOrNull { it.isInFuture() }
@@ -195,20 +194,11 @@ object MayorAPI {
nextMayorTimestamp = calculateNextMayorTime()
}
- private fun checkCurrentMayor() {
- val nextMayorTime = calculateNextMayorTime()
-
- // Check if it is still the mayor from the old SkyBlock year
- currentMayor = candidates[nextMayorTime.toSkyBlockTime().year - 1]?.let {
- if (it.name == lastMayor?.name) return
-
- // TODO: Once Jerry is active, add the sub mayor perks in here
- setAssumeMayorJson(it.name, it.perks)
+ private fun checkHypixelAPI(forceReload: Boolean = false) {
+ if (!forceReload) {
+ if (lastUpdate.passedSince() < 20.minutes) return
+ if (currentMayor == Mayor.UNKNOWN && lastUpdate.passedSince() < 1.minutes) return
}
- }
-
- private fun checkHypixelAPI() {
- if (lastUpdate.passedSince() < 20.minutes || (currentMayor == Mayor.UNKNOWN && lastUpdate.passedSince() < 1.minutes)) return
lastUpdate = SimpleTimeMark.now()
SkyHanniMod.coroutineScope.launch {
@@ -222,7 +212,11 @@ object MayorAPI {
map put data.current.getPairs()
}
candidates = map
- checkCurrentMayor()
+
+ val currentMayorName = data.mayor.name
+ if (lastMayor?.name != currentMayorName) {
+ currentMayor = setAssumeMayorJson(currentMayorName, data.mayor.perks)
+ }
}
}
@@ -236,9 +230,9 @@ object MayorAPI {
val mayor = SkyHanniMod.feature.dev.debug.assumeMayor.get()
if (mayor == Mayor.DISABLED) {
- checkCurrentMayor()
+ checkHypixelAPI(forceReload = true)
} else {
- mayor.setAssumeMayor(mayor.perks.toList())
+ mayor.addPerks(mayor.perks.toList())
currentMayor = mayor
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/Mayors.kt b/src/main/java/at/hannibal2/skyhanni/data/Mayors.kt
index b2ac98b32..975282a3a 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/Mayors.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/Mayors.kt
@@ -16,7 +16,7 @@ enum class Mayor(
"§3",
Perk.SLASHED_PRICING,
Perk.SLAYER_XP_BUFF,
- Perk.PATHFINDER
+ Perk.PATHFINDER,
),
COLE(
"Cole",
@@ -24,7 +24,7 @@ enum class Mayor(
Perk.PROSPECTION,
Perk.MINING_XP_BUFF,
Perk.MINING_FIESTA,
- Perk.MOLTEN_FORGE
+ Perk.MOLTEN_FORGE,
),
DIANA(
"Diana",
@@ -32,7 +32,7 @@ enum class Mayor(
Perk.LUCKY,
Perk.MYTHOLOGICAL_RITUAL,
Perk.PET_XP_BUFF,
- Perk.SHARING_IS_CARING
+ Perk.SHARING_IS_CARING,
),
DIAZ(
"Diaz",
@@ -40,7 +40,7 @@ enum class Mayor(
Perk.VOLUME_TRADING,
Perk.SHOPPING_SPREE,
Perk.STOCK_EXCHANGE,
- Perk.LONG_TERM_INVESTMENT
+ Perk.LONG_TERM_INVESTMENT,
),
FINNEGAN(
"Finnegan",
@@ -48,7 +48,7 @@ enum class Mayor(
Perk.FARMING_SIMULATOR,
Perk.PELT_POCALYPSE,
Perk.GOATED,
- Perk.BLOOMING_BUSINESS
+ Perk.BLOOMING_BUSINESS,
),
FOXY(
"Foxy",
@@ -66,28 +66,28 @@ enum class Mayor(
Perk.FISHING_XP_BUFF,
Perk.LUCK_OF_THE_SEA,
Perk.FISHING_FESTIVAL,
- Perk.DOUBLE_TROUBLE
+ Perk.DOUBLE_TROUBLE,
),
PAUL(
"Paul",
"§c",
Perk.MARAUDER,
Perk.EZPZ,
- Perk.BENEDICTION
+ Perk.BENEDICTION,
),
SCORPIUS(
"Scorpius",
"§d",
Perk.BRIBE,
- Perk.DARKER_AUCTIONS
+ Perk.DARKER_AUCTIONS,
),
JERRY(
"Jerry",
"§d",
Perk.PERKPOCALYPSE,
Perk.STATSPOCALYPSE,
- Perk.JERRYPOCALYPSE
+ Perk.JERRYPOCALYPSE,
),
DERPY(
"Derpy",
@@ -95,7 +95,7 @@ enum class Mayor(
Perk.TURBO_MINIONS,
Perk.AH_TAX,
Perk.DOUBLE_MOBS_HP,
- Perk.MOAR_SKILLZ
+ Perk.MOAR_SKILLZ,
),
UNKNOWN("Unknown", "§c"),
@@ -136,11 +136,11 @@ enum class Mayor(
Perk.entries.firstOrNull { it.perkName == perk.renameIfFoxyExtraEventPerkFound() }
}
- mayor.setAssumeMayor(perks)
+ mayor.addPerks(perks)
return mayor
}
- fun Mayor.setAssumeMayor(perks: List<Perk>) {
+ fun Mayor.addPerks(perks: List<Perk>) {
perks.forEach { it.isActive = false }
activePerks.clear()
for (perk in perks.filter { perks.contains(it) }) {