From 5c200ca99da0c2d6baa9aeabb52805906bbe5d4c Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Sun, 8 Dec 2024 14:54:45 +0100 Subject: [PATCH 1/6] use repo for island data Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- .../at/hannibal2/skyhanni/data/HypixelData.kt | 10 +- .../at/hannibal2/skyhanni/data/IslandType.kt | 105 +++++++++++++----- .../skyhanni/data/LocationFixData.kt | 2 +- .../data/jsonobjects/repo/IslandTypeJson.kt | 16 +++ 4 files changed, 96 insertions(+), 37 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/IslandTypeJson.kt diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index b243fe9be355..16a00c70f35e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -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.data?.maxPlayersMega ?: 80 } + return skyBlockIsland.data?.maxPlayers ?: 26 } // This code is modified from NEU, and depends on NEU (or another mod) sending /locraw. diff --git a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt index 4d36c1c0182e..40b9001b0404 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt @@ -1,40 +1,87 @@ 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("???"), +import at.hannibal2.skyhanni.data.IslandType.entries +import at.hannibal2.skyhanni.data.jsonobjects.repo.IslandTypeJson +import at.hannibal2.skyhanni.events.DebugDataCollectEvent +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 + + val displayName: String get() = islandData?.name ?: name + + @SkyHanniModule companion object { + var islandTypesData: IslandTypeJson? = null + 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 + fun onDebug(event: DebugDataCollectEvent) { + event.title("IslandType") + event.addIrrelevant { + add("Max players fallback: ${islandTypesData?.maxPlayers}") + add("Max players mega fallback ${islandTypesData?.maxPlayersMega}") + islandTypesData?.islands?.forEach { + add("${it.key}: ${it.value.name} - ${it.value.apiName} - ${it.value.maxPlayers}") + } + } + } + + @SubscribeEvent(priority = EventPriority.HIGHEST) + fun onRepoReload(event: RepositoryReloadEvent) { + val data = event.getConstant("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, +) diff --git a/src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt b/src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt index 8ec067deb926..0d3f899b97b5 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt @@ -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("LocationFix") locationFixes.clear() diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/IslandTypeJson.kt b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/IslandTypeJson.kt new file mode 100644 index 000000000000..cab89d366162 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/IslandTypeJson.kt @@ -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, + @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, +) From d49c805b26de6da84c04c359088b3a257e2ab58f Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Sun, 8 Dec 2024 15:02:25 +0100 Subject: [PATCH 2/6] oops Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index 16a00c70f35e..4b9d9f831c50 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -288,9 +288,9 @@ object HypixelData { return group("maxamount").toInt() } if (serverId?.startsWith("mega") == true) { - return IslandType.data?.maxPlayersMega ?: 80 + return IslandType.islandTypesData?.maxPlayersMega ?: 80 } - return skyBlockIsland.data?.maxPlayers ?: 26 + return skyBlockIsland.islandData?.maxPlayers ?: 26 } // This code is modified from NEU, and depends on NEU (or another mod) sending /locraw. From b193a84cb2a6e65fc4fea753c34af287fd5c9e01 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Sun, 8 Dec 2024 16:03:32 +0100 Subject: [PATCH 3/6] sure Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- .../java/at/hannibal2/skyhanni/data/IslandType.kt | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt index 40b9001b0404..617dc8dbb7fe 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt @@ -2,7 +2,6 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.data.IslandType.entries import at.hannibal2.skyhanni.data.jsonobjects.repo.IslandTypeJson -import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import net.minecraftforge.fml.common.eventhandler.EventPriority @@ -51,18 +50,6 @@ enum class IslandType { fun getByNameOrNull(name: String) = entries.firstOrNull { it.islandData?.name == name } - @SubscribeEvent - fun onDebug(event: DebugDataCollectEvent) { - event.title("IslandType") - event.addIrrelevant { - add("Max players fallback: ${islandTypesData?.maxPlayers}") - add("Max players mega fallback ${islandTypesData?.maxPlayersMega}") - islandTypesData?.islands?.forEach { - add("${it.key}: ${it.value.name} - ${it.value.apiName} - ${it.value.maxPlayers}") - } - } - } - @SubscribeEvent(priority = EventPriority.HIGHEST) fun onRepoReload(event: RepositoryReloadEvent) { val data = event.getConstant("IslandType") From ebb014eb30b5ec5efb376b9aee76937d2c840645 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:51:51 +0100 Subject: [PATCH 4/6] Assume 24 is default max --- src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index 4b9d9f831c50..7176ccc7042a 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -290,7 +290,7 @@ object HypixelData { if (serverId?.startsWith("mega") == true) { return IslandType.islandTypesData?.maxPlayersMega ?: 80 } - return skyBlockIsland.islandData?.maxPlayers ?: 26 + return skyBlockIsland.islandData?.maxPlayers ?: 24 } // This code is modified from NEU, and depends on NEU (or another mod) sending /locraw. From f508d7aeb4d1f621955bb38941fd6c057e0f4973 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:11:06 +0100 Subject: [PATCH 5/6] name fallback Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- .../at/hannibal2/skyhanni/data/IslandType.kt | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt index 617dc8dbb7fe..30d82ce96fab 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt @@ -7,38 +7,39 @@ 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, +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, - DARK_AUCTION, - THE_FARMING_ISLANDS, - CRYSTAL_HOLLOWS, - THE_PARK, - DEEP_CAVERNS, - GOLD_MINES, - GARDEN, - GARDEN_GUEST, - SPIDER_DEN, - WINTER, - THE_RIFT, - MINESHAFT, + 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, + NONE(""), + ANY(""), + UNKNOWN("???"), ; var islandData: IslandData? = null + private set - val displayName: String get() = islandData?.name ?: name + val displayName: String get() = islandData?.name ?: nameFallback @SkyHanniModule companion object { From b1896ecdc3ee6d3a1738c34034a1ca530f00e90f Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:28:38 +0100 Subject: [PATCH 6/6] resolve empa Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- .../java/at/hannibal2/skyhanni/data/HypixelData.kt | 4 ++-- .../java/at/hannibal2/skyhanni/data/IslandType.kt | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index 7176ccc7042a..db01794cf7b7 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -288,9 +288,9 @@ object HypixelData { return group("maxamount").toInt() } if (serverId?.startsWith("mega") == true) { - return IslandType.islandTypesData?.maxPlayersMega ?: 80 + return IslandType.maxPlayersMega } - return skyBlockIsland.islandData?.maxPlayers ?: 24 + return skyBlockIsland.islandData?.maxPlayers ?: IslandType.maxPlayers } // This code is modified from NEU, and depends on NEU (or another mod) sending /locraw. diff --git a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt index 30d82ce96fab..67ebf3d33321 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt @@ -43,7 +43,16 @@ enum class IslandType(private val nameFallback: String) { @SkyHanniModule companion object { - var islandTypesData: IslandTypeJson? = null + /** + * The maximum amount of players that can be on an island. + */ + var maxPlayers = 24 + private set + + /** + * The maximum amount of players that can be on a mega hub. + */ + var maxPlayersMega = 80 private set fun getByNameOrUnknown(name: String) = getByNameOrNull(name) ?: UNKNOWN @@ -63,7 +72,8 @@ enum class IslandType(private val nameFallback: String) { islandType.islandData = islandDataMap[islandType.name] } - islandTypesData = data + maxPlayers = data.maxPlayers + maxPlayersMega = data.maxPlayersMega } } }