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.
The Adventure API version used by BetterHud.
The Adventure platform version.
BStats IDs
BStats metrics ID for Bukkit platform.
BStats metrics ID for Velocity platform.
Reload Operations
Basic Reload
ReloadState reload(ReloadFlagType... args)
Executes a plugin reload with the specified flags.
Reload configuration flags
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
Reload configuration flags
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.
Complete reload configuration and context
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 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.
Check Dev Version
Checks whether the current build is a development version.
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.
The bootstrap instance for platform-specific operations
Check Reload Status
Checks if the plugin is currently executing a reload.
true if a reload is in progress
Example:
if (!api.isOnReload()) {
// Safe to perform operations
}
Configuration
Merge BossBar Setting
Checks whether the plugin merges the first bossbar.
true if bossbar merging is enabled
Encoded Namespace
String getEncodedNamespace()
Returns the encoded namespace used internally.
The encoded namespace string
Default Font Key
Returns the default font key used by the plugin.
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.
The resource folder path within the plugin
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.
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.
The Unicode codepoint of the character
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.
The locale code (e.g., “en_US”, “ko_KR”)
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.
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