diff options
author | nea <nea@nea.moe> | 2023-06-02 23:01:09 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-06-02 23:01:09 +0200 |
commit | f2eb8c4dc898336f1ee44e62e18b4a7406464736 (patch) | |
tree | 50af6c0e91306e2d5882b8407ff2028d91863585 /src/main/kotlin/moe/nea/firmament/gui | |
parent | f249df8f67114b14e3d75a955ace1d28ba6cb937 (diff) | |
download | firmament-f2eb8c4dc898336f1ee44e62e18b4a7406464736.tar.gz firmament-f2eb8c4dc898336f1ee44e62e18b4a7406464736.tar.bz2 firmament-f2eb8c4dc898336f1ee44e62e18b4a7406464736.zip |
Add more caching and fix some models
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/gui')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt | 54 |
1 files changed, 16 insertions, 38 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 63cb5a8..98e9489 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt @@ -3,22 +3,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 io.ktor.client.call.body -import io.ktor.client.request.get -import io.ktor.client.request.parameter -import io.ktor.http.URLProtocol -import io.ktor.http.path import java.util.UUID 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.AshconNameLookup import moe.nea.firmament.apis.Member import moe.nea.firmament.apis.PlayerData -import moe.nea.firmament.apis.PlayerResponse import moe.nea.firmament.apis.Profile -import moe.nea.firmament.apis.Profiles +import moe.nea.firmament.apis.Routes import moe.nea.firmament.util.ScreenUtil class ProfileViewer( @@ -48,40 +41,25 @@ class ProfileViewer( fun onCommand(source: FabricClientCommandSource, name: String) { source.sendFeedback(Text.translatable("firmament.pv.lookingup", name)) Firmament.coroutineScope.launch { - val nameData = Firmament.httpClient.get("https://api.ashcon.app/mojang/v2/user/$name").body<AshconNameLookup>() - val names = mapOf(nameData.uuid to nameData.username) - val data = Firmament.httpClient.get { - url { - protocol = URLProtocol.HTTPS - host = "api.hypixel.net" - path("player") - parameter("key", "e721a103-96e0-400f-af2a-73b2a91007b1") - parameter("uuid", nameData.uuid) - } - }.body<PlayerResponse>() - val accountData = mapOf(data.player.uuid to data.player) - val playerUuid = data.player.uuid - val profiles = Firmament.httpClient.get { - url { - protocol = URLProtocol.HTTPS - host = "api.hypixel.net" - path("skyblock", "profiles") - parameter("key", "e721a103-96e0-400f-af2a-73b2a91007b1") - parameter("uuid", playerUuid) - } - }.body<Profiles>() - val profile = profiles.profiles.find { it.selected } + val uuid = Routes.getUUIDForPlayerName(name) + if (uuid == null) { + source.sendError(Text.translatable("firmament.pv.noplayer", name)) + return@launch + } + val names = mapOf(uuid to (Routes.getPlayerNameForUUID(uuid) ?: name)) + val data = Routes.getAccountData(uuid) + if (data == null) { + source.sendError(Text.translatable("firmament.pv.nohypixel", name)) + return@launch + } + 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 } - ScreenUtil.setScreenLater( - CottonClientScreen( - ProfileViewer( - playerUuid, names, accountData, profile - ) - ) - ) + ScreenUtil.setScreenLater(CottonClientScreen(ProfileViewer(uuid, names, accountData, profile))) } } } |