1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Teleport player to other world

Discussion in 'Development' started by CupidonSauce173, Jul 15, 2018.

  1. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Hello, so I am trying to make a player to move on another world on a OnInteract founction. Here is the code
    PHP:
    elseif($item->getCustomName() == "§bDiamond"){

                
    $player->sendMessage("");
                
    $player->sendMessage($this-> prefix Color::RED " §7Du wurdest zu §6SkyWars §7teleportiert");
                
    $player->teleport(new Position(-18619278$this->getServer()->getLevelByName(Diamond)));
                
    $player->getlevel()->addSound(new EndermanTeleportSound($player));
                
    $player->getInventory()->clearAll();
                
    $player->getInventory()->setSize(9);
                
    $player->getInventory()->setItem(7Item::get(339)->setCustomName("§aInfo"));
                
    $player->getInventory()->setItem(0Item::get(345)->setCustomName("§eGames"));
                
    $player->getInventory()->setItem(6Item::get(388)->setCustomName("§2Your Profile"));
                
    $player->getInventory()->setItem(8Item::get(54)->setCustomName("§aGadgets"));

    I am getting this error : Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'Lobby':Class 'Lobby/Position' not found on Lobby\Main
    Error: "Class 'Lobby\Position' not found" (EXCEPTION) in "Lobby/src/Lobby/Main at line 251.

    This is what I tried :
    1.I tried to write other code like this :

    PHP:
    $level $player->getServer()->getLevelByName("Diamond");
                
    $ev->getPlayer()->teleport($ev->getPlayer()->getLevel($level)->getSafeSpawn());
    2. I tried to fix that with a hammer but sadly, it didn't work.
    Oh and between, $ev is $event ( public function onInteract(PlayerInteractEvent $ev) )

    I am not sure to understand this error..If someone can help :)
     
  2. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    The first error occurred because you did not import the Position class. Your second attempt failed, because Player::getLevel() has no arguments, as it simply returns the world that the player is in.

    Try this code:
    PHP:
    $player->teleport($this->getServer()->getLevelByName("Diamond")->getSafeSpawn());
     
    corytortoise likes this.
  3. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    I get this error :
    [06:32:45] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'LobbySystem v1': Call to a member function getSafeSpawn() on null on Lobby\Main
    [06:32:45] [Server thread/CRITICAL]: Error: "Call to a member function getSafeSpawn() on null" (EXCEPTION) in "LobbySystem-master/src/Lobby/Main" at line 251
     
    DavidDGTNT likes this.
  4. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    Make sure the argument of Server::getLevelByName() is your world name. Replace Diamond with your world name. It's case sensitive.
     
  5. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Diamond is the world name.
     
  6. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    Make sure the world is loaded.
     
    corytortoise likes this.
  7. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Oh perfect, sometimes I feel a little bit stupid...lol, thank you :)
    PS - Great plugins you made/make!
     
  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.