Skip to content

Commit 9b6ef08

Browse files
committed
Update to 1.4.0
1 parent 842f18e commit 9b6ef08

File tree

12 files changed

+267
-160
lines changed

12 files changed

+267
-160
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ apply plugin: 'maven-publish'
1010

1111
group = 'com.meowj'
1212
archivesBaseName = 'LangUtils'
13-
version = '1.3.0-1.7.10'
13+
version = '1.4.0-1.7.10'
1414

1515
final def EULA_ACCEPT = true
1616

src/main/java/com/meowj/langutils/LangUtils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package com.meowj.langutils;
1111

12+
import com.meowj.langutils.lang.LanguageRegistry;
1213
import com.meowj.langutils.lang.convert.EnumLang;
1314
import org.bukkit.plugin.java.JavaPlugin;
1415

@@ -32,13 +33,19 @@ public void onEnable() {
3233
isCauldron = true;
3334
warn("This API is not designed for Cauldron/KCauldron server, but it should work without problems for VANILLA items/entities. Again, you cannot use this API with items/entities in mods.");
3435
}
36+
37+
saveResource("lang/README.txt", false);
38+
39+
// Init default lang
3540
try {
3641
final long startTime = System.currentTimeMillis();
3742
EnumLang.init();
3843
info("Language Utils has been enabled." + "(" + (System.currentTimeMillis() - startTime) + "ms)");
3944
} catch (IOException e) {
4045
e.printStackTrace();
4146
}
47+
48+
LanguageRegistry.INSTANCE = new LanguageRegistry();
4249
}
4350

4451
@Override
@@ -65,6 +72,11 @@ public void warn(String msg) {
6572
getLogger().log(Level.WARNING, msg);
6673
}
6774

75+
/**
76+
* Return true if Cauldron environment is detected
77+
*
78+
* @return true if Cauldron environment is detected
79+
*/
6880
public boolean isCauldron() {
6981
return isCauldron;
7082
}

