Fix profile viewer for missing uuid pets
This commit is contained in:
@@ -10,19 +10,20 @@ package moe.nea.firmament.apis
|
|||||||
|
|
||||||
import io.github.moulberry.repo.constants.Leveling
|
import io.github.moulberry.repo.constants.Leveling
|
||||||
import io.github.moulberry.repo.data.Rarity
|
import io.github.moulberry.repo.data.Rarity
|
||||||
import java.util.*
|
|
||||||
import kotlinx.datetime.Instant
|
import kotlinx.datetime.Instant
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.UseSerializers
|
import kotlinx.serialization.UseSerializers
|
||||||
import kotlin.reflect.KProperty1
|
|
||||||
import net.minecraft.util.DyeColor
|
|
||||||
import net.minecraft.util.Formatting
|
|
||||||
import moe.nea.firmament.repo.RepoManager
|
import moe.nea.firmament.repo.RepoManager
|
||||||
import moe.nea.firmament.util.LegacyFormattingCode
|
import moe.nea.firmament.util.LegacyFormattingCode
|
||||||
import moe.nea.firmament.util.SkyblockId
|
import moe.nea.firmament.util.SkyblockId
|
||||||
|
import moe.nea.firmament.util.assertNotNullOr
|
||||||
import moe.nea.firmament.util.json.DashlessUUIDSerializer
|
import moe.nea.firmament.util.json.DashlessUUIDSerializer
|
||||||
import moe.nea.firmament.util.json.InstantAsLongSerializer
|
import moe.nea.firmament.util.json.InstantAsLongSerializer
|
||||||
|
import net.minecraft.util.DyeColor
|
||||||
|
import net.minecraft.util.Formatting
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.reflect.KProperty1
|
||||||
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@@ -81,7 +82,7 @@ enum class Skill(val accessor: KProperty1<Member, Double>, val color: DyeColor,
|
|||||||
ENCHANTING(Member::experienceSkillEnchanting, DyeColor.MAGENTA, SkyblockId("ENCHANTMENT_TABLE")),
|
ENCHANTING(Member::experienceSkillEnchanting, DyeColor.MAGENTA, SkyblockId("ENCHANTMENT_TABLE")),
|
||||||
;
|
;
|
||||||
|
|
||||||
fun getMaximumLevel(leveling: Leveling) = leveling.maximumLevels[name.lowercase()] ?: TODO("Repo error")
|
fun getMaximumLevel(leveling: Leveling) = assertNotNullOr(leveling.maximumLevels[name.lowercase()]) { 50 }
|
||||||
|
|
||||||
fun getLadder(leveling: Leveling): List<Int> {
|
fun getLadder(leveling: Leveling): List<Int> {
|
||||||
if (this == SOCIAL) return leveling.socialExperienceRequiredPerLevel
|
if (this == SOCIAL) return leveling.socialExperienceRequiredPerLevel
|
||||||
@@ -149,14 +150,14 @@ value class PetType(val name: String)
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Pet(
|
data class Pet(
|
||||||
val uuid: UUID?,
|
val uuid: UUID? = null,
|
||||||
val type: PetType,
|
val type: PetType,
|
||||||
val exp: Double,
|
val exp: Double = 0.0,
|
||||||
val active: Boolean,
|
val active: Boolean = false,
|
||||||
val tier: Rarity,
|
val tier: Rarity,
|
||||||
val candyUsed: Int,
|
val candyUsed: Int = 0,
|
||||||
val heldItem: String?,
|
val heldItem: String? = null,
|
||||||
val skin: String?,
|
val skin: String? = null,
|
||||||
) {
|
) {
|
||||||
val itemId get() = SkyblockId("${type.name};${tier.ordinal}")
|
val itemId get() = SkyblockId("${type.name};${tier.ordinal}")
|
||||||
}
|
}
|
||||||
@@ -184,7 +185,7 @@ data class PlayerData(
|
|||||||
val rankData get() = RepoManager.neuRepo.constants.misc.ranks[if (monthlyPackageRank == "NONE" || monthlyPackageRank == null) packageRank else monthlyPackageRank]
|
val rankData get() = RepoManager.neuRepo.constants.misc.ranks[if (monthlyPackageRank == "NONE" || monthlyPackageRank == null) packageRank else monthlyPackageRank]
|
||||||
fun getDisplayName(name: String = playerName) = rankData?.let {
|
fun getDisplayName(name: String = playerName) = rankData?.let {
|
||||||
("§${it.color}[${it.tag}${rankPlusDyeColor.modern}" +
|
("§${it.color}[${it.tag}${rankPlusDyeColor.modern}" +
|
||||||
"${it.plus ?: ""}§${it.color}] $name")
|
"${it.plus ?: ""}§${it.color}] $name")
|
||||||
} ?: "${Formatting.GRAY}$name"
|
} ?: "${Formatting.GRAY}$name"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ package moe.nea.firmament.apis
|
|||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.statement.*
|
import io.ktor.client.statement.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import java.time.Duration
|
|
||||||
import java.time.Instant
|
|
||||||
import java.util.*
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import net.minecraft.client.MinecraftClient
|
|
||||||
import moe.nea.firmament.Firmament
|
import moe.nea.firmament.Firmament
|
||||||
|
import net.minecraft.client.MinecraftClient
|
||||||
|
import java.time.Duration
|
||||||
|
import java.time.Instant
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
object UrsaManager {
|
object UrsaManager {
|
||||||
private data class Token(
|
private data class Token(
|
||||||
@@ -64,6 +64,9 @@ object UrsaManager {
|
|||||||
?: (Instant.now() + Duration.ofMinutes(55))
|
?: (Instant.now() + Duration.ofMinutes(55))
|
||||||
currentToken = Token(validUntil, savedToken, host)
|
currentToken = Token(validUntil, savedToken, host)
|
||||||
}
|
}
|
||||||
|
if (response.status.value != 200) {
|
||||||
|
Firmament.logger.error("Failed to contact ursa minor: ${response.bodyAsText()}")
|
||||||
|
}
|
||||||
return response
|
return response
|
||||||
} finally {
|
} finally {
|
||||||
if (didLock)
|
if (didLock)
|
||||||
|
|||||||
@@ -9,16 +9,15 @@ package moe.nea.firmament.gui.profileviewer
|
|||||||
import io.github.cottonmc.cotton.gui.client.CottonClientScreen
|
import io.github.cottonmc.cotton.gui.client.CottonClientScreen
|
||||||
import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription
|
import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription
|
||||||
import io.github.cottonmc.cotton.gui.widget.WTabPanel
|
import io.github.cottonmc.cotton.gui.widget.WTabPanel
|
||||||
import java.util.*
|
|
||||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import net.minecraft.text.Text
|
|
||||||
import moe.nea.firmament.Firmament
|
import moe.nea.firmament.Firmament
|
||||||
import moe.nea.firmament.apis.Member
|
import moe.nea.firmament.apis.Member
|
||||||
import moe.nea.firmament.apis.PlayerData
|
import moe.nea.firmament.apis.PlayerData
|
||||||
import moe.nea.firmament.apis.Profile
|
import moe.nea.firmament.apis.Profile
|
||||||
import moe.nea.firmament.apis.Routes
|
import moe.nea.firmament.apis.Routes
|
||||||
import moe.nea.firmament.util.ScreenUtil
|
import moe.nea.firmament.util.ScreenUtil
|
||||||
|
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
|
||||||
|
import net.minecraft.text.Text
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class ProfileViewer(
|
class ProfileViewer(
|
||||||
val primaryPlayer: UUID,
|
val primaryPlayer: UUID,
|
||||||
@@ -44,29 +43,32 @@ class ProfileViewer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun onCommand(source: FabricClientCommandSource, name: String) {
|
suspend fun onCommand(source: FabricClientCommandSource, name: String) {
|
||||||
source.sendFeedback(Text.translatable("firmament.pv.lookingup", name))
|
source.sendFeedback(Text.translatable("firmament.pv.lookingup", name))
|
||||||
Firmament.coroutineScope.launch {
|
try {
|
||||||
val uuid = Routes.getUUIDForPlayerName(name)
|
val uuid = Routes.getUUIDForPlayerName(name)
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
source.sendError(Text.translatable("firmament.pv.noplayer", name))
|
source.sendError(Text.translatable("firmament.pv.noplayer", name))
|
||||||
return@launch
|
return
|
||||||
}
|
}
|
||||||
val name = Routes.getPlayerNameForUUID(uuid) ?: name
|
val name = Routes.getPlayerNameForUUID(uuid) ?: name
|
||||||
val names = mapOf(uuid to (name))
|
val names = mapOf(uuid to (name))
|
||||||
val data = Routes.getAccountData(uuid)
|
val data = Routes.getAccountData(uuid)
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
source.sendError(Text.translatable("firmament.pv.noprofile", name))
|
source.sendError(Text.translatable("firmament.pv.noprofile", name))
|
||||||
return@launch
|
return
|
||||||
}
|
}
|
||||||
val accountData = mapOf(data.uuid to data)
|
val accountData = mapOf(data.uuid to data)
|
||||||
val profiles = Routes.getProfiles(uuid)
|
val profiles = Routes.getProfiles(uuid)
|
||||||
val profile = profiles?.profiles?.find { it.selected }
|
val profile = profiles?.profiles?.find { it.selected }
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
source.sendFeedback(Text.translatable("firmament.pv.noprofile", name))
|
source.sendFeedback(Text.translatable("firmament.pv.noprofile", name))
|
||||||
return@launch
|
return
|
||||||
}
|
}
|
||||||
ScreenUtil.setScreenLater(CottonClientScreen(ProfileViewer(uuid, names, accountData, profile)))
|
ScreenUtil.setScreenLater(CottonClientScreen(ProfileViewer(uuid, names, accountData, profile)))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Firmament.logger.error("Error loading profile data for $name", e)
|
||||||
|
source.sendError(Text.translatable("firmament.pv.badprofile", name, e.message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,11 @@ package moe.nea.firmament.util
|
|||||||
/**
|
/**
|
||||||
* Less aggressive version of `require(obj != null)`, which fails in devenv but continues at runtime.
|
* Less aggressive version of `require(obj != null)`, which fails in devenv but continues at runtime.
|
||||||
*/
|
*/
|
||||||
inline fun <T : Any> assertNotNullOr(obj: T?, block: () -> T): T {
|
inline fun <T : Any> assertNotNullOr(obj: T?, message: String? = null, block: () -> T): T {
|
||||||
assert(obj != null)
|
if (message == null)
|
||||||
|
assert(obj != null)
|
||||||
|
else
|
||||||
|
assert(obj != null) { message }
|
||||||
return obj ?: block()
|
return obj ?: block()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user