HomeJavaModsPlayerLangAPI | Simple translation identifiers [1.13+]
ModsJava

PlayerLangAPI | Simple translation identifiers [1.13+]

⬇ Download on Spigot
What is PlayerLangAPI ?

PlayerLangAPI is a library allowing developers to use client-side translations through the use of translation keys(block.minecraft.stone is the identifier of the stone).


For example, we can give a diamond sword with the name ItemStack "stone". Thus, when the player's client language is set to "English", the player will not see the same name if the game language is set to a different language (or if he uses a resourcepack).
This plugin is compatible with 1.13+ versions (until Mojang changes languages format)


Why use this library?

Usually several plugins use stored object names without taking into account the client's translation or the object name is fixed and if the client changes language, he will always see the old name.

This plugin in the form of a library gives you the possibility to use the languages used by the client. However, you will have to master the "TranslatableComponent" (see https://www.spigotmc.org/wiki/the-chat-component-api/#basics )


How use it ?

Maven repository

Code (Text):
<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Maven dependency

Code (Text):
<dependency>
    <groupId>com.github.Yovach</groupId>
    <artifactId>PlayerLangAPI</artifactId>
    <version>0.4</version>
</dependency>

Plugins folder

Place the plugin (.jar) in "./plugins/" folder


Usage

First example :
If you want to send the name of the stone sword according to the player's language :

Spoiler: FIRST EXAMPLE
Code (Java):
        final TranslatableComponent component = new TranslatableComponent ( MaterialLang. STONE_SWORD . getTranslation ( ) ) ;
        player. sendMessage ( component ) ;
This will send "Stone sword" for a player whose language of play is English and "Espada de piedre" for a Spanish player.


Second example :
A translatable component into a sentence :
Spoiler: SECOND EXAMPLE
Code (Text):
/* Our text component (a sentence for example) */
final TextComponent text = new TextComponent("Please use your ");

/* Our component which will be translated by client */
final TranslatableComponent translatableDiamond = new TranslatableComponent(MaterialLang.DIAMOND.getTranslation());

text.addExtra(translatableDiamond);

/* We can put a color on the translated component :) */
translatableDiamond.setColor(net.md_5.bungee.api.ChatColor.GOLD);


player.sendMessage(text);


Third example :
Retrieve a class from the API (EnchantmentLang -> Enchantment, MaterialLang -> Material) :

Spoiler: THIRD EXAMPLE
Code (Text):
final Enchantment enchantment = EnchantmentLang.DAMAGE_ALL.get();
final Material material = MaterialLang.DIAMOND.get();


Final example :
Add a translatable display name on a ItemStack (requires NBTAPI ) :

Spoiler: FINAL EXAMPLE
Code (Text):

// We check if the PlayerLangAPI is enabled on the server
if(Bukkit.getPluginManager().isPluginEnabled("PlayerLangAPI")) {
   // Get the instance of plugin
   final PlayerLangAPI langAPI = (PlayerLangAPI) Bukkit.getPluginManager().getPlugin("PlayerLangAPI");
   Validate.notNull(langAPI, "PlayerLangAPI is disabled!");
   // We check if NBTAPI plugin is enabled on the server.
   if(langAPI.hasNBTAPI()) {
       /* Creation of a new ItemStack */
       final ItemStack itemStack = new ItemStack(MaterialLang.DIAMOND.get());

       /* We put properties of display */
       final JsonObject gson = new JsonObject();
       gson.addProperty("translate", MaterialLang.STONE_SWORD.getTranslation());
       gson.addProperty("color", "red");
       gson.addProperty("italic", "false");

       /* We finally add itemstack into inventory of player */
       player.getInventory().addItem(langAPI.setDisplay(itemStack, gson));
   }
}


(You can see result with images which are uploaded)


NOTE : When I started to create the plugin, I hadn't noticed that there was a plugin similar to this one but that only supports 1.7-1.12 versions. ( https://www.spigotmc.org/resources/1-7-x-1-12-language-utils.8859/ )


If you have any suggestions, don't hesitate to tell me!
Quick facts

Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.

PlayerLangAPI | Simple translation identifiers [1.13+] is a free Minecraft Java mod. Compatible with Minecraft 1.13, 1.14, 1.15. Downloaded 280 times (via Spigot). Download it and open it directly in the game.

Explore more