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

Call to a member function getTiles() on null

Comments in 'Plugin Development' started by myst02, Jun 27, 2015.

  1. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Hi,

    my plugin crashes with the following crash dump:

    Code:
    PocketMine-Soft Crash Dump Sat Jun 27 15:55:48 AWST 2015
    
    Error: Call to a member function getTiles() on null
    File: /SuperPE SG/src/SuperPE/Main
    Line: 130
    Type: E_ERROR
    
    THIS CRASH WAS CAUSED BY A PLUGIN
    BAD PLUGIN: SG v1
    
    Code:
    [121]  public function getNextSpawn(){
    [122]  $this->spawns++;
    [123]  $x = $this->prefs->get('spawn_locs')[$this->spawns][0];
    [124]  $y = $this->prefs->get('spawn_locs')[$this->spawns][1];
    [125]  $z = $this->prefs->get('spawn_locs')[$this->spawns][2];
    [126]  return (new Vector3($x, $y, $z));
    [127]  }
    [128]
    [129]  public function refillChests(){
    [130]  foreach($this->getServer()->getLevelByName($this->prefs->get("world"))->getTiles() as $t){
    [131]  if($t instanceof Chest){
    [132]  if($t->isPaired()){
    [133]  $inv = $t->getInventory();
    [134]  }else{
    [135]  $inv = $t->getRealInventory();
    [136]  }
    [137]  $inv->clearAll();
    [138]  foreach($this->prefs->get('chest_items') as $i){
    [139]  $inv->addItem(Item::get($i[0], $i[1], $i[2]));
    [140]  }
    
    Backtrace:
    #0 /src/pocketmine/Server__32bit(0): pocketmine\Server->crashDump()
    #1 /SuperPE SG/src/SuperPE/Main(80): SuperPE\Main->refillChests()
    #2 /SuperPE SG/src/SuperPE/Main(69): SuperPE\Main->StartGame()
    #3 /src/pocketmine/plugin/PluginBase(86): SuperPE\Main->onEnable()
    #4 /DevTools_v1.10.0.phar/src/FolderPluginLoader/FolderPluginLoader(125): pocketmine\plugin\PluginBase->setEnabled()
    #5 /src/pocketmine/plugin/PluginManager(562): FolderPluginLoader\FolderPluginLoader->enablePlugin()
    #6 /src/pocketmine/Server__32bit(2030): pocketmine\plugin\PluginManager->enablePlugin()
    #7 /src/pocketmine/Server__32bit(2016): pocketmine\Server->enablePlugin()
    #8 /src/pocketmine/Server__32bit(1832): pocketmine\Server->enablePlugins()
    #9 /src/pocketmine/PocketMine(458): pocketmine\Server->__construct()
    #10 (1): ()
    #11 (0): {main}()
    
    PocketMine-MP version: 1.5dev #245 [Protocol 27; API 1.12.0]
    Git commit: 0000000000000000000000000000000000000000
    uname -a: Windows NT LEGOBOY 6.1 build 7601 (Windows 7 Home Premium Edition Service Pack 1) i586
    PHP Version: 5.6.6
    Zend version: 2.6.0
    OS : WINNT, win
    
    Loaded plugins:
    DevTools 1.10.0 by PocketMine Team for API(s) 1.3.1
    ManyWorlds 1.3.4 by aliuly for API(s) 1.10.0
    SG 1 by SuperPE Network for API(s) 1.12.0
    

    Can anyone help me? I have no idea how to fix it.
  2. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    A array?
    myst02 likes this.
  3. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    I'll try.
    Legoboy0215 likes this.
  4. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    What does $this->prefs->get("world") return?
    PEMapModder likes this.
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    string I think
  6. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    I know it returns a string, but what value does it return.
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    The config is like this:
    world: world
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    And are you sure that functions return "world", and are you sure that world exists? A plugin should always check the correctness of the config file
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    yes, it exist..
  10. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    @PEMapModder I can send you full plugin code in PM, but please don't share.
  11. Intyre
    Offline

    Intyre Staff Member PocketMine Team

    Joined:
    Aug 24, 2013
    Posts:
    118
    Minecraft User:
    Intyre
    Why don't you check for null and return when it is null?

    Code:
    if ($this->getServer()->getLevelByName($this->prefs->get("world")) === null) {
    return
    }
    PEMapModder likes this.
  12. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    I'll try it. Thank you! :)
  13. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
    That code looks pretty similar to @luca28pet's SimpleHungerGames
  14. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    He made it himself... I am sure because I am the bug fixer...
  15. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    I did it myself.
  16. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
  17. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Chest refill code is all the same. It may look like I just ripped off but I coded it myself.
  18. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
    Ok

Share This Page

Advertisement