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 8 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -287,14 +287,10 @@ object HypixelData {
scoreboardVisitingAmountPattern.firstMatcher(ScoreboardData.sidebarLinesFormatted) {
return group("maxamount").toInt()
}

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.islandTypesData?.maxPlayersMega ?: 80
}
return skyBlockIsland.islandData?.maxPlayers ?: 24
}

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

enum class IslandType(val displayName: String) {
// TODO USE SH-REPO (for displayName only)
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("???"),
j10a1n15 marked this conversation as resolved.
Show resolved Hide resolved
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
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

enum class IslandType {
PRIVATE_ISLAND,
PRIVATE_ISLAND_GUEST,
THE_END,
KUUDRA_ARENA,
CRIMSON_ISLE,
DWARVEN_MINES,
DUNGEON_HUB,
CATACOMBS,

HUB,
DARK_AUCTION,
THE_FARMING_ISLANDS,
CRYSTAL_HOLLOWS,
THE_PARK,
DEEP_CAVERNS,
GOLD_MINES,
GARDEN,
GARDEN_GUEST,
SPIDER_DEN,
WINTER,
THE_RIFT,
MINESHAFT,

NONE,
ANY,
UNKNOWN,
;

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

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

@SkyHanniModule
companion object {
var islandTypesData: IslandTypeJson? = null
j10a1n15 marked this conversation as resolved.
Show resolved Hide resolved
private set

fun getByNameOrUnknown(name: String) = getByNameOrNull(name) ?: UNKNOWN
fun getByName(name: String) = getByNameOrNull(name) ?: error("IslandType not found: '$name'")

fun getByNameOrNull(name: String) = entries.firstOrNull { it.displayName == name }
fun getByNameOrNull(name: String) = entries.firstOrNull { it.islandData?.name == name }

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

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

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

islandTypesData = data
}
}
}

data class IslandData(
val name: String,
val apiName: String?,
val maxPlayers: Int,
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object LocationFixData {
private data class LocationFix(val area: AxisAlignedBB, val realLocation: String)

// priority set to low so that IslandType can load their island names from repo earlier
@SubscribeEvent(priority = EventPriority.LOW)
@SubscribeEvent(priority = EventPriority.LOWEST)
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<LocationFixJson>("LocationFix")
locationFixes.clear()
Expand Down
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