-
Notifications
You must be signed in to change notification settings - Fork 16
Retrieve object names
As of version 1.6, you can get the accurate English name of any Minecraft object for which you have the key. For example, to convert Material.LAPIS_LAZULI into the text "Lapis Lazuli" in code:
String key = localeManager.queryMaterial(Material.LAPIS_LAZULI);
String englishName = "";
try {
englishName = localeManager.toServerLocale(key);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
Although the 1.13 update of Minecraft made it easier to get accurate names for items (and other game objects), the current methods of doing this through the Bukkit API do not always return consistent results and would require additional coding on your part. On pre-1.13 Minecraft, it is especially difficult, as variations of items would require you to code item-specific edge cases. For example, trying to get the name of Material.LAPIS_LAZULI would return "Ink Sac" on pre-1.13 unless you specify a durability value of 4. These edge cases are what ultimately spelled the doom of the immensely popular Vault plugin's dead Item API.
You could, but retrieving object names through this LocaleLib method will work on Bukkit, Spigot and Paper servers. While Paper does offer a functionally identical method to this, it will only work on servers running Paper software.
While LocaleLib is able to force the client to translate objects into any language, getting that result back from the client is not currently possible. Retrieving object names is only possible because all official Minecraft server jars contain an English localization file. Until the creators of Minecraft opt to include other language files within the jar, we are limited to English-only.