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

Solved Player teleporting to another level doesn't work

Comments in 'Plugin Development' started by Ragnok1234, Sep 27, 2016.

  1. Ragnok1234
    Offline

    Ragnok1234 Active Member

    Joined:
    Jul 18, 2016
    Posts:
    53
    Minecraft User:
    Ragnok123
    Hello all, i have code:
    PHP:
    $sender->teleport(new Vector3($this->getHomeX($sender->getName()), $this->getHomeY($sender->getName()), $this->getHomeZ($sender->getName()), $this->getHomeWorld($sender->getName())));
    This code teleports player to xyz position, but doesn't teleport to another level. Some ideas?
  2. Thunder33345
    Offline

    Thunder33345 Notable Member

    Joined:
    Apr 3, 2014
    Posts:
    755
    Minecraft User:
    Thunder33345
    dont quote me on this but i guess it ie because level not loaded or not using Position
  3. Ragnok1234
    Offline

    Ragnok1234 Active Member

    Joined:
    Jul 18, 2016
    Posts:
    53
    Minecraft User:
    Ragnok123
    I tried this all. Doesnt work
  4. TutoGamerWalid
    Offline

    TutoGamerWalid Active Member

    Joined:
    Jun 11, 2015
    Posts:
    69
    Minecraft User:
    TutoGamerWalid
    PHP:
    $level $this->getServer()->getLevelByName("yourworld");
    $this->getServer()->loadLevel("yourworld");//load level
    $sender->teleport(new Position($x,$y$z,$level);

    //New Vector3 = x,y,z
    //And
    //New Positon = x,y,z,level
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    /** @var Level $level */
    /** @var Player $player */
    $player->teleport($level->getSafeSpawn())
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Load the level before getting it.
  7. Ragnok1234
    Offline

    Ragnok1234 Active Member

    Joined:
    Jul 18, 2016
    Posts:
    53
    Minecraft User:
    Ragnok123
    Ok, fixed. Thanks you all. I forgot to make public function getHomeWorld
  8. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Do you use IDE? Usually, IDE will give you a warning if you call a function that doesn't exist...
  9. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    There's also an error in the console.. Maybe @Ragnok1234, you should learn to understand them
  10. Yeelze
    Offline

    Yeelze New Member

    Joined:
    Apr 2, 2016
    Posts:
    31
    Minecraft User:
    Yeelze
    Better.
    PHP:
    $server $this->getServer();
    $name $player->getName();
    $homeWorld $this->getHomeWorld($name);
    if(!
    $server->isLevelLoaded($homeWorld) {
        
    $server->loadLevel($homeWorld);
    }

    if(
    $player->getLevel() != $server->getLevelByName($homeWorld) {
        
    $player->teleport($server->getLevelByName($homeWorld)->getSafeSpawn());
    }
    $player->teleport(new Vector3($this->getHomeX($name), $this->getHomeY($name), $this->getHomeZ($name)));
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    How is it better to teleport the player twice?
  12. MichaelM04
    Offline

    MichaelM04 Active Member Plugin Developer

    Joined:
    Nov 12, 2015
    Posts:
    213
    Plugins:
    1
    Minecraft User:
    Michael
    I teleport twice for minigame plugins, sometimes when you teleport to the position it will glitch and teleport to that position but not in the world.

    $player->teleport($Level->getSafeSpawn());
    $player->teleport($x, $y, $z, $Level);
  13. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Just load the chunk before teleporting.

Share This Page

Advertisement