Skip to main content

Overview

The BetterHud interface is the main API entry point for interacting with the BetterHud plugin. It provides access to all managers, configuration, reload functionality, and core plugin operations.

Getting Instance

Static Method

BetterHud api = BetterHud.getInstance();

Using BetterHudAPI

BetterHud api = BetterHudAPI.inst();

Constants

Namespace and Versions

DEFAULT_NAMESPACE
String
default:"betterhud"
The default namespace used throughout the plugin.
ADVENTURE_VERSION
String
default:"4.26.1"
The Adventure API version used by BetterHud.
PLATFORM_VERSION
String
default:"4.4.1"
The Adventure platform version.
EXAMINATION_VERSION
String
default:"1.3.0"
The Examination version.

BStats IDs

BSTATS_ID_BUKKIT
int
default:"21287"
BStats metrics ID for Bukkit platform.
BSTATS_ID_VELOCITY
int
default:"23460"
BStats metrics ID for Velocity platform.

Reload Operations

Basic Reload

ReloadState reload(ReloadFlagType... args)
Executes a plugin reload with the specified flags.
args
ReloadFlagType...
Reload configuration flags
return
ReloadState
The result of the reload operation
Example:
BetterHud api = BetterHud.getInstance();
ReloadState state = api.reload();
if (state == ReloadState.SUCCESS) {
    // Reload successful
}

Reload with Sender

ReloadState reload(BetterCommandSource sender, ReloadFlagType... args)
Executes a reload with a specific command source for logging.
sender
BetterCommandSource
required
The command source that receives reload logs
args
ReloadFlagType...
Reload configuration flags
return
ReloadState
The result of the reload operation
Example:
ReloadState state = api.reload(player, ReloadFlagType.FULL);

Advanced Reload

ReloadState reload(ReloadInfo info)
Executes a reload with detailed reload information.
info
ReloadInfo
required
Complete reload configuration and context
return
ReloadState
The result of the reload operation

Manager Access

All manager getters return non-null instances.

PlaceholderManager

PlaceholderManager getPlaceholderManager()
Accesses the placeholder management system. Example:
PlaceholderManager manager = api.getPlaceholderManager();
PlaceholderContainer<Number> numbers = manager.getNumberContainer();

ListenerManager

ListenerManager getListenerManager()
Manages custom HUD listeners. Example:
ListenerManager manager = api.getListenerManager();
manager.addListener("custom_listener", yamlObject -> updateEvent -> {
    // Custom listener logic
    return new MyHudListener();
});

PopupManager

PopupManager getPopupManager()
Manages popup displays. Example:
PopupManager manager = api.getPopupManager();
Popup popup = manager.getPopup("welcome_message");

ConfigManager

ConfigManager getConfigManager()
Accesses plugin configuration. Example:
ConfigManager config = api.getConfigManager();
int bossbarLines = config.getBossbarLine();
boolean debug = config.debug();

CompassManager

CompassManager getCompassManager()
Manages compass HUD elements. Example:
CompassManager manager = api.getCompassManager();
Compass compass = manager.getCompass("main_compass");

TriggerManager

TriggerManager getTriggerManager()
Manages HUD triggers. Example:
TriggerManager manager = api.getTriggerManager();
manager.addTrigger("on_damage", yamlObject -> {
    // Custom trigger logic
    return new MyHudTrigger();
});

HudManager

HudManager getHudManager()
Manages HUD displays. Example:
HudManager manager = api.getHudManager();
Hud hud = manager.getHud("health_bar");
Set<String> allHuds = manager.getAllNames();

DatabaseManager

DatabaseManager getDatabaseManager()
Manages database connections and operations. Example:
DatabaseManager manager = api.getDatabaseManager();
HudDatabase database = manager.getCurrentDatabase();

ShaderManager

ShaderManager getShaderManager()
Manages shader customization. Example:
ShaderManager manager = api.getShaderManager();
manager.addConstant("MY_CONSTANT", "1.0");

PlayerManager

PlayerManager getPlayerManager()
Manages HUD player instances. Example:
PlayerManager manager = api.getPlayerManager();
HudPlayer hudPlayer = manager.getHudPlayer(playerUUID);

TextManager

TextManager getTextManager()
Manages text rendering and formatting.

Plugin Information

Check Dev Version

boolean isDevVersion()
Checks whether the current build is a development version.
return
boolean
true if this is a development build
Example:
if (api.isDevVersion()) {
    logger.info("Running development version");
}

Get Bootstrap

