Solved EnchantmentInstance Doesnt work

Discussion in 'Development' started by xXNiceAssassinlo YT, May 15, 2018.

  1. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    619
    GitHub:
    xXNiceYT
    PHP:

        
    public function getElite(Player $player){
            if(!
    $player->hasPermission("kit.elite") && !$player->isOp()){
                
    $player->sendMessage(C::RED "You don't have " C::BLUE "Elite " C::RED "Rank.");
                return;
            }
            
    $inv $player->getInventory();
            
    $armor =$player->getArmorInventory();
            
    $this->clearEffect($player);
            
    $inv->clearAll();
            
    //Armor
            
    $helmet Item::get(306); //Iron Helmet
            
    $helmet->addEnchantment($this->Enchant(01));
            
    $chestplate Item::get(307); //Iron Chestplate
            
    $chestplate->addEnchantment($this->Enchant(01));
            
    $legging Item::get(308); //Iron Legging
            
    $legging->addEnchantment($this->Enchant(01));
            
    $boot Item::get(309); //Iron Boot
            
    $boot->addEnchantment($this->Enchant(01));
            
    $sword Item::get(276); //Diamond Sword
            
    $sword->addEnchantment($this->Enchant(91));

            
    $armor->setHelmet($helmet);
            
    $armor->setChestplate($chestplate);
            
    $armor->setLeggings($legging);
            
    $armor->setBoots($boot);
            
    //Item in hand
            
    $inv->addItem(Item::get(276));
            
    $inv->addItem(Item::get(32212)); //2x Enchanted Golden Apple
            //Message
            
    $player->sendMessage(C::BLUE "Selected " C::LIGHT_PURPLE"Elite " C::BLUE "Kit!");
        }

        public function 
    Enchant(int $enchantmentint $level): EnchantmentInstance{
            return new 
    EnchantmentInstance(Enchantment::getEnchantment($enchantment), $level);
        }
    error
    PHP:
     Unhandled exception executing command 'kit Elite' in kitArgument 1 passed to pocketmine\item\enchantment\EnchantmentInstance::__construct() must be an instance of pocketmine\item\enchantment\Enchantmentnull givencalled in C:\Users\xxnic\OneDrive\Desktop\Server\plugins\ExonCore-Main\src\ExonCore\Kit\Kit.php on line 230
    [14:51:10] [Server thread/CRITICAL]: TypeError"Argument 1 passed to pocketmine\item\enchantment\EnchantmentInstance::__construct() must be an instance of pocketmine\item\enchantment\Enchantment, null given, called in C:\Users\xxnic\OneDrive\Desktop\Server\plugins\ExonCore-Main\src\ExonCore\Kit\Kit.php on line 230" (EXCEPTIONin "src/pocketmine/item/enchantment/EnchantmentInstance" at line 41
     
  2. Muqsit

    Muqsit Wither Skeleton Verified

    Messages:
    1,395
    GitHub:
    muqsit
    You haven't registered enchantment with id 9.
     
    xXNiceAssassinlo YT and RyanShaw like this.
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    619
    GitHub:
    xXNiceYT
    Thx
     

Share This Page

  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.