Skip to content

Commit 2a11f98

Browse files
author
Yovach
committed
add: colors, enchantments, potion effects, entities localized names | fix: plugin.yml
1 parent 30228c6 commit 2a11f98

12 files changed

Lines changed: 1297 additions & 1053 deletions

File tree

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
1-
# PlayerLangAPI
2-
A plugin which enables developpers to use translations on client side dynamically (with lang.json)
1+
###What is PlayerLangAPI ?
2+
3+
PlayerLangAPI is a library enables developpers to use translations on client side dynamically.
34

45
This plugin is only compatible with 1.13+ versions (until Mojang changes languages format)
56

7+
I haven't tested in 1.13.x and 1.14.x but I think it should work because the format of lang hasn't been updated since 1.13
68

7-
# Why ?
89

10+
###Why use this library?
911
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.
1012

1113
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)
1214

15+
###How use it ?
16+
Currently, it's rather difficult to use since I don't have a Maven directory, but I'll find out more about that in a few days.
17+
You can however use the library by compiling it and using the local repository.
18+
19+
20+
###Usage
21+
22+
If you want to send the name of the stone sword according to the player's language (null example but it is an example) :
23+
```
24+
final TranslatableComponent component = new TranslatableComponent(MaterialLang.STONE_SWORD.getTranslation());
25+
player.sendMessage(component);
26+
```
27+
This will send "Stone sword" for a player whose language of play is English and "Espada de piedre" for a Spanish player.
28+
1329
**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/)
30+
31+
32+
If you have any suggestions, don't hesitate to tell me!

TODO.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
### TODO list
22

33
- make compatible with < 1.13 versions
4-
- add potions and enchantments names
4+
5+
- ~~add potions and enchantments names~~

pom.xml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>fr.yovach</groupId>
88
<artifactId>PlayerLangAPI</artifactId>
9-
<version>0.1</version>
9+
<version>0.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>PlayerLangAPI</name>
@@ -63,13 +63,7 @@
6363
<url>https://oss.sonatype.org/content/groups/public/</url>
6464
</repository>
6565
</repositories>
66-
67-
<dependencies><!--
68-
<dependency>
69-
<groupId>com.google.code.gson</groupId>
70-
<artifactId>gson</artifactId>
71-
<version>2.8.6</version>
72-
</dependency>-->
66+
<dependencies>
7367
<dependency>
7468
<groupId>org.spigotmc</groupId>
7569
<artifactId>spigot-api</artifactId>

src/main/java/fr/yovach/lang/ICraftLang.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package fr.yovach.lang;
22

