aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-06-02 02:32:02 +0200
committernea <nea@nea.moe>2023-06-02 02:32:02 +0200
commit3d76538cef0cb150415ef5db734c80fb0dec7e85 (patch)
tree1fdeaf1f42e4a34d6637c3c74e9993ffcf8e4064
parentb61476608ec00642c5dc27cbfe02b4acf26c18d2 (diff)
downloadfirmament-3d76538cef0cb150415ef5db734c80fb0dec7e85.tar.gz
firmament-3d76538cef0cb150415ef5db734c80fb0dec7e85.tar.bz2
firmament-3d76538cef0cb150415ef5db734c80fb0dec7e85.zip
Display rank alongside name
-rw-r--r--build.gradle.kts2
-rw-r--r--gradle/libs.versions.toml2
-rw-r--r--src/main/kotlin/moe/nea/firmament/apis/Profiles.kt32
-rw-r--r--src/main/kotlin/moe/nea/firmament/commands/rome.kt22
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewer.kt59
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt12
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/LegacyFormattingCode.kt31
7 files changed, 135 insertions, 25 deletions
diff --git a/build.gradle.kts b/build.gradle.kts
index 83dd139..a5a28d3 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -9,7 +9,7 @@ plugins {
id("dev.architectury.loom") version "1.1.336"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("moe.nea.licenseextractificator")
- id("io.github.juuxel.loom-quiltflower") version "1.7.3"
+ id("io.github.juuxel.loom-quiltflower") version "1.10.0"
}
java {
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 0e6a970..b1187bf 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -11,7 +11,7 @@ modmenu = "6.2.1"
ktor = "2.3.0"
dbus_java = "4.2.1"
architectury = "8.1.79"
-neurepoparser = "1.1.0"
+neurepoparser = "1.2.0"
qolify = "1.2.2-1.19.4"
citresewn = "1.1.3+1.19.4"
lib39 = "1.4.2"
diff --git a/src/main/kotlin/moe/nea/firmament/apis/Profiles.kt b/src/main/kotlin/moe/nea/firmament/apis/Profiles.kt
index b05d2fc..3e6b2cb 100644
--- a/src/main/kotlin/moe/nea/firmament/apis/Profiles.kt
+++ b/src/main/kotlin/moe/nea/firmament/apis/Profiles.kt
@@ -11,6 +11,8 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
import kotlin.reflect.KProperty1
import net.minecraft.util.DyeColor
+import moe.nea.firmament.repo.RepoManager
+import moe.nea.firmament.util.LegacyFormattingCode
import moe.nea.firmament.util.json.DashlessUUIDSerializer
import moe.nea.firmament.util.json.InstantAsLongSerializer
@@ -105,5 +107,33 @@ data class Pet(
val candyUsed: Int,
val heldItem: String?,
val skin: String?,
+)
+
+@Serializable
+data class PlayerResponse(
+ val success: Boolean,
+ val player: PlayerData,
+)
- )
+@Serializable
+data class PlayerData(
+ val uuid: UUID,
+ val firstLogin: Instant,
+ val lastLogin: Instant,
+ @SerialName("playername")
+ val playerName: String,
+ val achievementsOneTime: List<String> = listOf(),
+ @SerialName("newPackageRank")
+ val packageRank: String?,
+ val monthlyPackageRank: String? = null,
+ val rankPlusColor: String = "GOLD"
+) {
+ val rankPlusDyeColor = LegacyFormattingCode.values().find { it.name == rankPlusColor } ?: LegacyFormattingCode.GOLD
+ val rankData get() = RepoManager.neuRepo.constants.misc.ranks[monthlyPackageRank ?: packageRank]
+}
+
+@Serializable
+data class AshconNameLookup(
+ val username: String,
+ val uuid: UUID,
+)
diff --git a/src/main/kotlin/moe/nea/firmament/commands/rome.kt b/src/main/kotlin/moe/nea/firmament/commands/rome.kt
index 56ab84d..2d70df0 100644
--- a/src/main/kotlin/moe/nea/firmament/commands/rome.kt
+++ b/src/main/kotlin/moe/nea/firmament/commands/rome.kt
@@ -66,27 +66,7 @@ fun firmamentCommand() = literal("firmament") {
}
thenLiteral("pv") {
thenExecute {
- val me = MC.player!!.uuid
- val name = MC.player!!.name.unformattedString
- val names = mapOf(me to name)
- source.sendFeedback(Text.translatable("firmament.pv.lookingup", name))
- Firmament.coroutineScope.launch {
- val profiles = Firmament.httpClient.get {
- url {
- protocol = URLProtocol.HTTPS
- host = "api.hypixel.net"
- path("skyblock", "profiles")
- parameter("key", "06b68418-71eb-4c2a-bb8a-65ed8bd4d5aa")
- parameter("uuid", me.toString())
- }
- }.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(me, names, profile)))
- }
+ ProfileViewer.onCommand(source, MC.player!!.name.unformattedString)
}
}
thenLiteral("price") {
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)
diff --git a/src/main/kotlin/moe/nea/firmament/util/LegacyFormattingCode.kt b/src/main/kotlin/moe/nea/firmament/util/LegacyFormattingCode.kt
new file mode 100644
index 0000000..f93c274
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/util/LegacyFormattingCode.kt
@@ -0,0 +1,31 @@
+package moe.nea.firmament.util
+
+import net.minecraft.util.Formatting
+
+enum class LegacyFormattingCode(val label: String, val char: Char, val index: Int) {
+ BLACK("BLACK", '0', 0),
+ DARK_BLUE("DARK_BLUE", '1', 1),
+ DARK_GREEN("DARK_GREEN", '2', 2),
+ DARK_AQUA("DARK_AQUA", '3', 3),
+ DARK_RED("DARK_RED", '4', 4),
+ DARK_PURPLE("DARK_PURPLE", '5', 5),
+ GOLD("GOLD", '6', 6),
+ GRAY("GRAY", '7', 7),
+ DARK_GRAY("DARK_GRAY", '8', 8),
+ BLUE("BLUE", '9', 9),
+ GREEN("GREEN", 'a', 10),
+ AQUA("AQUA", 'b', 11),
+ RED("RED", 'c', 12),
+ LIGHT_PURPLE("LIGHT_PURPLE", 'd', 13),
+ YELLOW("YELLOW", 'e', 14),
+ WHITE("WHITE", 'f', 15),
+ OBFUSCATED("OBFUSCATED", 'k', -1),
+ BOLD("BOLD", 'l', -1),
+ STRIKETHROUGH("STRIKETHROUGH", 'm', -1),
+ UNDERLINE("UNDERLINE", 'n', -1),
+ ITALIC("ITALIC", 'o', -1),
+ RESET("RESET", 'r', -1);
+
+ val modern = Formatting.byCode(char)!!
+
+}