Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion velocity/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Loading