Skip to content

Dynamic Content

Hudkit supports dynamic content through placeholder resolution and visibility controls, allowing you to display player-specific information and show/hide HUD elements programmatically.

Create custom placeholder resolvers by extending the abstract PlaceholderResolver class. This allows you to define what happens when a placeholder is referenced in your HUD definition.

import net.hudkit.api.document.placeholder.PlaceholderResolver
import net.kyori.adventure.audience.Audience
import net.kyori.adventure.text.Component
import net.minestom.server.entity.Player
class MyPlaceholderResolver : PlaceholderResolver() {
override fun resolve(placeholder: String, audience: Audience): Component {
return when (placeholder) {
"player_name" -> (audience as Player).name
"player_level" -> Component.text((audience as Player).level)
"player_health" -> Component.text(String.format("%.1f", (audience as Player).health))
"server_online" -> Component.text(MinecraftServer.getConnectionManager().onlinePlayers.size)
else -> Component.text("?")
}
}
}
val manager = HudManager(
studioOptions = StudioOptions.online("your-api-key"),
renderOptions = RenderOptions.customPlaceholderResolver(MyPlaceholderResolver())
)

You can dynamically show and hide HUD elements using the show() and hide() methods on a Hud instance. Elements are identified by their key, which you define in Studio or the XML.

// Get the player's HUD instance
val hud = hudManager.getHud(player)
hud?.hide("health_bar")
// Show a previously hidden element
hud?.show("health_bar")

When you hide an element, all its children (including nested elements) are also hidden. This also goes the other way, as showing an element only affects that specific key, if a parent element is still hidden, children remain hidden.

When placeholder values change and you want the HUD to update:

// Force all HUDs to re-render
hudManager.rerenderAllHuds()
// Re-render a specific player's HUD
hudManager.getHud(player)?.rerender()
  • Keep placeholder resolve() functions FAST!
  • Cache expensive computations when possible
  • Avoid blocking operations or database calls in resolve()