From 7eb0d58a80f215f21f87afd959238f488c9078cf Mon Sep 17 00:00:00 2001 From: Lukas Jost Date: Fri, 27 Nov 2026 20:00:13 +0100 Subject: [PATCH] feat: expose system badge readiness on the proxy --- .../proxy/api/PlayerSystemBadgeQuery.kt | 8 +++++ velocity/build.gradle.kts | 2 +- .../presentation/VelocitySystemMessages.kt | 35 +++++++++++++------ 3 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 api/src/main/kotlin/gg/grounds/proxy/api/PlayerSystemBadgeQuery.kt diff --git a/api/src/main/kotlin/gg/grounds/proxy/api/PlayerSystemBadgeQuery.kt b/api/src/main/kotlin/gg/grounds/proxy/api/PlayerSystemBadgeQuery.kt new file mode 100644 index 0000000..e08d37b --- /dev/null +++ b/api/src/main/kotlin/gg/grounds/proxy/api/PlayerSystemBadgeQuery.kt @@ -0,0 +1,8 @@ +package gg.grounds.proxy.api + +import java.util.UUID + +/** Reports readiness for the system-badge font on this recipient's current Java session. */ +fun interface PlayerSystemBadgeQuery { + fun systemBadgesReady(playerId: UUID): Boolean +} diff --git a/velocity/build.gradle.kts b/velocity/build.gradle.kts index c01d136..e18c5a7 100644 --- a/velocity/build.gradle.kts +++ b/velocity/build.gradle.kts @@ -20,7 +20,7 @@ dependencies { implementation("com.google.code.gson:gson:2.15.0") // The tab list header and footer are player-facing text, so they come from a bundle and are // drawn in the design tokens, like every other line the network shows a player. - implementation("gg.grounds:library-i18n:0.4.4") + implementation("gg.grounds:library-i18n:0.5.0") implementation("io.nats:jnats:2.26.4") // The metrics endpoint. Micrometer rather than a hand-written exposition format, because its diff --git a/velocity/src/main/kotlin/gg/grounds/presentation/VelocitySystemMessages.kt b/velocity/src/main/kotlin/gg/grounds/presentation/VelocitySystemMessages.kt index f7b4d16..f6eaa04 100644 --- a/velocity/src/main/kotlin/gg/grounds/presentation/VelocitySystemMessages.kt +++ b/velocity/src/main/kotlin/gg/grounds/presentation/VelocitySystemMessages.kt @@ -2,20 +2,35 @@ package gg.grounds.presentation import com.velocitypowered.api.proxy.Player import gg.grounds.i18n.SystemMessageRenderer +import gg.grounds.i18n.SystemPrefixStyle import gg.grounds.proxy.api.PlayerChatAppearanceQuery +import gg.grounds.proxy.api.PlayerSystemBadgeQuery import gg.grounds.proxy.api.ProxyServiceRegistry +import java.util.UUID -/** Resolve readiness at delivery time: plugins never cache a player's pack state. */ +/** Resolves the current recipient's pack capabilities at delivery time. */ internal object VelocitySystemMessages { val renderer = - SystemMessageRenderer.withLogoReadiness { audience -> - val player = audience as? Player - player != null && - runCatching { - ProxyServiceRegistry.get(PlayerChatAppearanceQuery::class.java) - ?.appearanceOf(player.uniqueId) - ?.chatFontReady == true - } - .getOrDefault(false) + SystemMessageRenderer.withPrefixStyle { audience -> + runCatching { (audience as? Player)?.uniqueId?.let(::prefixStyle) }.getOrNull() + ?: SystemPrefixStyle.TEXT } + + fun prefixStyle(playerId: UUID): SystemPrefixStyle { + val badgeReady = + runCatching { + ProxyServiceRegistry.get(PlayerSystemBadgeQuery::class.java) + ?.systemBadgesReady(playerId) == true + } + .getOrDefault(false) + if (badgeReady) return SystemPrefixStyle.BADGE + val logoReady = + runCatching { + ProxyServiceRegistry.get(PlayerChatAppearanceQuery::class.java) + ?.appearanceOf(playerId) + ?.chatFontReady == true + } + .getOrDefault(false) + return if (logoReady) SystemPrefixStyle.LOGO else SystemPrefixStyle.TEXT + } }