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

Transferring a player on server restart

Discussion in 'Development' started by BruhLol, Jan 1, 2018.

  1. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    How can we transfer a player to a different server on server restart?
     
    Levi likes this.
  2. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    if you want, you can plan when your server will restart and then with a TaskDelay you can use the method to transfer a player
     
  3. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    isn't there a simpler method which will transfer players when the players are kicked for server restarting?
     
  4. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    In a plugin's onDisable() method you can check if the server has stopped running.
    Combine this with transfering all players and you should get a good result.
    PHP:
    public function onDisable(): void// The onDisable() method inside the plugin's main class
        
    if(!$this->getServer()->isRunning()){  // Is the server running?
            
    foreach($this->getServer()->getOnlinePlayers() as $player){  // Loop through all online players
                
    $player->transfer($ip$port);  // Transfer each player to $ip:$port
            
    }
        }
    }
     
  5. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    oh ok, thats smart af.
     
  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.