3-
public interface ICraftLang {
3+
public interface ICraftLang<T> {
44

55
public String getTranslation();
66

src/main/java/fr/yovach/lang/MaterialLang.java

Lines changed: 0 additions & 984 deletions
This file was deleted.

src/main/java/fr/yovach/lang/PlayerLangAPI.java

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,18 @@
11
package fr.yovach.lang;
22

3-
import com.google.gson.Gson;
4-
import com.google.gson.GsonBuilder;
5-
import com.google.gson.JsonElement;
6-
import com.google.gson.JsonObject;
7-
import org.apache.commons.lang.Validate;
83
import org.bukkit.plugin.java.JavaPlugin;
94

10-
import java.io.*;
11-
import java.nio.file.Files;
12-
import java.nio.file.StandardOpenOption;
13-
import java.util.Arrays;
14-
import java.util.Map;
15-
165
public final class PlayerLangAPI extends JavaPlugin {
176

187
@Override
198
public void onEnable() {
9+
/*
2010
getLogger().info(MaterialLang.values().length + " translations of materials are loaded.");
21-
22-
try {
23-
readJSON("assets/minecraft/lang/en_us.json");
24-
} catch (IOException e) {
25-
e.printStackTrace();
26-
}
27-
}
28-
29-
private void readJSON(String path) throws IOException {
30-
final InputStream stream = getResource(path);
31-
32-
final File file = new File(getDataFolder(), "lang.json");
33-
if(!file.exists()){
34-
file.getParentFile().mkdirs();
35-
file.createNewFile();
36-
}
37-
38-
Validate.notNull(stream, "stream cannot be null");
39-
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
40-
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
41-
final JsonObject json = gson.fromJson(reader, JsonObject.class);
42-
reader.close();
43-
44-
final JsonObject result = new JsonObject();
45-
for (Map.Entry<String, JsonElement> consumer : json.entrySet()) {
46-
final String key = consumer.getKey();
47-
final String[] chunks = key.split("\\.");
48-
if (chunks.length == 3) {
49-
// {type}.minecraft.{name}.{?..properties} | without properties, length = 3 else > 3
50-
if (chunks[0].equalsIgnoreCase("item")) {
51-
if (!chunks[1].equalsIgnoreCase("minecraft")) {
52-
continue;
53-
}
54-
} else if (!chunks[0].equalsIgnoreCase("block")){
55-
continue;
56-
}
57-
final String materialName = Arrays.copyOfRange(chunks, 2, 3)[0].toUpperCase();
58-
result.addProperty(materialName, key);
59-
}
60-
61-
}
62-
final String content = gson.toJson(result);
63-
file.delete();
64-
Files.write(file.toPath(), content.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
11+
getLogger().info(EnchantmentLang.values().length + " translations of enchantments are loaded.");
12+
getLogger().info(ColorLang.values().length + " translations of colors are loaded.");
13+
getLogger().info(EntityTypeLang.values().length + " translations of enchantments are loaded.");
14+
getLogger().info(PotionEffectTypeLang.values().length + " translations of enchantments are loaded.");
15+
*/
6516
}
6617

6718
@Override
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package fr.yovach.lang.data;
2+
3+
import fr.yovach.lang.ICraftLang;
4+
import org.bukkit.Color;
5+
6+
import java.util.Arrays;
7+
8+
public enum ColorLang implements ICraftLang<Color> {
9+
BLACK("black"),
10+
BLUE("blue"),
11+
BROWN("brown"),
12+
CYAN("cyan"),
13+
GRAY("gray"),
14+
GREEN("green"),
15+
LIGHT_BLUE("light_blue"),
16+
LIGHT_GRAY("light_gray"),
17+
LIME("lime"),
18+
MAGENTA("magenta"),
19+
ORANGE("orange"),
20+
PINK("pink"),
21+
PURPLE("purple"),
22+
RED("red"),
23+
WHITE("white"),
24+
YELLOW("yellow"),
25+
;
26+
27+
private final String translation;
28+
29+
ColorLang(final String translation) {
30+
this.translation = translation;
31+
}
32+
33+
@Override public String getTranslation() {
34+
final String type = "color";
35+
return String.join(".", Arrays.asList(type, "minecraft", translation));
36+
}
37+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package fr.yovach.lang.data;
2+
3+
import fr.yovach.lang.ICraftLang;
4+
import org.bukkit.enchantments.Enchantment;
5+
6+
import java.util.Arrays;
7+
8+
public enum EnchantmentLang implements ICraftLang<Enchantment> {
9+
PROTECTION_FIRE("fire_protection"),
10+
DAMAGE_ALL("sharpness"),
11+
ARROW_FIRE("flame"),
12+
WATER_WORKER("aqua_affinity"),
13+
ARROW_KNOCKBACK("punch"),
14+
LOYALTY("loyalty"),
15+
DEPTH_STRIDER("depth_strider"),
16+
VANISHING_CURSE("vanishing_curse"),
17+
DURABILITY("unbreaking"),
18+
KNOCKBACK("knockback"),
19+
LUCK("luck_of_the_sea"),
20+
BINDING_CURSE("binding_curse"),
21+
LOOT_BONUS_BLOCKS("fortune"),
22+
PROTECTION_ENVIRONMENTAL("protection"),
23+
DIG_SPEED("efficiency"),
24+
MENDING("mending"),
25+
FROST_WALKER("frost_walker"),
26+
LURE("lure"),
27+
LOOT_BONUS_MOBS("looting"),
28+
PIERCING("piercing"),
29+
PROTECTION_EXPLOSIONS("blast_protection"),
30+
DAMAGE_UNDEAD("smite"),
31+
MULTISHOT("multishot"),
32+
FIRE_ASPECT("fire_aspect"),
33+
CHANNELING("channeling"),
34+
SWEEPING_EDGE("sweeping"),
35+
THORNS("thorns"),
36+
DAMAGE_ARTHROPODS("bane_of_arthropods"),
37+
OXYGEN("respiration"),
38+
RIPTIDE("riptide"),
39+
SILK_TOUCH("silk_touch"),
40+
QUICK_CHARGE("quick_charge"),
41+
PROTECTION_PROJECTILE("projectile_protection"),
42+
IMPALING("impaling"),
43+
PROTECTION_FALL("feather_falling"),
44+
ARROW_DAMAGE("power"),
45+
ARROW_INFINITE("infinity");
46+
47+
private final String translation;
48+
49+
EnchantmentLang(final String translation) {
50+
this.translation = translation;
51+
}
52+
53+
@Override public String getTranslation() {
54+
final String type = "enchantment";
55+
return String.join(".", Arrays.asList(type, "minecraft", translation));
56+
}
57+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package fr.yovach.lang.data;
2+
3+
import fr.yovach.lang.ICraftLang;
4+
import org.bukkit.entity.EntityType;
5+
6+
import java.util.Arrays;
7+
8+
public enum EntityTypeLang implements ICraftLang<EntityType> {
9+
AREA_EFFECT_CLOUD("area_effect_cloud"),
10+
ARMOR_STAND("armor_stand"),
11+
ARROW("arrow"),
12+
BAT("bat"),
13+
BEE("bee"),
14+
BLAZE("blaze"),
15+
BOAT("boat"),
16+
CAT("cat"),
17+
CAVE_SPIDER("cave_spider"),
18+
CHEST_MINECART("chest_minecart"),
19+
CHICKEN("chicken"),
20+
COD("cod"),
21+
COMMAND_BLOCK_MINECART("command_block_minecart"),
22+
COW("cow"),
23+
CREEPER("creeper"),
24+
DOLPHIN("dolphin"),
25+
DONKEY("donkey"),
26+
DRAGON_FIREBALL("dragon_fireball"),
27+
DROWNED("drowned"),
28+
EGG("egg"),
29+
ELDER_GUARDIAN("elder_guardian"),
30+
ENDERMAN("enderman"),
31+
ENDERMITE("endermite"),
32+
ENDER_DRAGON("ender_dragon"),
33+
ENDER_PEARL("ender_pearl"),
34+
END_CRYSTAL("end_crystal"),
35+
EVOKER("evoker"),
36+
EVOKER_FANGS("evoker_fangs"),
37+
EXPERIENCE_BOTTLE("experience_bottle"),
38+
EXPERIENCE_ORB("experience_orb"),
39+
EYE_OF_ENDER("eye_of_ender"),
40+
FALLING_BLOCK("falling_block"),
41+
FIREBALL("fireball"),
42+
FIREWORK_ROCKET("firework_rocket"),
43+
FISHING_BOBBER("fishing_bobber"),
44+
FOX("fox"),
45+
FURNACE_MINECART("furnace_minecart"),
46+
GHAST("ghast"),
47+
GIANT("giant"),
48+
GUARDIAN("guardian"),
49+
HOPPER_MINECART("hopper_minecart"),
50+
HORSE("horse"),
51+
HUSK("husk"),
52+
ILLUSIONER("illusioner"),
53+
IRON_GOLEM("iron_golem"),
54+
ITEM("item"),
55+
ITEM_FRAME("item_frame"),
56+
KILLER_BUNNY("killer_bunny"),
57+
LEASH_KNOT("leash_knot"),
58+
LIGHTNING_BOLT("lightning_bolt"),
59+
LLAMA("llama"),
60+
LLAMA_SPIT("llama_spit"),
61+
MAGMA_CUBE("magma_cube"),
62+
MINECART("minecart"),
63+
MOOSHROOM("mooshroom"),
64+
MULE("mule"),
65+
OCELOT("ocelot"),
66+
PAINTING("painting"),
67+
PANDA("panda"),
68+
PARROT("parrot"),
69+
PHANTOM("phantom"),
70+
PIG("pig"),
71+
PILLAGER("pillager"),
72+
PLAYER("player"),
73+
POLAR_BEAR("polar_bear"),
74+
POTION("potion"),
75+
PUFFERFISH("pufferfish"),
76+
RABBIT("rabbit"),
77+
RAVAGER("ravager"),
78+
SALMON("salmon"),
79+
SHEEP("sheep"),
80+
SHULKER("shulker"),
81+
SHULKER_BULLET("shulker_bullet"),
82+
SILVERFISH("silverfish"),
83+
SKELETON("skeleton"),
84+
SKELETON_HORSE("skeleton_horse"),
85+
SLIME("slime"),
86+
SMALL_FIREBALL("small_fireball"),
87+
SNOWBALL("snowball"),
88+
SNOW_GOLEM("snow_golem"),
89+
SPAWNER_MINECART("spawner_minecart"),
90+
SPECTRAL_ARROW("spectral_arrow"),
91+
SPIDER("spider"),
92+
SQUID("squid"),
93+
STRAY("stray"),
94+
TNT("tnt"),
95+
TNT_MINECART("tnt_minecart"),
96+
TRADER_LLAMA("trader_llama"),
97+
TRIDENT("trident"),
98+
TROPICAL_FISH("tropical_fish"),
99+
TURTLE("turtle"),
100+
VEX("vex"),
101+
VILLAGER("villager"),
102+
VINDICATOR("vindicator"),
103+
WANDERING_TRADER("wandering_trader"),
104+
WITCH("witch"),
105+
WITHER("wither"),
106+
WITHER_SKELETON("wither_skeleton"),
107+
WITHER_SKULL("wither_skull"),
108+
WOLF("wolf"),
109+
ZOMBIE("zombie"),
110+
ZOMBIE_HORSE("zombie_horse"),
111+
ZOMBIE_PIGMAN("zombie_pigman"),
112+
ZOMBIE_VILLAGER("zombie_villager"),
113+
;
114+
115+
private final String translation;
116+
117+
EntityTypeLang(final String translation) {
118+
this.translation = translation;
119+
}
120+
121+
@Override public String getTranslation() {
122+
final String type = "entity";
123+
return String.join(".", Arrays.asList(type, "minecraft", translation));
124+
}
125+
}

0 commit comments

Comments
 (0)