ItemMeta So Hard 2

Discussion in 'Plugin Development' started by MagicMan, Apr 8, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    MagicMan

    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


    Show 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.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    iPoke111

    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.
     
  3. Offline

    MagicMan


    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
     
  4. Offline

    MagicMan

    24 Hour Bump :3
     
  5. Offline

    Benlewis9000

    What exactly are you trying to craft with an ender pearl?
     
  6. Offline

    Zethariel

    Get the item's lore, split it according to spaces or whatever, extract the number, substract, string the result back together and set lore.
     
    Benlewis9000 likes this.
  7. Offline

    Benlewis9000

    and if you didn't know how you will need to use .substring() on the items lore.
     
  8. Offline

    MagicMan

    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.
     
    Last edited by a moderator: Jun 7, 2016
  9. Offline

    Benlewis9000

    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".
     
Thread Status:
Not open for further replies.

Share This Page