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($i, Item::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(1, 5);
                            if(
    $r == 1){
                              
    $item = Item::get(438, 10, 1);
                            }
                            if(
    $r == 2){
                              
    $item = Item::get(438, 15, 1);
                            }
                            if(
    $r == 3){
                              
    $item = Item::get(438, 28, 1);
                            }
                            if(
    $r == 4){
                              
    $item = Item::get(438, 25, 1);
                            }
                            if(
    $r == 5){
                              
    $item = Item::get(438, 21, 1);
                            }
                        } 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(1, 2)));
                        } 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(1, 2);
                                    
    $enchants = array(9, 10, 11, 12, 13, 14);
                                      if(
    $rand == 1){
                                     
    $item->addEnchantment(Enchantment::getEnchantment($enchants[array_rand($enchants)])->setLevel(mt_rand(1, 2)));
                                     
    $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(1, 2);
                                    
    $enchants = array(15, 17);
                                      if(
    $rand == 1){
                                     
    $item->addEnchantment(Enchantment::getEnchantment($enchants[array_rand($enchants)])->setLevel(mt_rand(1, 2)));
                                     
    $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(1, 2);
                                    
    $enchants = array(0, 1, 4, 5);
                                      if(
    $rand == 1){
                                     
    $item->addEnchantment(Enchantment::getEnchantment($enchants[array_rand($enchants)])->setLevel(mt_rand(1, 2)));
                                     
    $tile->getInventory()->setItem($key, $item);
                                   }else{
                                     
    $tile->getInventory()->setItem($key, $item);
                                   }
                              }
                              if(
    $item->getId() == 261){
                                    
    $rand = mt_rand(1, 2);
                                    
    $enchants = array(19, 20, 21);
                                      if(
    $rand == 1){
                                     
    $item->addEnchantment(Enchantment::getEnchantment($enchants[array_rand($enchants)])->setLevel(mt_rand(1, 2)));
                                     
    $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.