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

[Solved]Two problems

Discussion in 'Development' started by SavionLegendZzz, Feb 23, 2017.

  1. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    Ok so i have some issues with teleporting a player to spawn.

    1. When i use Player::setLevel() then Player::teleport() the server crashes due to getEntites() on null because of chunk hashing blah blah
    2. If i use just Player::teleport() the crashing does not happen but the player cant move and is stuck

    This all happens when i call the win() function(my own code)

    Here is my current code:
    PHP:
     /**
         * @param Player $player
         */
        
    public function win(Player $player){
            
    $level $this->getServer()->getDefaultLevel()->getSafeSpawn();
            
    $player->teleport(new Position($level->x$level->y+2$level->z));
            
    $this->stats->updateGapple($player);
            
    $player->getInventory()->setContents([]);
            if(
    $this->isInMatch($player) === true){
                
    $match $this->getMatch($player);
                
    $player->sendMessage(self::PREFIX."You won on ".$match->getName()."!");
                
    $match->end();
            }
        }
     
  2. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
  3. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    It's good practice to post the answer, even if it's your own question, in case other people have a similar problem.
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Sadly, most people don't search for their problem though....
     
  5. SavionLegendZzz

    SavionLegendZzz Slime

    Messages:
    75
    GitHub:
    savionlegends
    I just changed how i teleport them
    Code:
    PHP:
       /**
         * @param Player $player
         */
        
    public function win(Player $player){
            
    $level $this->getServer()->getDefaultLevel()->getSpawnLocation();
            
    $player->teleport($level);
            
    $this->stats->updateGapple($player);
            
    $player->getInventory()->setContents([]);
            if(
    $this->isInMatch($player) === true){
                
    $match $this->getMatch($player);
                
    $player->sendMessage(self::PREFIX."You won on ".$match->getName()."!");
                
    $match->end();
            }
        }
     
    Awzaw and corytortoise like this.
  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.