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

Why doesn't teleporting work?

Comments in 'Plugin Development' started by CraftYourBukkit, Jun 20, 2015.

  1. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I'm using $player->teleport() on PlayerJoinEvent, but it doesn't work. Why doesn't it and how can I fix it?
    Last edited: Jun 20, 2015
  2. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    Make a task do it.. already have many similar threads.
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    What do you mean? And could you post a link to one, I din't found one..
  4. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    981
    Plugins:
    9
    Code? Most likely something to do with the code.
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    $player $event->getPlayer();
            
    $x $this->getConfig()->getNested("lobby.x");
            
    $y $this->getConfig()->getNested("lobby.y");
            
    $z $this->getConfig()->getNested("lobby.z");
            
    $player->teleport(new Vector3($x$y$z));
  6. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    I had this issue when developing SpawnMgr. Pocketmine does a teleport AFTER the join event. So whatever teleport you did is lost. What I did was to remove the teleport in the join event handler instead that would trigger a delayed task. Then the delayed task wold do the teleport.
  7. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Below is the code directly out of my AlwaysSpawn plugin:
    PHP:
    <?php
        
    namespace philipshilling\alwaysspawn;
      
        use 
    pocketmine\plugin\PluginBase as Plugin;
        use 
    pocketmine\event\Listener;
        use 
    pocketmine\event\player\PlayerLoginEvent;
        use 
    pocketmine\math\Vector3;
                  
        class 
    Loader extends Plugin implements Listener {
            public function 
    onEnable() {
                
    $this->getServer()->getPluginManager()->registerEvents($this$this);
                
    $this->getServer()->getLogger()->info("AlwaysSpawn Enabled!");
            }
          
            public function 
    onPlayerLogin(PlayerLoginEvent $event) {
                
    $player $event->getPlayer();
                
    $x $this->getServer()->getDefaultLevel()->getSafeSpawn()->getX();
                
    $y $this->getServer()->getDefaultLevel()->getSafeSpawn()-> getY();
                
    $z $this->getServer()->getDefaultLevel()->getSafeSpawn()->getZ();
                
    $level $this->getServer()->getDefaultLevel();
                
    $player->teleport(new Vector3($x$y$z$level));
            }
          
            public function 
    onDisable() {
                
    $this->getServer()->getLogger()->info("AlwaysSpawn is no longer enabled! Did the server stop?");
            }
        }
    EDIT: If you decide to use my code to ease development, don't copy-paste it. Edit it a little to make it your own.
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    That's actually the same as mine, just not the level thing. I will try it with it, thanks!
  9. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Doesn't work, I will use @aliuly's version. Thanks!
  10. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    The reason that didn't work is because you were using PlayerJoinEvent not PlayerLoginEvent.
    luca28pet and CraftYourBukkit like this.
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    *facepalm* Works now, thanks! xD
    Legoboy0215 likes this.
  12. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    I spent hours trying to figure out why PlayerJoinEvent wouldnt do that too youre not alone XD
  13. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    What's the difference between Join and Login?
  14. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    I dont know if im right about this but I think Join is called when the client and server are communicating then Login is called right before (or maybe during idk) the player spawns.
  15. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Now I'd better use PlayerLoginEvent... XD
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    @shoghicp recommended to use PlayerRespawnEvent the respawn position setter, which is also called when player joins.
    Tethered_ and CraftYourBukkit like this.

Share This Page

Advertisement