Why is the item not enchanted every time? Code works, but not always. PHP: if($item->getId() !== Item::AIR){ if($item instanceof Tool or $item instanceof Armor){ $this->main->eco->delMoney($name, 85); $enchantment = Enchantment::getEnchantment(mt_rand(0, 26)); $enchantment->setLevel(1); $item->addEnchantment($enchantment); $p->getInventory()->setItemInHand($item); }} Code: Error: "Call to a member function setLevel() on null
It simply explains that the enchantment isn't registered. I recommend use any plugin that implements enchants. But if you don't know any, use mine instead Click here Install it and it will fix your problem (Except Enchants with ID 23, 24, 25, 26)