PlayerLangAPI | Simple translation identifiers [1.13+]
0.4A library which enables developpers to use translations on client-side with translations keys
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
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Maven dependency
<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 :
FIRST EXAMPLE
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 :
SECOND EXAMPLE
/* 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) :
THIRD EXAMPLE
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 ) :
FINAL EXAMPLE
// 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!
Similar projects
Plugin →Let Me Despawn
Improves performance by tweaking mob despawn rules. Say bye to pesky unintentional persistent mobs.
25MSueta
JourneyMap
Real-time map used for mapping in-game or your browser as you explore.
14.7MSueta
Emotecraft
Create your own emotes in Minecraft.
7.5MSueta
Simple Tpa
A simple tpa plugin which sends requests
5.4MSueta
Common Network
Forge and Fabric Unified Networking Solution
3.9MSueta
Set Home
A lightweight plugin for players to set their homes.
3.8MSueta