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

Solved Error with the new pocketmine

Discussion in 'Development' started by KHAV, Feb 9, 2018.

  1. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    Hello,

    When I installed the new pocketmine(3.0.0-ALPHA11) I had an error with my plugin:
    PHP:
    [23:45:08] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'SpaceLife v1.0.0'Call to undefined method pocketmine\item\enchantment\ProtectionEnchantment::setLevel() on SpaceLife\Main
    [23:45:08] [Server thread/CRITICAL]: Error"Call to undefined method pocketmine\item\enchantment\ProtectionEnchantment::setLevel()" (EXCEPTIONin "SpaceLife/src/SpaceLife/Main" at line 194
    How I can fix it?:(
     
  2. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    You need to use the EnchantmentInstance class now.

    Example:
    PHP:
    //All used classes are located in the namespace pocketmine\item\enchantment

    $enchantment Enchantment::getEnchantment(Enchantment::PROTECTION);
    $level 10;

    $item->addEnchantment(new EnchantmentInstance($enchantment$level));
     
  3. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    what is this now?:
    PHP:
    Call to undefined method pocketmine\inventory\PlayerInventory::setHelmet()
    [
    12:18:31] [Server thread/CRITICAL]: Error"Call to undefined method pocketmine\inventory\PlayerInventory::setHelmet()" (EXCEPTIONin "SpaceLIfe/src/SpaceLife/Main" at line 287
    this is the code:
    PHP:
    [282$item Item::get(30201);
    [
    283$item->setCustomName("§9Space §fHelmet");
    [
    284]            $enchantment Enchantment::getEnchantment(Enchantment::PROTECTION);
    [
    285]            $level 10;
    [
    286$item->addEnchantment(new EnchantmentInstance($enchantment$level));
    [
    287$sender->getInventory()->setHelmet($item);
     
  4. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    You're using the wrong inventory.
    This would be correct:
    PHP:
    $sender->getArmorInventory()->setHelmet($item);
     
  5. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    Okay it is work but if i want to remove the helmet from the player the console send for me:
    PHP:
    [16:25:23] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'SpaceLife v1.0.0'Argument 1 passed to pocketmine\item\Item::getEnchantment() must be of the type integerobject givencalled in C:\Users\Reem\Desktop\PocketMine-MP\plugins\SpaceLife\src\SpaceLife\Main.php on line 205 on SpaceLife\Main
    [16:25:23] [Server thread/CRITICAL]: TypeError"Argument 1 passed to pocketmine\item\Item::getEnchantment() must be of the type integer, object given, called in C:\Users\Reem\Desktop\PocketMine-MP\plugins\SpaceLife\src\SpaceLife\Main.php on line 205" (EXCEPTIONin "src/pocketmine/item/Item" at line 316
    This is my code:
    PHP:
    [201$item Item::get(30201);
    [
    202]$item->setCustomName("§9Space §fHelmet");
    [
    203$enchantment Enchantment::getEnchantment(Enchantment::PROTECTION);
    [
    204$level 10;
    [
    205$item->getEnchantment(new EnchantmentInstance($enchantment$level)); //Here is the proplem:/
    [206$player->getArmorInventory()->remove($item);
     
  6. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    :facepalm:
    Why did you even change $item->addEnchantment() to $item->getEnchantment()?
     
  7. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    Oh that was my mistake sorry xD, thank you , solved
     
  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.