Skip to content

Commit c7b9718

Browse files
committed
Improve translation of Regen, fixes #37
1 parent 122b1c9 commit c7b9718

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/main/java/me/pikamug/localelib/LocaleManager.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,17 +427,24 @@ public String queryMaterial(final Material material, final short durability, fin
427427
matKey = "block.minecraft." + material.name().toLowerCase();
428428
} else {
429429
try {
430-
final Method m = craftMagicNumbers.getDeclaredMethod("getItem", material.getClass());
431-
m.setAccessible(true);
432-
final Object item = m.invoke(craftMagicNumbers, material);
430+
final Method itemMethod = craftMagicNumbers.getDeclaredMethod("getItem", material.getClass());
431+
itemMethod.setAccessible(true);
432+
final Object item = itemMethod.invoke(craftMagicNumbers, material);
433433
if (item == null) {
434434
throw new IllegalArgumentException(material.name() + " material could not be queried!");
435435
}
436-
matKey = (String) resolveMethod(itemClazz, "getDescriptionId", "a", "getName", "j", "l").invoke(item);
436+
final Method keyMethod = resolveMethod(itemClazz, "getDescriptionId", "a", "getName", "j", "l");
437+
if (keyMethod == null) {
438+
throw new IllegalArgumentException("Could not get description ID for " + itemClazz.getName());
439+
}
440+
matKey = (String) keyMethod.invoke(item);
437441
if (meta instanceof PotionMeta) {
438442
matKey += ".effect." + ((PotionMeta)meta).getBasePotionData().getType().name().toLowerCase()
439-
.replace("regen", "regeneration").replace("speed", "swiftness").replace("jump", "leaping")
443+
.replace("speed", "swiftness").replace("jump", "leaping")
440444
.replace("instant_heal", "healing").replace("instant_damage", "harming");
445+
if (!matKey.contains("regeneration")) {
446+
matKey = matKey.replace("regen", "regeneration");
447+
}
441448
}
442449
} catch (final Exception ex) {
443450
throw new IllegalArgumentException("[LocaleLib] Unable to query Material: " + material.name(), ex);

0 commit comments

Comments
 (0)