diff options
author | nea <nea@nea.moe> | 2023-06-02 02:32:02 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-06-02 02:32:02 +0200 |
commit | 3d76538cef0cb150415ef5db734c80fb0dec7e85 (patch) | |
tree | 1fdeaf1f42e4a34d6637c3c74e9993ffcf8e4064 /src/main/kotlin/moe/nea/firmament/gui/profileviewer | |
parent | b61476608ec00642c5dc27cbfe02b4acf26c18d2 (diff) | |
download | firmament-3d76538cef0cb150415ef5db734c80fb0dec7e85.tar.gz firmament-3d76538cef0cb150415ef5db734c80fb0dec7e85.tar.bz2 firmament-3d76538cef0cb150415ef5db734c80fb0dec7e85.zip |
Display rank alongside name
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/gui/profileviewer')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt | 59 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt | 12 |
2 files changed, 70 insertions, 1 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 d3612e5..63cb5a8 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt @@ -1,19 +1,36 @@ 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.util.ScreenUtil class ProfileViewer( val primaryPlayer: UUID, val playerNames: Map<UUID, String>, + val accountData: Map<UUID, PlayerData>, val profile: Profile, ) : LightweightGuiDescription() { val member: Member = profile.members[primaryPlayer] ?: error("Primary player not in profile") val primaryName: String = playerNames[primaryPlayer] ?: error("Primary player has no name") + val account: PlayerData = accountData[primaryPlayer] ?: error("Primary player has no data") init { val panel = WTabPanel().also { rootPanel = it } @@ -26,6 +43,48 @@ class ProfileViewer( } } } + + companion object { + 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 } + if (profile == null) { + source.sendFeedback(Text.translatable("firmament.pv.noprofile", name)) + return@launch + } + ScreenUtil.setScreenLater( + CottonClientScreen( + ProfileViewer( + playerUuid, names, accountData, profile + ) + ) + ) + } + } + } } diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt index 8f0693f..d189b5b 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt @@ -10,6 +10,7 @@ import io.github.cottonmc.cotton.gui.widget.icon.ItemIcon import net.minecraft.item.ItemStack import net.minecraft.item.Items import net.minecraft.text.Text +import net.minecraft.util.Formatting import moe.nea.firmament.apis.Skill import moe.nea.firmament.gui.WBar import moe.nea.firmament.repo.RepoManager @@ -19,7 +20,16 @@ object SkillPage : ProfilePage { override fun getElements(profileViewer: ProfileViewer): WWidget { return WGridPanel().also { it.insets = Insets.ROOT_PANEL - it.add(WText(Text.literal(profileViewer.primaryName /* with rank? */)), 0, 0, 6, 1) + it.add( + WText( + Text.literal( + profileViewer.account.rankData?.let { + ("§${it.color}[${it.tag}${profileViewer.account.rankPlusDyeColor.modern}" + + "${it.plus ?: ""}§${it.color}] ${profileViewer.primaryName}") + } ?: "§${Formatting.GRAY}${profileViewer.primaryName}" + ) + ), 0, 0, 6, 1 + ) for ((i, skill) in Skill.values().withIndex()) { val leveling = RepoManager.neuRepo.constants.leveling val exp = skill.accessor.get(profileViewer.member) |