Solved Why are the enchantments being removed?

Discussion in 'Plugin Development' started by Gonmarte, May 6, 2016.

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

    Gonmarte

    My point is to delete the meta (lore, the name....) of an item and keep the enchanements, durabilirt and material.
    Why the enchatments are not being saved?
    Code:
                    Material clonedMaterial = item.getType();
                    short clonedDurability = item.getDurability();
                    Map<Enchantment, Integer> clonedEnchantments = item.getEnchantments();
                    ItemStack clonedItem = new ItemStack(clonedMaterial);
                    item.setDurability(clonedDurability);
                    for(Entry<Enchantment, Integer> e : clonedEnchantments.entrySet()){
                        item.addEnchantment(e.getKey(), e.getValue());
                    }
     
  2. Offline

    I Al Istannen

    @Gonmarte
    If you want to clear the itemmeta just use ItemStack#setItemMeta(null).
    I think it will preserve enchantments, but you will need to try.

    Edit. Ok, it probably wont.

    EDIT 2: You could change "item" to "clonedItem" in the last two lines.
     
  3. Offline

    Gonmarte

    It wont :p
     
  4. Offline

    I Al Istannen

    @Gonmarte
    Just reload the page and see my second edit.
     
    Gonmarte likes this.
  5. Offline

    Gonmarte

    My bad :3
    Didnt notice that.
    Thanks!
     
    I Al Istannen likes this.
Thread Status:
Not open for further replies.

Share This Page