src/main/java/com/meowj/langutils/lang/LanguageHelper.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public static String getItemDisplayName(ItemStack item, Player player) {
6464
* @return The localized name. if the item doesn't have a localized name, this method will return the unlocalized name of it.
6565
*/
6666
public static String getItemName(ItemStack item, String locale) {
67-
Map<String, String> map = EnumLang.get(locale).getMap();
68-
6967
// Potion & SpawnEgg & Player Skull
7068
if (item.getType() == Material.POTION && item.getDurability() != 0)
7169
return EnumPotionEffect.getLocalizedName(item, locale);
@@ -309,10 +307,11 @@ public static String getEnchantmentDisplayName(Map.Entry<Enchantment, Integer> e
309307
*
310308
* @param unlocalizedName The unlocalized field.
311309
* @param locale The language to be translated to.
312-
* @return The localized field. If the localized field doesn't exist, it will return the unlocalized name.
310+
* @return The localized field. If the localized field doesn't exist, it will first look up the English map. If the entry still doesn't exist, then return the unlocalized name.
313311
*/
314312
public static String translateToLocal(String unlocalizedName, String locale) {
315313
Map<String, String> map = EnumLang.get(locale).getMap();
316-
return map.containsKey(unlocalizedName) ? map.get(unlocalizedName) : unlocalizedName;
314+
return map.containsKey(unlocalizedName) ? map.get(unlocalizedName) :
315+
(EnumLang.EN_US.getMap().containsKey(unlocalizedName) ? EnumLang.EN_US.getMap().get(unlocalizedName) : unlocalizedName);
317316
}
318317
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2015 Jerrell Fang
3+
*
4+
* This project is Open Source and distributed under The MIT License (MIT)
5+
* (http://opensource.org/licenses/MIT)
6+
*
7+
* You should have received a copy of the The MIT License along with
8+
* this project. If not, see <http://opensource.org/licenses/MIT>.
9+
*/
10+
11+
package com.meowj.langutils.lang;
12+
13+
import com.meowj.langutils.lang.convert.EnumLang;
14+
15+
/**
16+
* Created by Meow J on 8/11/2015.
17+
* <p>
18+
* Customize the language entry
19+
*
20+
* @author Meow J
21+
*/
22+
public class LanguageRegistry {
23+
24+
public static LanguageRegistry INSTANCE;
25+
26+
/**
27+
* Add or replace a language entry
28+
*
29+
* @param lang The language of the entry
30+
* @param unlocalizedName The unlocalized name of the entry
31+
* @param localizedName The localized name of the entry
32+
* @return the previous value of the entry, or null if the entry is newly added.
33+
*/
34+
public String registerEntry(EnumLang lang, String unlocalizedName, String localizedName) {
35+
return lang.getMap().put(unlocalizedName, localizedName);
36+
}
37+
38+
}

src/main/java/com/meowj/langutils/lang/convert/EnumEnchantment.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,15 @@ public enum EnumEnchantment {
5050
LUCK(Enchantment.LUCK, "enchantment.lootBonusFishing"),
5151
LURE(Enchantment.LURE, "enchantment.fishingSpeed");
5252

53-
/**
54-
* @return The {@link Enchantment} of the enchantment.
55-
*/
56-
public Enchantment getEnchantment() {
57-
return enchantment;
58-
}
53+
private static final Map<Enchantment, EnumEnchantment> lookup = new HashMap<Enchantment, EnumEnchantment>();
5954

60-
/**
61-
* @return The unlocalized name of the enchantment.
62-
*/
63-
public String getUnlocalizedName() {
64-
return unlocalizedName;
55+
static {
56+
for (EnumEnchantment enchantment : EnumSet.allOf(EnumEnchantment.class))
57+
lookup.put(enchantment.enchantment, enchantment);
6558
}
6659

60+
private Enchantment enchantment;
61+
private String unlocalizedName;
6762

6863
/**
6964
* Create an index of enchantments.
@@ -80,13 +75,6 @@ public String getUnlocalizedName() {
8075
this.unlocalizedName = unlocalizedName;
8176
}
8277

83-
private static final Map<Enchantment, EnumEnchantment> lookup = new HashMap<Enchantment, EnumEnchantment>();
84-
85-
static {
86-
for (EnumEnchantment enchantment : EnumSet.allOf(EnumEnchantment.class))
87-
lookup.put(enchantment.enchantment, enchantment);
88-
}
89-
9078
/**
9179
* Get the index of an enchantment based on {@link EnumEnchantment}.
9280
*
@@ -97,6 +85,17 @@ public static EnumEnchantment get(Enchantment enchantment) {
9785
return lookup.containsKey(enchantment) ? lookup.get(enchantment) : null;
9886
}
9987

100-
private Enchantment enchantment;
101-
private String unlocalizedName;
88+
/**
89+
* @return The {@link Enchantment} of the enchantment.
90+
*/
91+
public Enchantment getEnchantment() {
92+
return enchantment;
93+
}
94+
95+
/**
96+
* @return The unlocalized name of the enchantment.
97+
*/
98+
public String getUnlocalizedName() {
99+
return unlocalizedName;
100+
}
102101
}

src/main/java/com/meowj/langutils/lang/convert/EnumEnchantmentLevel.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ public enum EnumEnchantmentLevel {
3434
LEVEL9(9, "enchantment.level.9"),
3535
LEVEL10(10, "enchantment.level.10"),;
3636

37+
private static final Map<Integer, EnumEnchantmentLevel> lookup = new HashMap<Integer, EnumEnchantmentLevel>();
38+
39+
static {
40+
for (EnumEnchantmentLevel level : EnumSet.allOf(EnumEnchantmentLevel.class))
41+
lookup.put(level.getLevel(), level);
42+
}
43+
44+
private int level;
45+
private String unlocalizedName;
46+
3747
/**
3848
* Create an index of enchantments.
3949
*/
@@ -42,6 +52,14 @@ public enum EnumEnchantmentLevel {
4252
this.unlocalizedName = unlocalizedName;
4353
}
4454

55+
/**
56+
* @param level Enchantment level.
57+
* @return The index of a level.
58+
*/
59+
public static EnumEnchantmentLevel get(Integer level) {
60+
return lookup.containsKey(level) ? lookup.get(level) : null;
61+
}
62+
4563
/**
4664
* @return Enchantment level
4765
*/
@@ -55,22 +73,4 @@ public int getLevel() {
5573
public String getUnlocalizedName() {
5674
return unlocalizedName;
5775
}
58-
59-
private static final Map<Integer, EnumEnchantmentLevel> lookup = new HashMap<Integer, EnumEnchantmentLevel>();
60-
61-
static {
62-
for (EnumEnchantmentLevel level : EnumSet.allOf(EnumEnchantmentLevel.class))
63-
lookup.put(level.getLevel(), level);
64-
}
65-
66-
/**
67-
* @param level Enchantment level.
68-
* @return The index of a level.
69-
*/
70-
public static EnumEnchantmentLevel get(Integer level) {
71-
return lookup.containsKey(level) ? lookup.get(level) : null;
72-
}
73-
74-
private int level;
75-
private String unlocalizedName;
7676
}

src/main/java/com/meowj/langutils/lang/convert/EnumEntity.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,21 @@ public enum EnumEntity {
7070
MINECART(EntityType.MINECART, "entity.Minecart.name"),
7171
BOAT(EntityType.BOAT, "entity.Boat.name");
7272

73-
public String getUnlocalizedName() {
74-
return unlocalizedName;
75-
}
76-
77-
public EntityType getType() {
78-
return type;
79-
}
80-
8173
private static final Map<EntityType, EnumEntity> lookup = new HashMap<EntityType, EnumEntity>();
8274

8375
static {
8476
for (EnumEntity entity : EnumSet.allOf(EnumEntity.class))
8577
lookup.put(entity.getType(), entity);
8678
}
8779

80+
private EntityType type;
81+
private String unlocalizedName;
82+
83+
EnumEntity(EntityType type, String unlocalizedName) {
84+
this.type = type;
85+
this.unlocalizedName = unlocalizedName;
86+
}
87+
8888
/**
8989
* @param entityType The Entity type.
9090
* @return The index of an entity based on entity type
@@ -107,12 +107,12 @@ public static String getSpawnEggName(ItemStack egg, String locale) {
107107
: LanguageHelper.translateToLocal("item.monsterPlacer.name", locale);
108108
}
109109

110-
EnumEntity(EntityType type, String unlocalizedName) {
111-
this.type = type;
112-
this.unlocalizedName = unlocalizedName;
110+
public String getUnlocalizedName() {
111+
return unlocalizedName;
113112
}
114113

115-
private EntityType type;
116-
private String unlocalizedName;
114+
public EntityType getType() {
115+
return type;
116+
}
117117

118118
}

src/main/java/com/meowj/langutils/lang/convert/EnumItem.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -531,30 +531,16 @@ public enum EnumItem {
531531
GOLD_HORSE_ARMOR(Material.GOLD_BARDING, "item.horsearmorgold.name"),
532532
DIAMOND_HORSE_ARMOR(Material.DIAMOND_BARDING, "item.horsearmordiamond.name");
533533

534-
private Material material;
535-
private int metadata;
536-
private String unlocalizedName;
537-
538-
/**
539-
* @return The unlocalized name of the item.
540-
*/
541-
public String getUnlocalizedName() {
542-
return unlocalizedName;
543-
}
534+
private static final Map<ItemEntry, EnumItem> lookup = new HashMap<ItemEntry, EnumItem>();
544535

545-
/**
546-
* @return The metadata(damage value, durability) of the item.
547-
*/
548-
public int getMetadata() {
549-
return metadata;
536+
static {
537+
for (EnumItem item : EnumSet.allOf(EnumItem.class))
538+
lookup.put(new ItemEntry(item.material, item.getMetadata()), item);
550539
}
551540

552-
/**
553-
* @return The {@link Material} of the item.
554-
*/
555-
public Material getMaterial() {
556-
return material;
557-
}
541+
private Material material;
542+
private int metadata;
543+
private String unlocalizedName;
558544

559545
/**
560546
* Create an index of an item
@@ -569,14 +555,6 @@ public Material getMaterial() {
569555
this(material, 0, unlocalizedName);
570556
}
571557

572-
573-
private static final Map<ItemEntry, EnumItem> lookup = new HashMap<ItemEntry, EnumItem>();
574-
575-
static {
576-
for (EnumItem item : EnumSet.allOf(EnumItem.class))
577-
lookup.put(new ItemEntry(item.material, item.getMetadata()), item);
578-
}
579-
580558
/**
581559
* Get the index of an item based on {@link ItemEntry}.
582560
*
@@ -595,4 +573,25 @@ public static String getPlayerSkullName(ItemStack skull, String locale) {
595573
meta.getOwner());
596574
} else return LanguageHelper.translateToLocal("item.skull.char.name", locale);
597575
}
576+
577+
/**
578+
* @return The unlocalized name of the item.
579+
*/
580+
public String getUnlocalizedName() {
581+
return unlocalizedName;
582+
}
583+
584+
/**
585+
* @return The metadata(damage value, durability) of the item.
586+
*/
587+
public int getMetadata() {
588+
return metadata;
589+
}
590+
591+
/**
592+
* @return The {@link Material} of the item.
593+
*/
594+
public Material getMaterial() {
595+
return material;
596+
}
598597
}

0 commit comments

Comments
 (0)