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

Call to a member function getInventory() on null

Discussion in 'Development' started by Junkdude, Dec 2, 2016.

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    So I get this error:
    [00:16:07] [Server thread/CRITICAL]: Could not execute task Sean_M\LootCrate\LootCrate: Call to a member function getInventory() on null
    [00:16:07] [Server thread/CRITICAL]: Error: "Call to a member function getInventory() on null" (EXCEPTION) in "/plugins/LootCrate-master/src/Sean_M/LootCrate/LootCrate" at line 38

    This is my code:
    PHP:
    <?php

    namespace Sean_M\LootCrate;

    use 
    pocketmine\block\Block;
    use 
    pocketmine\inventory\Inventory;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\utils\TextFormat as TF;
    use 
    pocketmine\Server;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\math\Vector3;

    class 
    LootCrate extends PluginTask implements listener {

      
    ##Rhorerien LEVEL NAME FOR REFERENCE

      ##$this->getOwner()->getServer()

       
    public $plugin;

          public function 
    __construct(Main $plugin) {
             
    parent::__construct($plugin);
             
    $this->plugin $plugin;
          }

          public function 
    onRun($currentTick) {
             
    $level $this->getOwner()->getServer()->getLevelByName("Rhorerien");
              
    $x mt_rand(0,255);
              
    $y mt_rand(0,255);
              
    $z mt_rand(0,255);
              
    $pos = new Vector3($x$y$z);
              
    $block Block::get(Block::CHEST);
              
    $level->setBlock($pos$block);
              
    $chest $level->getTile($pos);
              
    $slot mt_rand(0,27);
              foreach(
    $this->getOwner()->getconfig()->get("items") as $item){
              
    $chest->getInventory()->setItem($slot$item);
              
    $cx $chest->getX();
              
    $cy $chest->getY();
              
    $cz $chest->getZ();
              
    $cpos = new Vector3($cx$cy$cz);
              if(
    $this->config->get("broadcast.message") == "true"){
                
    $this->getServer()->broadcastMessage($this->config->get("message"str_replace("{CHEST}"$cpos)));
              }
              }
      }
    }
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    There is no chest tile at $pos
    You tried to set a chest block, but not a tile. Please check the chest code in PM on how to create a tile
     
    Last edited: Dec 3, 2016
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Can you show me the code/how?
     
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
  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.