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

Help error Chest::getSize()

Discussion in 'Plugin Help' started by Mochi, May 13, 2020.

  1. Mochi

    Mochi Baby Zombie

    Messages:
    113
    Error: "Call to undefined method pocketmine\tile\Chest::getSize()" (EXCEPTION) in "plugins/Sw/src/svile/sw/SWarena" at line 311

    Code :

    PHP:
    private function refillChests()
        {
            
    $contents $this->pg->getChestContents();
            foreach (
    $this->pg->getServer()->getLevelByName($this->world)->getTiles() as $tile) {
                if (
    $tile instanceof Chest) {
                    
    //CLEARS CHESTS
                    
    for ($i 0$i $tile->getSize(); $i++) {  #Line: 311
                        
    $tile->getInventory()->setItem($iItem::get(0));
                    }
                    
    //SET CONTENTS
                    
    if (empty($contents))
                        
    $contents $this->pg->getChestContents();
                    foreach (
    array_shift($contents) as $key => $val) {
                        if(
    $val[0] == Item::SPLASH_POTION) {
                            
    $item = new SplashPotion();
                            
    $r mt_rand(15);
                            if(
    $r == 1){
                              
    $item Item::get(438101);
                            }
                            if(
    $r == 2){
                              
    $item Item::get(438151);
                            }
                            if(
    $r == 3){
                              
    $item Item::get(438281);
                            }
                            if(
    $r == 4){
                              
    $item Item::get(438251);
                            }
                            if(
    $r == 5){
                              
    $item Item::get(438211);
                            }
                        } else
                            
    $item Item::get($val[0], 0$val[1]);
                        
    $tile->getInventory()->setItem($key$item);
                        }

                    foreach (
    array_shift($contents) as $key => $val) {
                        if(
    $val[0] == Item::WOOL) {
                            
    $item = new \pocketmine\item\IronSword();
                            
    $item->addEnchantment(Enchantment::getEnchantment(9)->setLevel(mt_rand(12)));
                        } else
                            
    $item Item::get($val[0], 0$val[1]);
                            
                              if(
    $item->getId() == Item::STONE_SWORD || $item->getId() == Item::IRON_SWORD || $item->getId() == Item::DIAMOND_SWORD){
                                    
    $rand mt_rand(12);
                                    
    $enchants = array(91011121314);
                                      if(
    $rand == 1){
                                     
    $item->addEnchantment(Enchantment::getEnchantment($enchants[array_rand($enchants)])->setLevel(mt_rand(12)));
                                     
    $tile->getInventory()->setItem($key$item);
                                   }else{
                                     
    $tile->getInventory()->setItem($key$item);
                                   }
                              }
                              if(
    $item->getId() == Item::STONE_PICKAXE || $item->getId() == Item::IRON_PICKAXE || $item->getId() == Item::DIAMOND_PICKAXE || $item->getId() == Item::STONE_AXE || $item->getId() == Item::IRON_AXE || $item->getId() == Item::DIAMOND_AXE){
                                    
    $rand mt_rand(12);
                                    
    $enchants = array(1517);
                                      if(
    $rand == 1){
                                     
    $item->addEnchantment(Enchantment::getEnchantment($enchants[array_rand($enchants)])->setLevel(mt_rand(12)));
                                     
    $tile->getInventory()->setItem($key$item);
                                   }else{
                                     
    $tile->getInventory()->setItem($key$item);
                                   }
                              }
                              if(
    $item->getId() == Item::CHAIN_HELMET || $item->getId() == Item::CHAIN_CHESTPLATE || $item->getId() == Item::CHAIN_LEGGINGS || $item->getId() == Item::CHAIN_BOOTS || $item->getId() == Item::IRON_HELMET || $item->getId() == Item::IRON_CHESTPLATE || $item->getId() == Item::IRON_LEGGINGS || $item->getId() == Item::IRON_BOOTS || $item->getId() == Item::DIAMOND_HELMET || $item->getId() == Item::DIAMOND_CHESTPLATE || $item->getId() == Item::DIAMOND_LEGGINGS || $item->getId() == Item::DIAMOND_BOOTS){
                                    
    $rand mt_rand(12);
                                    
    $enchants = array(0145);
                                      if(
    $rand == 1){
                                     
    $item->addEnchantment(Enchantment::getEnchantment($enchants[array_rand($enchants)])->setLevel(mt_rand(12)));
                                     
    $tile->getInventory()->setItem($key$item);
                                   }else{
                                     
    $tile->getInventory()->setItem($key$item);
                                   }
                              }
                              if(
    $item->getId() == 261){
                                    
    $rand mt_rand(12);
                                    
    $enchants = array(192021);
                                      if(
    $rand == 1){
                                     
    $item->addEnchantment(Enchantment::getEnchantment($enchants[array_rand($enchants)])->setLevel(mt_rand(12)));
                                     
    $tile->getInventory()->setItem($key$item);
                                   }else{
                                     
    $tile->getInventory()->setItem($key$item);
                                   }
                              }
                    }
                 }
            }
            unset(
    $contents$tile);
        }
     
  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.