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

Solved Fatal error: Call to a member function setBlock()

Comments in 'Plugin Development' started by TheKillerTacos, Feb 8, 2016.

  1. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    Help, im remaking a Skyblock plugin created by Linuzo, so, since the plugin is outdated, im fixing it to update it for my Servers and anyone who sees my github, ill later add multi language support:

    So here is my error
    and here is the rest
    and here the Bad code:

    Code:
    public function makeIsland($name){
            $player = $this->getServer()->getPlayer($name);
            if(!($player instanceof Player)){
                return TextFormat::RED."[Skyblock] Error: Jugador no Encontrado";
            }else{
               
                $randX = rand(30, 1000);
                $randZ = rand(30, 1000);
                $randY = rand(15, 100);
               
            $levelName = $this->getServer()->getPlayer($name)->getLevel();
               
                // Make a file for the island
                $levelName = fopen($this->getDataFolder()."Islands/".$name.".txt", "w");
                fwrite($levelName, $randX.", ".$randY.", ".$randZ);
                $playerFile = fopen($this->getDataFolder()."Players/".$name.".txt", "w");
                fwrite($playerFile, $player->getLevel()->getName());
               
                // Top layer of the island
               
                // 1st side
                $levelName->setBlock(new Vector3($randX, $randY, $randZ), new Grass());
                $levelName->setBlock(new Vector3($randX+6, $randY, $randZ+6), new Grass());
                $levelName->setBlock(new Vector3($randX+6, $randY, $randZ+5), new Grass());
                $levelName->setBlock(new Vector3($randX+6, $randY, $randZ+4), new Grass());
                $levelName->setBlock(new Vector3($randX+6, $randY, $randZ+3), new Grass());
                $levelName->setBlock(new Vector3($randX+6, $randY, $randZ+2), new Grass());
                $levelName->setBlock(new Vector3($randX+6, $randY, $randZ+1), new Grass());
               
                // 2nd side
                $levelName->setBlock(new Vector3($randX+5, $randY, $randZ+6), new Grass());
                $levelName->setBlock(new Vector3($randX+5, $randY, $randZ+5), new Grass());
                $levelName->setBlock(new Vector3($randX+5, $randY, $randZ+4), new Grass());
                $levelName->setBlock(new Vector3($randX+5, $randY, $randZ+3), new Grass());
                $levelName->setBlock(new Vector3($randX+5, $randY, $randZ+2), new Grass());
                $levelName->setBlock(new Vector3($randX+5, $randY, $randZ+1), new Grass());
    
    // and so on!, it there are lots of setBlocks
    and the crash dump if needed

    Attached Files:

  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    $level $this->getServer()->getLevelByName($levelName);
    Then always use setBlock() on $level
    applqpak likes this.
  3. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    ok, going to check out.
  4. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    so i replace
    PHP:
    $levelName $this->getServer()->getPlayer($name)->getLevel();
    with
    PHP:
    $level $this->getServer()->getLevelByName($levelName);
  5. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    so now
    $level->setBlock(new Vector3($randX, $randY, $randZ), new Grass());
    rather than
    $levelName->setBlock(new Vector3($randX, $randY, $randZ), new Grass());
  6. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    NOW I GET THIS ERROR:

  7. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    \
    Here's how you can do it:

    PHP:
    @mkdir($this->getDataFolder()."Islands/".$name.".txt");
    $level = new Config($this->getDataFolder()."Islands/".$name.".txt"Config::ENUM);
    $level->set("location"$level.",".$x.",".$y.",".$z);
    $level->setAll($level->getAll());
    $level->save();

    //get pos

    $pos explode(","$level->get("location"));
    $level $pos[0];
    $x $pos[1];
    $y $pos[2];
    $z $pos[3];

    //set block

    $level $this->getServer()->getLevelByName($level);
    $level->setBlock(new Position($x$y$z$level), Block::get(Block::GRASS));
    Last edited: Feb 9, 2016
  8. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
  9. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Suggestion: You should really learn proper OO PHP and the PocketMine API....
  10. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    I know, but i just started again, 3 years without coding PHP, Flash, js, and C#
    my skills Got way too rusty
  11. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Time for a refresher course, eh?
  12. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    Im Really Confused, What do i do? the plugin already makes that stuff, it will make more errors. help
  13. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    Yep, ill try CodeAcademy, and other, also reviewing some plugins code lets me recognise some code,
    then i experiment. :D
    applqpak likes this.
  14. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Wrong. Should be
    PHP:
    $level->setBlock(new Position($x$y$z$level), Block::get(Block::GRASS));
    PEMapModder and applqpak like this.
  15. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Yes, I forgot to put that, just typed it so fast.
  16. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    fopen is wrong opened, you opened it with type "w", means it is only opened for writing, open it with a+ (write and read) or with r (read)
  17. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    I didn't even use fopen
  18. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    ...ok, im implementing this, going to test it out
  19. TheKillerTacos
    Offline

    TheKillerTacos Active Member

    Joined:
    Jan 21, 2016
    Posts:
    76
    Minecraft User:
    TheKillerTacos
    So this is the New Problem:

    no matter what i do, if the command tries to get the user file from the /players folders
    help, and i think that this line will aslo give errors:

    PHP:
    $type 0;
    Tree::growTree($level$x+6$x+1$x+6, new Random(mt_rand()), Sapling::OAK);
  20. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    PHP:
    $level $this->getServer()->getPlayer($name)->getLevel();
    $level = $this->getServer()->getLevelByName($levelName);
    would both be the Level

    To get the name, do $level->getName()

Share This Page

Advertisement