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 5 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
41 changes: 38 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/IslandType.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package at.hannibal2.skyhanni.data

enum class IslandType(val displayName: String) {
// TODO USE SH-REPO (for displayName only)
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 val nameFallback: String) {
PRIVATE_ISLAND("Private Island"),
PRIVATE_ISLAND_GUEST("Private Island Guest"),
THE_END("The End"),
Expand Down Expand Up @@ -30,11 +36,40 @@ enum class IslandType(val displayName: String) {
UNKNOWN("???"),
;

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 {
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