BetterHudBootstrap bootstrap()
Gets the platform bootstrap instance.
return
BetterHudBootstrap
The bootstrap instance for platform-specific operations

Check Reload Status

boolean isOnReload()
Checks if the plugin is currently executing a reload.
return
boolean
true if a reload is in progress
Example:
if (!api.isOnReload()) {
    // Safe to perform operations
}

Configuration

Merge BossBar Setting

boolean isMergeBossBar()
Checks whether the plugin merges the first bossbar.
return
boolean
true if bossbar merging is enabled

Encoded Namespace

String getEncodedNamespace()
Returns the encoded namespace used internally.
return
String
The encoded namespace string

Default Font Key

Key getDefaultKey()
Returns the default font key used by the plugin.
return
Key
The Adventure Key for the default font
Example:
Key defaultFont = api.getDefaultKey();
Component text = Component.text("Hello").font(defaultFont);

Asset Management

Load Assets to Directory

void loadAssets(String prefix, File dir)
Loads plugin resources to a target directory.
prefix
String
required
The resource folder path within the plugin
dir
File
required
The target directory to extract resources to
Example:
File customDir = new File("plugins/BetterHud/custom");
api.loadAssets("assets/textures", customDir);

Load Assets with Consumer

void loadAssets(String prefix, BiConsumer<String, InputStream> consumer)
Loads plugin resources and processes each file with a consumer.
prefix
String
required
The resource folder path within the plugin
consumer
BiConsumer<String, InputStream>
required
Callback that receives filename and input stream for each asset
Example:
api.loadAssets("assets/sounds", (filename, stream) -> {
    System.out.println("Processing: " + filename);
    // Process the stream
});

Font Utilities

Get Character Width

int getWidth(int codepoint)
Gets the width of a character in the default font.
codepoint
int
required
The Unicode codepoint of the character
return
int
The width in pixels
Example:
int width = api.getWidth('A');
int unicodeWidth = api.getWidth(0x1F600); // Emoji

Translation

Translate Key

String translate(String locale, String key)
Gets a translated string for a specific locale.
locale
String
required
The locale code (e.g., “en_US”, “ko_KR”)
key
String
required
The translation key
return
String
The translated value, or null if not found
Example:
String message = api.translate("en_US", "ui.welcome");
if (message != null) {
    player.sendMessage(message);
}

Reload Tasks

Add Reload Start Task

void addReloadStartTask(Runnable runnable)
Registers a task to run when reload begins.
runnable
Runnable
required
The task to execute at reload start
Example:
api.addReloadStartTask(() -> {
    System.out.println("Reload starting...");
    // Clear caches, prepare for reload
});

Add Reload End Task

void addReloadEndTask(Consumer<ReloadState> runnable)
Registers a task to run when reload completes.
runnable
Consumer<ReloadState>
required
The task to execute at reload end, receives the reload state
Example:
api.addReloadEndTask(state -> {
    if (state == ReloadState.SUCCESS) {
        System.out.println("Reload completed successfully");
    } else {
        System.out.println("Reload failed: " + state);
    }
});

Complete Example

import kr.toxicity.hud.api.BetterHud;
import kr.toxicity.hud.api.BetterHudAPI;
import kr.toxicity.hud.api.manager.*;
import kr.toxicity.hud.api.player.HudPlayer;
import kr.toxicity.hud.api.popup.Popup;

public class BetterHudExample {
    
    public void example() {
        // Get API instance
        BetterHud api = BetterHudAPI.inst();
        
        // Check version info
        if (api.isDevVersion()) {
            System.out.println("Running dev version");
        }
        
        // Access managers
        PlayerManager playerManager = api.getPlayerManager();
        PopupManager popupManager = api.getPopupManager();
        HudManager hudManager = api.getHudManager();
        
        // Get player data
        HudPlayer hudPlayer = playerManager.getHudPlayer(playerUUID);
        if (hudPlayer != null) {
            hudPlayer.setHudEnabled(true);
        }
        
        // Show popup to player
        Popup welcomePopup = popupManager.getPopup("welcome");
        
        // Get font width
        int width = api.getWidth('W');
        
        // Translation
        String message = api.translate("en_US", "hud.health");
        
        // Add reload callbacks
        api.addReloadStartTask(() -> {
            System.out.println("Starting reload...");
        });
        
        api.addReloadEndTask(state -> {
            System.out.println("Reload finished: " + state);
        });
        
        // Trigger reload
        if (!api.isOnReload()) {
            ReloadState result = api.reload();
        }
    }
}

See Also

Build docs developers (and LLMs) love