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

Always on spawn

Comments in 'Plugin Development' started by Xenturio, May 10, 2015.

  1. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    $p = $event->getPlayer();
    $p->teleport($p->getLevel()->getSafeSpawn());

    dont have any functions since dev build 1120.
    by 1116 all works fine. anyone know the issue?
    Last edited: May 10, 2015
  2. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Try this
    PHP:
      $p $event->getPlayer();

      
    $p->teleport($this->getServer()->getDefaultLevel()->getSafeSpawn());
  3. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    same issue - you dont will teleport back to spawn after join the server...
  4. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  5. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
  7. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    public function onPlayerJoinEvent (PlayerJoinEvent $event)
    {
    $p = $event->getPlayer();
    $event->getPlayer()->teleport(Server::getInstance()->getLevelByName($event->getPlayer()->getLevel()->getName())->getSafeSpawn());
    return true;
    }

    as command all works fine but not in PlayerJoinEvent o_O
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Why return true in an event? And did you use PlayerJoinEvent?
    PHP:
    public function onPlayerJoinEvent (PlayerJoinEvent $event){
           
    $p $event->getPlayer();
           
    $p->teleport($this->getServer()->getLevelByName($p->getLevel()->getName())->getSafeSpawn());
         }
  9. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    i return always true xD iam not a good plugin developer but it works ^^

    i dont understand, yes i use PlayerJoinEvent...

    the problem is by 1116 all works fine and if u update the server version to 1117 it doesnt work anymore...
    and i dont know why...

    if i use it in a command, all works but not in the playerjoin event...

    if i do ->sendmessage befor and after the teleport code

    both messages will be shown but the teleportation will not be done
  10. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Try
    PHP:
                    $player $event->getPlayer();
                    
    $x $this->getServer()->getLevelByName($player->getLevel()->getName())->getSafeSpawn()->getX();
                    
    $y $this->getServer()->getLevelByName($player->getLevel()->getName())->getSafeSpawn()->getY();
                    
    $z $this->getServer()->getLevelByName($player->getLevel()->getName())->getSafeSpawn()->getZ();
                    
    $level $player->getLevel()->getName();
                  
                    
    $player->teleport(new Position($x$y$z$level));
  11. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    18:00:17 [NOTICE] InvalidArgumentException: "Argument 4 passed to pocketmine\level\Position::__construct() must be an instance of pocketmine\level\Level, string given, called in phar:///home/mcpe011/plugins/AlwaysSpawn.phar/src/main/onspawn.php on line 38 and defined" (E_RECOVERABLE_ERROR) in "/src/pocketmine/level/Position" at line 38

    i think its the level as arg 4
  12. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Yes, remove the ->getName() at $level = $player->getLevel()->getName();
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why search the level object by name when you already have the level object? It's just terrible...
    TigerHix likes this.
  14. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    try this:
    PHP:
    public function onJoin(PlayerJoinEvent $e){
      
    $p=$e->getPlayer();
      
    $p->teleport($p->getLevel()->getSpawnLocation());
    }
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This is terrible. Why calculate the safe spawn thrice, and while you already got the Vector3, create another one, and base on it make a position with the level that doesn't matter at all?
    TigerHix and HotFireyDeath like this.
  17. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    same problem - player doenst join at spawn position - nothing happens...
  18. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    PHP:
    public function onJoin(PlayerJoinEvent $event) {
        
    $p $event->getPlayer();
        
    $spawn $event->getServer()->getLevelByName("world")->getSafeSpawn();
        
    $p->teleport($spawn);
    }
    or
    PHP:
    public function onJoin(PlayerJoinEvent $event) {
        
    $p $event->getPlayer();
        
    $spawn $event->getServer()->getLevelByName("world")->getSpawnLocation();
        
    $p->teleport($spawn);
    }
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What about executing the teleport one or two ticks after the event, via a scheduler?
  20. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Why not teleport them when they leave the server?
    PEMapModder likes this.

Share This Page

Advertisement