Solved Can't add enchanted item to player's inventory?

Discussion in 'Plugin Development' started by Didi1150, Sep 1, 2020.

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

    Didi1150

    I am doing a shop where you can buy items. However, if the player wants to buy an enchanted pickaxe, it gives him a regular pickaxe. I'm giving the player the Itemstacks I use to set the shop. Why can't I add an enchanted item to the player's inventory?
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Didi1150 How are you giving the enchanted items?
     
  3. Offline

    Didi1150

    I'm creating an ItemStack:

    ItemStack item = new ItemStack(Material.Pickaxe);


    then I enchant it:
    ItemMeta itemMeta = item.getItemMeta();
    itemMeta.addEnchantment(Enchantment.DIG_SPEED, 1);
    item.setItemMeta(itemMeta);

    then I add it to the player's inventory:

    player.getInventory().addItem(item);
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    Didi1150

    public void buyItem(Player player, ItemStack result){
    player.getInventory.addItem(result);

    }

    And the Item is:
    new ItemBuilder(Material.WOOD_PICKAXE).addEnchantment(Enchantment.DIG_SPEED, 1).build();

    EDIT: Sry for double Posting, I forgot about it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
Thread Status:
Not open for further replies.

Share This Page