Java Code Examples for org.bukkit.inventory.meta.ItemMeta#hasLocalizedName()

The following examples show how to use org.bukkit.inventory.meta.ItemMeta#hasLocalizedName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShopInventory.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static String getNameOrCustomNameOfItem(ItemStack stack) {
	try {
		if (stack.hasItemMeta()) {
			ItemMeta meta = stack.getItemMeta();
			if (meta == null) {
				return "";
			}

			if (meta.hasDisplayName()) {
				return meta.getDisplayName();
			}
			if (meta.hasLocalizedName()) {
				return meta.getLocalizedName();
			}
		}
	} catch (Throwable ignored) {
	}

	String normalItemName = stack.getType().name().replace("_", " ").toLowerCase();
	String[] sArray = normalItemName.split(" ");
	StringBuilder stringBuilder = new StringBuilder();

	for (String s : sArray) {
		stringBuilder.append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).append(" ");
	}
	return stringBuilder.toString().trim();
}
 
Example 2
Source File: Util.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get ItemStack's local name, return null if failed to get.
 *
 * @param itemStack Target ItemStack
 * @return LocalName or NULL
 */
@Nullable
public static String getLocalizedName(@NotNull ItemStack itemStack) {
    ItemMeta itemMeta = itemStack.getItemMeta();
    if (itemMeta == null) {
        return null;
    }
    if (!itemMeta.hasLocalizedName()) {
        return null;
    }
    return itemMeta.getLocalizedName();
}
 
Example 3
Source File: ShopInventory.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static String getNameOrCustomNameOfItem(ItemStack stack) {
	try {
		if (stack.hasItemMeta()) {
			ItemMeta meta = stack.getItemMeta();
			if (meta == null) {
				return "";
			}

			if (meta.hasDisplayName()) {
				return meta.getDisplayName();
			}
			if (meta.hasLocalizedName()) {
				return meta.getLocalizedName();
			}
		}
	} catch (Throwable ignored) {
	}

	String normalItemName = stack.getType().name().replace("_", " ").toLowerCase();
	String[] sArray = normalItemName.split(" ");
	StringBuilder stringBuilder = new StringBuilder();

	for (String s : sArray) {
		stringBuilder.append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).append(" ");
	}
	return stringBuilder.toString().trim();
}