So I need a way to make it so everytime someone crafts with this Enderpearl it loses 1 durability and it gives it back with 1 less durability and when it reaches 0 durability it doesn't give it back to you Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler int durability = 1552; ItemStack ender = new ItemStack(Material.ENDER_PEARL); ItemMeta meta = ender.getItemMeta(); meta.setLore(Arrays.asList(ChatColor.GRAY + "Durability" + durability + " / 1552")); meta.setDisplayName(ChatColor.DARK_RED + "Ender Pearl"); meta.addEnchant(Enchantment.ARROW_INFINITE, 1, true); ender.setItemMeta(meta); 1 Hour Bump :3 EDIT by Moderator: merged posts, please use the edit button instead of double posting.
MagicMan aw man, don't one hour bump! Leave at least a day. On topic: You do realise enderpearls don't have durability, right? Only weapons and tools do. Use metadata. EDIT: Also for that .addEnchantment use .addUnsafeEnchantment instead. Otherwise you'll get an error.
Ah ok and sorry bout that. I didn't actually give the enderpearl durability. I set his lore to say Durability 1552/1552. I need a way to change the enderpearls lore everytime I craft with it and it gives it back
Get the item's lore, split it according to spaces or whatever, extract the number, substract, string the result back together and set lore.
Ok ill try this out.. Ok now before I try this out is this the code I don't want any errors Code: meta.setLore(Arrays.asList(ChatColor.GRAY + "Durability: " + durability + " / 1552".substring(durability, 1))); EDIT by Moderator: merged posts, please use the edit button instead of double posting.
MagicMan You don't do the substring inside the final output. Technically speaking you don't really need a substring at all, it was just one of the ways to use it, but it looks like it may be confusing you. The substring takes two int that represent characters in the string you are splitting. The first one is the character you start with -1, and the second is the last character you want in the sequence. If you only want the starting point, only give the parameters one int. i.e. String d = "durability"; String s = d.substring(0, 4); return s; This would give is the string "dura".