Overview | EssentialsC | LanguageApi
net.godlycow.org.essc.api

Interface LanguageApi

public interface LanguageApi

API interface for interacting with EssentialsC's language system. Messages are resolved per-sender using the following priority:

  1. The player's manually set language override (via /language set).
  2. The player's client locale as reported by Bukkit.
  3. The configured server default language.

Messages are returned as Adventure Components with MiniMessage formatting already applied. Placeholders in the raw message string are substituted before deserialization.

Retrieve an instance via EssentialsCAPI.getLanguageApi().

LanguageApi lang = APIProvider.getAPI().getLanguageApi();

// resolve a message with placeholders
Component msg = lang.get(player, "home.teleport.success",
        Map.of("name", "base"));
player.sendMessage(msg);

// resolve a message with no placeholders
Component header = lang.get(player, "kit.list.header");

Method Summary

Component get(CommandSender sender, String key, Map<String,String> placeholders)
Resolves the message for the given key with placeholder substitution.
Component get(CommandSender sender, String key)
Resolves the message for the given key with no placeholder substitution.
void setPlayerLanguage(UUID playerUuid, String languageCode)
Sets a manual language override for the given player.
void removePlayerLanguage(UUID playerUuid)
Removes the manual language override for the given player.
String getPlayerLanguage(UUID playerUuid)
Returns the manually set language code for the given player, or null.
boolean hasPlayerLanguage(UUID playerUuid)
Returns whether the given player has a manual language override set.
Map<UUID,String> getPlayerLanguages()
Returns a snapshot of all currently active player language overrides.
String getDefaultLanguage()
Returns the server's configured default language code.
Method Detail
public Component get(CommandSender sender, String key, Map<String, String> placeholders)

Resolves the message for the given key in the sender's active language, substituting the provided placeholders.

Placeholders are applied by replacing <key> tokens in the raw message string before MiniMessage deserialization. For example, a placeholder entry of "name" -> "base" replaces all occurrences of <name> in the raw string.

If the key is not found in the sender's language, the default language is tried as a fallback. If still not found, an error component is returned.

Parameters:
senderthe sender whose language preference is used for resolution; must not be null
keythe message key to look up (e.g. "home.teleport.success"); must not be null
placeholdersa map of placeholder names to replacement values, or null if there are no placeholders
Returns:
Componentthe resolved Component; never null
public Component get(CommandSender sender, String key)

Resolves the message for the given key in the sender's active language with no placeholder substitution.

Equivalent to get(sender, key, null).

Parameters:
senderthe sender whose language preference is used for resolution; must not be null
keythe message key to look up; must not be null
Returns:
Componentthe resolved Component; never null
public void setPlayerLanguage(UUID playerUuid, String languageCode)

Sets a manual language override for the given player. Once set, this language takes precedence over the player's client locale. If the language file for the given code has not yet been loaded it is loaded into the cache immediately.

Parameters:
playerUuidthe UUID of the player; must not be null
languageCodethe language code to set (e.g. "de_DE"); must not be null
public void removePlayerLanguage(UUID playerUuid)

Removes the manual language override for the given player, returning them to automatic locale detection. Has no effect if the player has no override set.

Parameters:
playerUuidthe UUID of the player; must not be null
public String getPlayerLanguage(UUID playerUuid)

Returns the manually set language code for the given player, or null if no override has been set. A null return means the player's message resolution falls back to their client locale and then the server default.

Parameters:
playerUuidthe UUID of the player; must not be null
Returns:
Stringthe language code, or null if no override is set
public boolean hasPlayerLanguage(UUID playerUuid)

Returns whether the given player has a manual language override set. Equivalent to getPlayerLanguage(playerUuid) != null.

Parameters:
playerUuidthe UUID of the player; must not be null
Returns:
booleantrue if the player has a language override
public Map<UUID, String> getPlayerLanguages()

Returns a snapshot of all currently active manual player language overrides. The returned map is a copy — modifications have no effect on the internal state.

Returns:
Map<UUID, String>a map of player UUID to language code; never null, may be empty
public String getDefaultLanguage()

Returns the server's configured default language code. This is used as the final fallback when neither a player override nor a matching client locale file is available.

Returns:
Stringthe default language code (e.g. "en_US"); never null