1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Plugin addEnchantment() Error

Discussion in 'Development' started by #A6543, Dec 21, 2016.

  1. #A6543

    #A6543 Zombie

    Messages:
    267
    Hi,
    I have a problem with addEnchantment.
    If I add the Item to the players inventory without an Enchantment it works...

    The Code:
    PHP:
    $killer->getInventory()->setItem(0Item::get(27101)->addEnchantment(Enchantment::getEnchantment(12)->setLevel(1)));
    Error:
    Code:
    Argument 2 passed to pocketmine\inventory
    \PlayerInventory::setItem() must be an instance of pock
    etmine\item\Item, null given
    
    I hope someone could help me :p
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    addEnchantment does not return the item object.
    It just modifies the object.
    PHP:
    $item Item::get(27101);
    $item->addEnchantment(Enchantment::getEnchantment(12)->setLevel(1));
    $killer->getInventory()->setItem(0$item);
     
    SOFe, #A6543 and HimbeersaftLP like this.
  3. #A6543

    #A6543 Zombie

    Messages:
    267
    Thanks. Now it works!
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.