diff --git a/build.gradle b/build.gradle index a10c898..540d8ff 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ apply plugin: 'maven-publish' group = 'com.meowj' archivesBaseName = 'LangUtils' -version = '1.2.0' +version = '1.3.0' final def EULA_ACCEPT = true diff --git a/src/main/java/com/meowj/langutils/lang/LanguageHelper.java b/src/main/java/com/meowj/langutils/lang/LanguageHelper.java index 1394a8c..1416451 100644 --- a/src/main/java/com/meowj/langutils/lang/LanguageHelper.java +++ b/src/main/java/com/meowj/langutils/lang/LanguageHelper.java @@ -41,7 +41,7 @@ public static String getItemDisplayName(ItemStack item, String locale) { if (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) return item.getItemMeta().getDisplayName(); else - return LanguageHelper.getItemName(item, locale); + return getItemName(item, locale); } /** @@ -192,30 +192,30 @@ public static String getEntityName(EntityType entityType, Player player) { * Return the unlocalized name of the enchantment level(Minecraft convention) * * @param level The enchantment level - * @return The unlocalized name. + * @return The unlocalized name.(if level is greater than 10, it will only return the number of the level) */ public static String getEnchantmentLevelUnlocalizedName(int level) { - EnumEnchantementLevel enumEnchLevel = EnumEnchantementLevel.get(level); - return (enumEnchLevel != null ? enumEnchLevel.getUnlocalizedName() : Integer.toString(level)); + EnumEnchantmentLevel enumEnchLevel = EnumEnchantmentLevel.get(level); + return enumEnchLevel != null ? enumEnchLevel.getUnlocalizedName() : Integer.toString(level); } /** - * Return the unlocalized name of the enchantment level(Minecraft convention) + * Return the name of the enchantment level * - * @param level The enchantment level + * @param level The enchantment level * @param player The language of the level - * @return The unlocalized name. + * @return The name of the level.(if level is greater than 10, it will only return the number of the level) */ public static String getEnchantmentLevelName(int level, Player player) { return translateToLocal(getEnchantmentLevelUnlocalizedName(level), LocaleHelper.getPlayerLanguage(player)); } /** - * Return the unlocalized name of the enchantment level(Minecraft convention) + * Return the name of the enchantment level * - * @param level The enchantment level + * @param level The enchantment level * @param locale The language of the level - * @return The unlocalized name. + * @return The name of the level.(if level is greater than 10, it will only return the number of the level) */ public static String getEnchantmentLevelName(int level, String locale) { return translateToLocal(getEnchantmentLevelUnlocalizedName(level), locale); @@ -224,62 +224,83 @@ public static String getEnchantmentLevelName(int level, String locale) { /** * Return the unlocalized name of the enchantment(Minecraft convention) * - * @param ench The enchantment + * @param enchantment The enchantment * @return The unlocalized name. */ - public static String getEnchantmentUnlocalizedName(Enchantment ench) { - EnumEnchantement enumEnch = EnumEnchantement.get(ench); - return (enumEnch != null ? enumEnch.getUnlocalizedName() : ench.getName()); + public static String getEnchantmentUnlocalizedName(Enchantment enchantment) { + EnumEnchantment enumEnch = EnumEnchantment.get(enchantment); + return (enumEnch != null ? enumEnch.getUnlocalizedName() : enchantment.getName()); } /** - * Return the display name of the enchantement. + * Return the name of the enchantment. * - * @param ench The enchantment - * @param player The receiver of the name - * @return The name of the item + * @param enchantment The enchantment + * @param player The receiver of the name + * @return The name of the enchantment */ - public static String getEnchantmentName(Enchantment ench, Player player) { - return getEnchantmentName(ench, LocaleHelper.getPlayerLanguage(player)); + public static String getEnchantmentName(Enchantment enchantment, Player player) { + return getEnchantmentName(enchantment, LocaleHelper.getPlayerLanguage(player)); } /** - * Return the display name of the item. + * Return the name of the enchantment. * - * @param ench The enchantment - * @param locale The language of the item(if the item doesn't have a customized name, the method will return the name of the item in this language) - * @return The name of the item + * @param enchantment The enchantment + * @param locale The language of the name + * @return The name of the enchantment */ - public static String getEnchantmentName(Enchantment ench, String locale) { - return translateToLocal(getEnchantmentUnlocalizedName(ench), locale); + public static String getEnchantmentName(Enchantment enchantment, String locale) { + return translateToLocal(getEnchantmentUnlocalizedName(enchantment), locale); } /** - * Return the display name of the enchantement. + * Return the display name of the enchantment(with level). * - * @param ench The enchantment - * @param level The enchantment level - * @param player The receiver of the name + * @param enchantment The enchantment + * @param level The enchantment level + * @param player The receiver of the name * @return The name of the item */ - public static String getEnchantmentName(Enchantment ench, int level, Player player) { - return getEnchantmentName(ench, level, LocaleHelper.getPlayerLanguage(player)); + public static String getEnchantmentDisplayName(Enchantment enchantment, int level, Player player) { + return getEnchantmentDisplayName(enchantment, level, LocaleHelper.getPlayerLanguage(player)); } /** - * Return the display name of the item. + * Return the display name of the enchantment(with level). * - * @param ench The enchantment - * @param level The enchantment level - * @param locale The language of the item(if the item doesn't have a customized name, the method will return the name of the item in this language) + * @param enchantment The enchantment + * @param level The enchantment level + * @param locale The language of the name * @return The name of the item */ - public static String getEnchantmentName(Enchantment ench, int level, String locale) { - String enchantment = getEnchantmentName(ench, locale); + public static String getEnchantmentDisplayName(Enchantment enchantment, int level, String locale) { + String name = getEnchantmentName(enchantment, locale); String enchLevel = getEnchantmentLevelName(level, locale); - return enchantment + (enchLevel.length()>0 ? " " + enchLevel : ""); + return name + (enchLevel.length() > 0 ? " " + enchLevel : ""); + } + + /** + * Return the display name of the enchantment(with level). + * + * @param entry The Entry of an enchantment with level The type is {@code Map.Entry} + * @param locale The language of the name + * @return The name of the item + */ + public static String getEnchantmentDisplayName(Map.Entry entry, String locale) { + return getEnchantmentDisplayName(entry.getKey(), entry.getValue(), locale); } + /** + * Return the display name of the enchantment(with level). + * + * @param entry The Entry of an enchantment with level The type is {@code Map.Entry} + * @param player The receiver of the name + * @return The name of the item + */ + public static String getEnchantmentDisplayName(Map.Entry entry, Player player) { + return getEnchantmentDisplayName(entry.getKey(), entry.getValue(), player); + } /** * Translate unlocalized field to localized field. diff --git a/src/main/java/com/meowj/langutils/lang/convert/EnumEnchantement.java b/src/main/java/com/meowj/langutils/lang/convert/EnumEnchantement.java deleted file mode 100644 index 34e7a5f..0000000 --- a/src/main/java/com/meowj/langutils/lang/convert/EnumEnchantement.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2015 Hexosse - * - * This project is Open Source and distributed under The MIT License (MIT) - * (http://opensource.org/licenses/MIT) - * - * You should have received a copy of the The MIT License along with - * this project. If not, see . - */ - -package com.meowj.langutils.lang.convert; - -import org.bukkit.enchantments.Enchantment; - -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - -/** - * This file is part of LanguageUtils - *

- * A list of enchantements. - * - * @author hexosse (hexosse on GitHub). - */ -public enum EnumEnchantement -{ - PROTECTION_ENVIRONMENTAL(Enchantment.PROTECTION_ENVIRONMENTAL, "enchantment.protect.all"), // Protection - PROTECTION_FIRE(Enchantment.PROTECTION_FIRE, "enchantment.protect.fire"), // Protection contre le feu - PROTECTION_FALL(Enchantment.PROTECTION_FALL, "enchantment.protect.fall"), // Chute amortie - PROTECTION_EXPLOSIONS(Enchantment.PROTECTION_EXPLOSIONS, "enchantment.protect.explosion"), // Protection contre les explosions - PROTECTION_PROJECTILE(Enchantment.PROTECTION_PROJECTILE, "enchantment.protect.projectile"), // Protection contre les projectiles - OXYGEN(Enchantment.OXYGEN, "enchantment.oxygen"), // Apnée - WATER_WORKER(Enchantment.WATER_WORKER, "enchantment.waterWorker"), // Affinité aquatique - THORNS(Enchantment.THORNS, "enchantment.thorns"), // Épines - DEPTH_STRIDER(Enchantment.DEPTH_STRIDER, "enchantment.waterWalker"), // Agilité aquatique - DAMAGE_ALL(Enchantment.DAMAGE_ALL, "enchantment.damage.all"), // Tranchant - DAMAGE_UNDEAD(Enchantment.DAMAGE_UNDEAD, "enchantment.damage.undead"), // Châtiment - DAMAGE_ARTHROPODS(Enchantment.DAMAGE_ARTHROPODS, "enchantment.damage.arthropods"), // Fléau des arthropodes - KNOCKBACK(Enchantment.KNOCKBACK, "enchantment.knockback"), // Recul - FIRE_ASPECT(Enchantment.FIRE_ASPECT, "enchantment.fire"), // Aura de feu - LOOT_BONUS_MOBS(Enchantment.LOOT_BONUS_MOBS, "enchantment.lootBonusDigger"), // Fortune - DIG_SPEED(Enchantment.DIG_SPEED, "enchantment.digging"), // Efficacité - SILK_TOUCH(Enchantment.SILK_TOUCH, "enchantment.untouching"), // Toucher de soie - DURABILITY(Enchantment.DURABILITY, "enchantment.durability"), // Solidité - LOOT_BONUS_BLOCKS(Enchantment.LOOT_BONUS_BLOCKS, "enchantment.lootBonus"), // Butin - ARROW_DAMAGE(Enchantment.ARROW_DAMAGE, "enchantment.arrowDamage"), // Puissance - ARROW_KNOCKBACK(Enchantment.ARROW_KNOCKBACK, "enchantment.arrowKnockback"), // Frappe - ARROW_FIRE(Enchantment.ARROW_FIRE, "enchantment.arrowFire"), // Flamme - ARROW_INFINITE(Enchantment.ARROW_INFINITE, "enchantment.arrowInfinite"), // Infinité - LUCK(Enchantment.LUCK, "enchantment.lootBonusFishing"), // Chance de la mer - LURE(Enchantment.LURE, "enchantment.fishingSpeed"); // Appât - - - - /** - * @return The {@link Enchantment} of the enchantement. - */ - public Enchantment getEnchantement() { - return enchantement; - } - - /** - * @return The unlocalized name of the enchantement. - */ - public String getUnlocalizedName() { - return unlocalizedName; - } - - - /** - * Create an index of enchantements. - */ - EnumEnchantement(Enchantment enchantement, String unlocalizedName) { - this(enchantement,0,unlocalizedName); - } - - /** - * Create an index of enchantements. - */ - EnumEnchantement(Enchantment enchantement, int level, String unlocalizedName) { - this.enchantement = enchantement; - this.unlocalizedName = unlocalizedName; - } - - - private static final Map lookup = new HashMap(); - - static { - for (EnumEnchantement enchantement : EnumSet.allOf(EnumEnchantement.class)) - lookup.put(enchantement.enchantement, enchantement); - } - - /** - * Get the index of an enchantement based on {@Link EnumEnchantement}. - * - * @param enchantement The enchantement. - * @return The index of the item. - */ - public static EnumEnchantement get(Enchantment enchantement) { - return lookup.containsKey(enchantement) ? lookup.get(enchantement) : null; - } - - - private Enchantment enchantement; - private String unlocalizedName; -} diff --git a/src/main/java/com/meowj/langutils/lang/convert/EnumEnchantementLevel.java b/src/main/java/com/meowj/langutils/lang/convert/EnumEnchantementLevel.java deleted file mode 100644 index e251d01..0000000 --- a/src/main/java/com/meowj/langutils/lang/convert/EnumEnchantementLevel.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2015 Hexosse - * - * This project is Open Source and distributed under The MIT License (MIT) - * (http://opensource.org/licenses/MIT) - * - * You should have received a copy of the The MIT License along with - * this project. If not, see . - */ - -package com.meowj.langutils.lang.convert; - -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - -/** - * This file is part of LanguageUtils - *

- * A list of enchantements level. - * - * @author hexosse (hexosse on GitHub). - */ -public enum EnumEnchantementLevel -{ - LEVEL1(1,"enchantment.level.1"), - LEVEL2(2,"enchantment.level.2"), - LEVEL3(3,"enchantment.level.3"), - LEVEL4(4,"enchantment.level.4"), - LEVEL5(5,"enchantment.level.5"), - LEVEL6(6,"enchantment.level.6"), - LEVEL7(7,"enchantment.level.7"), - LEVEL8(8,"enchantment.level.8"), - LEVEL9(9,"enchantment.level.9"), - LEVEL10(10,"enchantment.level.10"),; - - - - /** - * Create an index of enchantements. - */ - EnumEnchantementLevel(int level, String unlocalizedName) { - this.level = level; - this.unlocalizedName = unlocalizedName; - } - - /** - * @return Enchantement level - */ - public int getLevel() - { - return level; - } - - /** - * @return The unlocalized name of the enchantement level - */ - public String getUnlocalizedName() - { - return unlocalizedName; - } - - private static final Map lookup = new HashMap(); - - static { - for (EnumEnchantementLevel level : EnumSet.allOf(EnumEnchantementLevel.class)) - lookup.put(level.getLevel(), level); - } - - /** - * @param level Enchantement level. - * @return The index of a leve. - */ - public static EnumEnchantementLevel get(Integer level) { - return lookup.containsKey(level) ? lookup.get(level) : null; - } - - - private int level; - private String unlocalizedName; -} diff --git a/src/main/java/com/meowj/langutils/lang/convert/EnumEnchantment.java b/src/main/java/com/meowj/langutils/lang/convert/EnumEnchantment.java new file mode 100644 index 0000000..c6d888e --- /dev/null +++ b/src/main/java/com/meowj/langutils/lang/convert/EnumEnchantment.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2015 Hexosse + * + * This project is Open Source and distributed under The MIT License (MIT) + * (http://opensource.org/licenses/MIT) + * + * You should have received a copy of the The MIT License along with + * this project. If not, see . + */ + +package com.meowj.langutils.lang.convert; + +import org.bukkit.enchantments.Enchantment; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +/** + * This file is part of LanguageUtils + *

+ * A list of enchantments. + * + * @author hexosse (hexosse on GitHub). + */ +public enum EnumEnchantment { + + PROTECTION_ENVIRONMENTAL(Enchantment.PROTECTION_ENVIRONMENTAL, "enchantment.protect.all"), + PROTECTION_FIRE(Enchantment.PROTECTION_FIRE, "enchantment.protect.fire"), + PROTECTION_FALL(Enchantment.PROTECTION_FALL, "enchantment.protect.fall"), + PROTECTION_EXPLOSIONS(Enchantment.PROTECTION_EXPLOSIONS, "enchantment.protect.explosion"), + PROTECTION_PROJECTILE(Enchantment.PROTECTION_PROJECTILE, "enchantment.protect.projectile"), + OXYGEN(Enchantment.OXYGEN, "enchantment.oxygen"), + WATER_WORKER(Enchantment.WATER_WORKER, "enchantment.waterWorker"), + THORNS(Enchantment.THORNS, "enchantment.thorns"), + DEPTH_STRIDER(Enchantment.DEPTH_STRIDER, "enchantment.waterWalker"), + DAMAGE_ALL(Enchantment.DAMAGE_ALL, "enchantment.damage.all"), + DAMAGE_UNDEAD(Enchantment.DAMAGE_UNDEAD, "enchantment.damage.undead"), + DAMAGE_ARTHROPODS(Enchantment.DAMAGE_ARTHROPODS, "enchantment.damage.arthropods"), + KNOCKBACK(Enchantment.KNOCKBACK, "enchantment.knockback"), + FIRE_ASPECT(Enchantment.FIRE_ASPECT, "enchantment.fire"), + LOOT_BONUS_MOBS(Enchantment.LOOT_BONUS_MOBS, "enchantment.lootBonus"), + DIG_SPEED(Enchantment.DIG_SPEED, "enchantment.digging"), + SILK_TOUCH(Enchantment.SILK_TOUCH, "enchantment.untouching"), + DURABILITY(Enchantment.DURABILITY, "enchantment.durability"), + LOOT_BONUS_BLOCKS(Enchantment.LOOT_BONUS_BLOCKS, "enchantment.lootBonusDigger"), + ARROW_DAMAGE(Enchantment.ARROW_DAMAGE, "enchantment.arrowDamage"), + ARROW_KNOCKBACK(Enchantment.ARROW_KNOCKBACK, "enchantment.arrowKnockback"), + ARROW_FIRE(Enchantment.ARROW_FIRE, "enchantment.arrowFire"), + ARROW_INFINITE(Enchantment.ARROW_INFINITE, "enchantment.arrowInfinite"), + LUCK(Enchantment.LUCK, "enchantment.lootBonusFishing"), + LURE(Enchantment.LURE, "enchantment.fishingSpeed"); + + /** + * @return The {@link Enchantment} of the enchantment. + */ + public Enchantment getEnchantment() { + return enchantment; + } + + /** + * @return The unlocalized name of the enchantment. + */ + public String getUnlocalizedName() { + return unlocalizedName; + } + + + /** + * Create an index of enchantments. + */ + EnumEnchantment(Enchantment enchantment, String unlocalizedName) { + this(enchantment, 0, unlocalizedName); + } + + /** + * Create an index of enchantments. + */ + EnumEnchantment(Enchantment enchantment, int level, String unlocalizedName) { + this.enchantment = enchantment; + this.unlocalizedName = unlocalizedName; + } + + private static final Map lookup = new HashMap(); + + static { + for (EnumEnchantment enchantment : EnumSet.allOf(EnumEnchantment.class)) + lookup.put(enchantment.enchantment, enchantment); + } + + /** + * Get the index of an enchantment based on {@link EnumEnchantment}. + * + * @param enchantment The enchantment. + * @return The index of the item. + */ + public static EnumEnchantment get(Enchantment enchantment) { + return lookup.containsKey(enchantment) ? lookup.get(enchantment) : null; + } + + private Enchantment enchantment; + private String unlocalizedName; +} diff --git a/src/main/java/com/meowj/langutils/lang/convert/EnumEnchantmentLevel.java b/src/main/java/com/meowj/langutils/lang/convert/EnumEnchantmentLevel.java new file mode 100644 index 0000000..bd50a06 --- /dev/null +++ b/src/main/java/com/meowj/langutils/lang/convert/EnumEnchantmentLevel.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2015 Hexosse + * + * This project is Open Source and distributed under The MIT License (MIT) + * (http://opensource.org/licenses/MIT) + * + * You should have received a copy of the The MIT License along with + * this project. If not, see . + */ + +package com.meowj.langutils.lang.convert; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +/** + * This file is part of LanguageUtils + *

+ * A list of enchantments level. + * + * @author hexosse (hexosse on GitHub). + */ +public enum EnumEnchantmentLevel { + + LEVEL1(1, "enchantment.level.1"), + LEVEL2(2, "enchantment.level.2"), + LEVEL3(3, "enchantment.level.3"), + LEVEL4(4, "enchantment.level.4"), + LEVEL5(5, "enchantment.level.5"), + LEVEL6(6, "enchantment.level.6"), + LEVEL7(7, "enchantment.level.7"), + LEVEL8(8, "enchantment.level.8"), + LEVEL9(9, "enchantment.level.9"), + LEVEL10(10, "enchantment.level.10"),; + + /** + * Create an index of enchantments. + */ + EnumEnchantmentLevel(int level, String unlocalizedName) { + this.level = level; + this.unlocalizedName = unlocalizedName; + } + + /** + * @return Enchantment level + */ + public int getLevel() { + return level; + } + + /** + * @return The unlocalized name of the enchantment level + */ + public String getUnlocalizedName() { + return unlocalizedName; + } + + private static final Map lookup = new HashMap(); + + static { + for (EnumEnchantmentLevel level : EnumSet.allOf(EnumEnchantmentLevel.class)) + lookup.put(level.getLevel(), level); + } + + /** + * @param level Enchantment level. + * @return The index of a level. + */ + public static EnumEnchantmentLevel get(Integer level) { + return lookup.containsKey(level) ? lookup.get(level) : null; + } + + private int level; + private String unlocalizedName; +} diff --git a/src/main/java/com/meowj/langutils/lang/convert/EnumPotionEffect.java b/src/main/java/com/meowj/langutils/lang/convert/EnumPotionEffect.java index 5a33671..534c3c9 100644 --- a/src/main/java/com/meowj/langutils/lang/convert/EnumPotionEffect.java +++ b/src/main/java/com/meowj/langutils/lang/convert/EnumPotionEffect.java @@ -102,7 +102,7 @@ public static String getLocalizedName(ItemStack potion, String locale) { case 64: case 8192: return LanguageHelper.translateToLocal("potion.prefix.mundane", locale) + " " + LanguageHelper.translateToLocal("item.potion.name", locale); - // Fix Instant Health Potion problem + // Fix Instant Health Potion problem(This problem has been fixed in the latest version of the Bukkit, but I'll still leave it here in case many people don't update their server very often. Indeed, I highly recommend updating the servers) case 16453: return LanguageHelper.translateToLocal("potion.prefix.grenade", locale) + " " + LanguageHelper.translateToLocal("potion.heal.postfix", locale); case 8261: diff --git a/src/test/java/com/meowj/langutils/lang/LanguageHelperTest.java b/src/test/java/com/meowj/langutils/lang/LanguageHelperTest.java index 679a0c8..6822668 100644 --- a/src/test/java/com/meowj/langutils/lang/LanguageHelperTest.java +++ b/src/test/java/com/meowj/langutils/lang/LanguageHelperTest.java @@ -13,12 +13,13 @@ import com.meowj.langutils.lang.convert.EnumLang; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; -import org.bukkit.enchantments.EnchantmentWrapper; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.material.SpawnEgg; +import org.bukkit.potion.PotionEffectType; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.modules.junit4.PowerMockRunner; @@ -35,9 +36,49 @@ @RunWith(PowerMockRunner.class) public class LanguageHelperTest { + + @BeforeClass + public static void setup() throws IOException { + PotionEffectType.registerPotionEffectType(new PotionEffectType(10) { + @Override + public double getDurationModifier() { + return 1; + } + + @Override + public String getName() { + return "Regeneration"; + } + + @Override + public boolean isInstant() { + return false; + } + }); + + //Init Lang(Only English and Chinese(for UTF-8 Test)) + String temp; + String[] tempStringArr; + for (EnumLang enumLang : new EnumLang[]{EnumLang.EN_US, EnumLang.ZH_CN}) { + BufferedReader reader = new BufferedReader(new InputStreamReader(LanguageHelperTest.class.getResourceAsStream("/lang/" + enumLang.getLocale() + ".lang"), Charset.forName("UTF-8"))); + try { + temp = reader.readLine(); + while (temp != null) { + if (temp.contains("=")) { + tempStringArr = temp.split("="); + enumLang.getMap().put(tempStringArr[0], tempStringArr.length > 1 ? tempStringArr[1] : ""); + } + temp = reader.readLine(); + } + } finally { + reader.close(); + } + } + } + @Test public void testItemDisplayName() throws Exception { - initLangs(); // Only load en_US and zh_CN(Encoding test) + // Only load en_US and zh_CN(Encoding test) ItemStack test = mock(ItemStack.class); @@ -63,9 +104,9 @@ public void testItemDisplayName() throws Exception { assertEquals("\u82b1\u5c97\u5ca9", LanguageHelper.getItemDisplayName(UTF8Test, "zh_CN")); } + @Test public void testPotionDisplayName() throws Exception { - initLangs(); ItemStack waterBottle = mock(ItemStack.class); when(waterBottle.getType()).thenReturn(Material.POTION); @@ -94,7 +135,6 @@ public void testPotionDisplayName() throws Exception { @Test public void testMonsterEggDisplayName() throws Exception { - initLangs(); ItemStack creeperEgg = mock(ItemStack.class); SpawnEgg egg = mock(SpawnEgg.class); @@ -147,18 +187,16 @@ public void testGetEntityUnlocalizedName() { @Test public void testGetEntityName() throws IOException { - initLangs(); Entity entity1 = mock(Entity.class); when(entity1.getType()).thenReturn(EntityType.CREEPER); assertEquals("Creeper", LanguageHelper.getEntityName(entity1, "en_US")); - assertEquals("arrow", LanguageHelper.getEntityName(EntityType.ARROW, "en_US")); + assertEquals("Arrow", LanguageHelper.getEntityName(EntityType.ARROW, "en_US")); } @Test public void testGetEntityDisplayName() throws IOException { - initLangs(); Entity entity1 = mock(Entity.class); when(entity1.getType()).thenReturn(EntityType.CREEPER); @@ -173,43 +211,17 @@ public void testGetEntityDisplayName() throws IOException { @Test public void testEnchantmentDisplayName() throws Exception { - /*initLangs(); - - Enchantment ench = mock(Enchantment.class); - - when(ench.getId()).thenReturn((int) 0); - when(ench.getName()).thenReturn((String) "PROTECTION_ENVIRONMENTAL"); - when(ench.toString()).thenReturn("Enchantment[" + 0 + ", " + "protection" + "]"); - - assertEquals("Protection", LanguageHelper.getEnchantementUnlocalizedName(ench)); - assertEquals("Protection", LanguageHelper.getEnchantmentName(ench, "fr_FR")); - assertEquals("Protection IV", LanguageHelper.getEnchantmentName(ench, 4, "fr_FR"));*/ + assertEquals("enchantment.protect.all", LanguageHelper.getEnchantmentUnlocalizedName(Enchantment.PROTECTION_ENVIRONMENTAL)); + assertEquals("X", LanguageHelper.getEnchantmentLevelName(10, "en_US")); + assertEquals("Protection", LanguageHelper.getEnchantmentName(Enchantment.PROTECTION_ENVIRONMENTAL, "en_US")); + assertEquals("Protection IV", LanguageHelper.getEnchantmentDisplayName(Enchantment.PROTECTION_ENVIRONMENTAL, 4, "en_US")); + assertEquals("Protection 11", LanguageHelper.getEnchantmentDisplayName(Enchantment.PROTECTION_ENVIRONMENTAL, 11, "en_US")); } @Test public void testTranslateToLocale() throws IOException { - initLangs(); assertEquals("Creeper", LanguageHelper.translateToLocal("entity.Creeper.name", "en_US")); assertEquals("Stone", LanguageHelper.translateToLocal("tile.stone.stone.name", "en_US")); } - private void initLangs() throws IOException { - String temp; - String[] tempStringArr; - for (EnumLang enumLang : new EnumLang[]{EnumLang.EN_US, EnumLang.ZH_CN, EnumLang.FR_FR}) { - BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/lang/" + enumLang.getLocale() + ".lang"), Charset.forName("UTF-8"))); - try { - temp = reader.readLine(); - while (temp != null) { - if (temp.contains("=")) { - tempStringArr = temp.split("="); - enumLang.getMap().put(tempStringArr[0], tempStringArr.length > 1 ? tempStringArr[1] : ""); - } - temp = reader.readLine(); - } - } finally { - reader.close(); - } - } - } } \ No newline at end of file