aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/gui/profileviewer
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-08-31 18:19:06 +0200
committernea <nea@nea.moe>2023-08-31 18:19:06 +0200
commitb7b01f1c6fbf889ae9bfcdb5b34c5ccfa48d5ba0 (patch)
tree535b601405763736109be9ff281a71c06155b52f /src/main/kotlin/moe/nea/firmament/gui/profileviewer
parentba72aedf7fb98c1ec72a8745402f577fb0024508 (diff)
downloadfirmament-b7b01f1c6fbf889ae9bfcdb5b34c5ccfa48d5ba0.tar.gz
firmament-b7b01f1c6fbf889ae9bfcdb5b34c5ccfa48d5ba0.tar.bz2
firmament-b7b01f1c6fbf889ae9bfcdb5b34c5ccfa48d5ba0.zip
Fix profile viewer for missing uuid pets
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/gui/profileviewer')
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt
index 5561476..e811663 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt
@@ -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.LightweightGuiDescription
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.apis.Member
import moe.nea.firmament.apis.PlayerData
import moe.nea.firmament.apis.Profile
import moe.nea.firmament.apis.Routes
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(
val primaryPlayer: UUID,
@@ -44,29 +43,32 @@ class ProfileViewer(
}
companion object {
- fun onCommand(source: FabricClientCommandSource, name: String) {
+ suspend fun onCommand(source: FabricClientCommandSource, name: String) {
source.sendFeedback(Text.translatable("firmament.pv.lookingup", name))
- Firmament.coroutineScope.launch {
+ try {
val uuid = Routes.getUUIDForPlayerName(name)
if (uuid == null) {
source.sendError(Text.translatable("firmament.pv.noplayer", name))
- return@launch
+ return
}
val name = Routes.getPlayerNameForUUID(uuid) ?: name
val names = mapOf(uuid to (name))
val data = Routes.getAccountData(uuid)
if (data == null) {
source.sendError(Text.translatable("firmament.pv.noprofile", name))
- return@launch
+ return
}
val accountData = mapOf(data.uuid to data)
val profiles = Routes.getProfiles(uuid)
val profile = profiles?.profiles?.find { it.selected }
if (profile == null) {
source.sendFeedback(Text.translatable("firmament.pv.noprofile", name))
- return@launch
+ return
}
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))
}
}
}