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

Solved Problem with teleporting a player to another world

Comments in 'Plugin Development' started by BlubberBoy333, Oct 4, 2015.

  1. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    I'm having problems with teleporting a player to another world. The code i'm using is:
    PHP:
    $file = new Config($this->getDataFolder()."Islands/".$player->getName().".yml"Config::YAML);
    $x $file->get("X");
    $y $file->get("Y");
    $z $file->get("Z");
    $world $file->get("World");
    $player->teleport(new Position($x$y$z$world);
    But when i do that, it doesn't teleport me, it send an error to the console saying:
    InvalidArgumentException: "Argument 4 passed to pocketmine\level\Position::__construct() must be an instance of pocketmine\level\Level, string given, called in /home/max/ser/plugins/SkyBlock_v1.5.6/src/SkyBlock/Main.php on line 104 and defined" (E_RECOVERABLE_ERROR) in "/src/pocketmine/level/Position" at line 38

    Can anyone explain what i'm doing wrong?
  2. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Read the error. Argument 4 passed to Position::__construct() must be instance of Level, string given(parameter 4 requires an object, not a string). It should be:
    PHP:
    $player->teleport(new Position($x$y$z$this->getServer()->getLevelByName($world)))
    Learn about types in PHP here: http://php.net/manual/en/language.types.intro.php
    Last edited: Oct 4, 2015
  3. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    I know the different types in php, i just thought that the level name would work for teleporting to a different level. Thanks for the help :D
  4. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Well then you thought wrong. It doesn't take a string, it takes the Level object.
  5. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Great :) someone is already making SkyBlock!
    So i can start a different plugin ^^
    (I could send you my generator script when its working)
  6. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Please do not post if you cannot help him with his problem. Thank you.
  7. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Right.. I forgot to add "off-topic".. But hey! Its late night!
    Legoboy0215 likes this.

Share This Page

Advertisement