Use localizedName for itemI18n default value if avaliable.

Former-commit-id: b83c073754069401fbc77c7d379b458e2e2fda90 [formerly 353a8b78190b37cd9d8e6f02da0506532a561a26]
Former-commit-id: 48d185c3b607f38830f93cf9aa58990026f94168
This commit is contained in:
Ghost_chu committed 2019-06-09 22:46:06 +08:00
1 parent 47ee9bbdd1
commit bc4bd89ffe
2 files changed
+21 -2

No files matched your search

@@ -441,8 +441,12 @@ public class MsgUtil {
if (itemi18nString != null && !itemi18nString.isEmpty())
continue;
String itemName = material.name();
itemi18n.set("itemi18n." + itemName, Util.prettifyText(itemName));
plugin.getLogger().info("Found new items/blocks [" + Util.prettifyText(itemName) + "] ,adding it in config...");
String lastItemName = Util.prettifyText(itemName);
String localizedName = Util.getLocalizedName(new ItemStack(material));
if (localizedName != null)
lastItemName = localizedName;
itemi18n.set("itemi18n." + itemName, lastItemName);
plugin.getLogger().info("Found new items/blocks [" + Util.prettifyText(lastItemName) + "] ,adding it in config...");
}
try {
itemi18n.save(itemi18nFile);
@@ -383,6 +383,21 @@ public class Util {
return sb.toString();
}
/**
* Get ItemStack's local name, return null if failed to get.
*
* @param itemStack Target ItemStack
* @return LocalName or NULL
*/
public static String getLocalizedName(@NotNull ItemStack itemStack) {
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null)
return null;
if (!itemMeta.hasLocalizedName())
return null;
return itemMeta.getLocalizedName();
}
/**
* Get item's sign name for display on the sign.
*