Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Set/Send Armor Contents

Comments in 'Plugin Development' started by CrazedMiner, May 8, 2015.

  1. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I'm trying to set and send the Player armor and its not working :/
    If anyone could tell me what to do to fix this problem that'd be great :)

    My Code:
    Code:
            $event->getPlayer()->getInventory()->setHelmet(Item::get(298));
            $event->getPlayer()->getInventory()->setChestplate(Item::get(299));
            $event->getPlayer()->getInventory()->setLeggings(Item::get(300));
            $event->getPlayer()->getInventory()->setBoots(Item::get(301));
            $event->getPlayer()->getInventory()->sendArmorContents($event->getPlayer()->getName());
    Console Error:
    19:35:27 [CRITICAL] Could not pass event pocketmine\event\player\PlayerJoinEvent to CrazedCraftCore vBuild_1.0: Invalid argument supplied for foreach() on CrazedMiner\EventsListener
    19:35:27 [WARNING] RuntimeException: "Invalid argument supplied for foreach()" (E_WARNING) in "/src/pocketmine/inventory/PlayerInventory" at line 333
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why getName()? $event->getPlayer() returns a Player object, and if you $player->getName(), it returns a string! You should pass a Player object (or an array of them) not a string to sendArmorContents()!
  3. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I've been through other posts that have
    PHP:
    $event->getPlayer()->getInventory()->sendArmorContents("steve");
    and assumed I needed the Players name but thanks for the help it works now :D
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Those posts are wrong. Where are they?
    Look at the docs instead.
    CrazedMiner and HotFireyDeath like this.
  5. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I did and it said $target and me being a noob assumed it need to get the name but now I know that getName() returns a string :p

Share This Page

Advertisement