Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: Use Repo for IslandType Data #3035

Open
wants to merge 16 commits into
base: beta
Choose a base branch
from
10 changes: 3 additions & 7 deletions src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,10 @@ object HypixelData {
scoreboardVisitingAmountPattern.firstMatcher(ScoreboardData.sidebarLinesFormatted) {
return group("maxamount").toInt() + playerAmountOnIsland
}

return when (skyBlockIsland) {
IslandType.MINESHAFT -> 4
IslandType.CATACOMBS -> 5
IslandType.CRYSTAL_HOLLOWS -> 24
IslandType.CRIMSON_ISLE -> 24
else -> if (serverId?.startsWith("mega") == true) 80 else 26
if (serverId?.startsWith("mega") == true) {
return IslandType.maxPlayersMega
}
return skyBlockIsland.islandData?.maxPlayers ?: IslandType.maxPlayers
}

// This code is modified from NEU, and depends on NEU (or another mod) sending /locraw.
Expand Down
108 changes: 76 additions & 32 deletions src/main/java/at/hannibal2/skyhanni/data/IslandType.kt
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
package at.hannibal2.skyhanni.data

enum class IslandType(val displayName: String, private val id: String?) {
// TODO
// USE SH-REPO (for displayName only)
PRIVATE_ISLAND("Private Island", "dynamic"),
PRIVATE_ISLAND_GUEST("Private Island Guest", null),
THE_END("The End", "combat_3"),
KUUDRA_ARENA("Kuudra", "kuudra"),
CRIMSON_ISLE("Crimson Isle", "crimson_isle"),
DWARVEN_MINES("Dwarven Mines", "mining_3"),
DUNGEON_HUB("Dungeon Hub", "dungeon_hub"),
CATACOMBS("Catacombs", "dungeon"),

HUB("Hub", "hub"),
DARK_AUCTION("Dark Auction", "dark_auction"),
THE_FARMING_ISLANDS("The Farming Islands", "farming_1"),
CRYSTAL_HOLLOWS("Crystal Hollows", "crystal_hollows"),
THE_PARK("The Park", "foraging_1"),
DEEP_CAVERNS("Deep Caverns", "mining_2"),
GOLD_MINES("Gold Mine", "mining_1"),
GARDEN("Garden", "garden"),
GARDEN_GUEST("Garden Guest", null),
SPIDER_DEN("Spider's Den", "combat_1"),
WINTER("Jerry's Workshop", "winter"),
THE_RIFT("The Rift", "rift"),
MINESHAFT("Mineshaft", "mineshaft"),

NONE("", null),
ANY("", null),
UNKNOWN("???", null),
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.api.event.HandleEvent.Companion.HIGHEST
import at.hannibal2.skyhanni.data.IslandType.entries
import at.hannibal2.skyhanni.data.jsonobjects.repo.IslandTypeJson
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule

enum class IslandType(private val nameFallback: String) {
PRIVATE_ISLAND("Private Island"),
PRIVATE_ISLAND_GUEST("Private Island Guest"),
THE_END("The End"),
KUUDRA_ARENA("Kuudra"),
CRIMSON_ISLE("Crimson Isle"),
DWARVEN_MINES("Dwarven Mines"),
DUNGEON_HUB("Dungeon Hub"),
CATACOMBS("Catacombs"),

HUB("Hub"),
DARK_AUCTION("Dark Auction"),
THE_FARMING_ISLANDS("The Farming Islands"),
CRYSTAL_HOLLOWS("Crystal Hollows"),
THE_PARK("The Park"),
DEEP_CAVERNS("Deep Caverns"),
GOLD_MINES("Gold Mine"),
GARDEN("Garden"),
GARDEN_GUEST("Garden Guest"),
SPIDER_DEN("Spider's Den"),
WINTER("Jerry's Workshop"),
THE_RIFT("The Rift"),
MINESHAFT("Mineshaft"),

NONE(""),
ANY(""),
UNKNOWN("???"),
;

fun guestVariant(): IslandType = when (this) {
Expand All @@ -43,14 +48,53 @@ enum class IslandType(val displayName: String, private val id: String?) {
else -> false
}

var islandData: IslandData? = null
j10a1n15 marked this conversation as resolved.
Show resolved Hide resolved
private set

val displayName: String get() = islandData?.name ?: nameFallback

@SkyHanniModule
companion object {
/**
* The maximum amount of players that can be on an island.
*/
var maxPlayers = 24
private set

fun getByNameOrUnknown(name: String): IslandType = getByNameOrNull(name) ?: UNKNOWN
fun getByName(name: String): IslandType = getByNameOrNull(name) ?: error("IslandType not found: '$name'")
/**
* The maximum amount of players that can be on a mega hub.
*/
var maxPlayersMega = 80
private set

fun getByName(name: String): IslandType = getByNameOrNull(name) ?: error("IslandType not found: '$name'")
fun getByNameOrUnknown(name: String): IslandType = getByNameOrNull(name) ?: UNKNOWN
fun getByNameOrNull(name: String): IslandType? = entries.find { it.displayName == name }

fun getByIdOrNull(id: String): IslandType? = entries.find { it.id == id }
fun getByIdOrNull(id: String): IslandType? = entries.find { it.islandData?.apiName == id }
fun getByIdOrUnknown(id: String): IslandType = getByIdOrNull(id) ?: UNKNOWN

@HandleEvent(priority = HIGHEST)
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<IslandTypeJson>("IslandType")

val islandDataMap = data.islands.mapValues {
val island = it.value
IslandData(island.name, island.apiName, island.maxPlayers ?: data.maxPlayers)
}

entries.forEach { islandType ->
islandType.islandData = islandDataMap[islandType.name]
}

maxPlayers = data.maxPlayers
maxPlayersMega = data.maxPlayersMega
}
}
}

data class IslandData(
val name: String,
val apiName: String?,
val maxPlayers: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package at.hannibal2.skyhanni.data.jsonobjects.repo

import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName

data class IslandTypeJson(
@Expose val islands: Map<String, IslandJson>,
@Expose @SerializedName("max_players") val maxPlayers: Int,
@Expose @SerializedName("max_players_mega") val maxPlayersMega: Int,
)

data class IslandJson(
@Expose val name: String,
@Expose @SerializedName("api_name") val apiName: String? = null,
@Expose @SerializedName("max_players") val maxPlayers: Int? = null,
)
Loading