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

Enchantment error

Discussion in 'Development' started by alexwolf_dev, Nov 25, 2017.

  1. alexwolf_dev

    alexwolf_dev Spider Jockey

    Messages:
    43
    GitHub:
    Frago9876543210
    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($name85);
            
    $enchantment Enchantment::getEnchantment(mt_rand(026));
            
    $enchantment->setLevel(1);
            
    $item->addEnchantment($enchantment);
            
    $p->getInventory()->setItemInHand($item);
        }
    }
    Code:
    Error: "Call to a member function setLevel() on null
     
  2. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    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 :p
    Click here

    Install it and it will fix your problem (Except Enchants with ID 23, 24, 25, 26)
     
  3. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Lol.
     
  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.