Player: move some functions to a more sensible place

let's keep disconnect-related logic grouped together.
This commit is contained in:
Dylan K. Taylor 2019-04-02 19:57:10 +01:00
parent f332550e52
commit f901c2a612

View File

@ -2273,58 +2273,6 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
return $this->sendDataPacket($packet, false);
}
/**
* Transfers a player to another server.
*
* @param string $address The IP address or hostname of the destination server
* @param int $port The destination port, defaults to 19132
* @param string $message Message to show in the console when closing the player
*
* @return bool if transfer was successful.
*/
public function transfer(string $address, int $port = 19132, string $message = "transfer") : bool{
$ev = new PlayerTransferEvent($this, $address, $port, $message);
$ev->call();
if(!$ev->isCancelled()){
$this->networkSession->transfer($ev->getAddress(), $ev->getPort(), $ev->getMessage());
return true;
}
return false;
}
/**
* Kicks a player from the server
*
* @param string $reason
* @param bool $isAdmin
* @param TextContainer|string $quitMessage
*
* @return bool
*/
public function kick(string $reason = "", bool $isAdmin = true, $quitMessage = null) : bool{
$ev = new PlayerKickEvent($this, $reason, $quitMessage ?? $this->getLeaveMessage());
$ev->call();
if(!$ev->isCancelled()){
$reason = $ev->getReason();
$message = $reason;
if($isAdmin){
if(!$this->isBanned()){
$message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : "");
}
}else{
if($reason === ""){
$message = "disconnectionScreen.noReason";
}
}
$this->close($ev->getQuitMessage(), $message);
return true;
}
return false;
}
/**
* Adds a title text to the user's screen, with an optional subtitle.
*
@ -2486,6 +2434,58 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
return true;
}
/**
* Transfers a player to another server.
*
* @param string $address The IP address or hostname of the destination server
* @param int $port The destination port, defaults to 19132
* @param string $message Message to show in the console when closing the player
*
* @return bool if transfer was successful.
*/
public function transfer(string $address, int $port = 19132, string $message = "transfer") : bool{
$ev = new PlayerTransferEvent($this, $address, $port, $message);
$ev->call();
if(!$ev->isCancelled()){
$this->networkSession->transfer($ev->getAddress(), $ev->getPort(), $ev->getMessage());
return true;
}
return false;
}
/**
* Kicks a player from the server
*
* @param string $reason
* @param bool $isAdmin
* @param TextContainer|string $quitMessage
*
* @return bool
*/
public function kick(string $reason = "", bool $isAdmin = true, $quitMessage = null) : bool{
$ev = new PlayerKickEvent($this, $reason, $quitMessage ?? $this->getLeaveMessage());
$ev->call();
if(!$ev->isCancelled()){
$reason = $ev->getReason();
$message = $reason;
if($isAdmin){
if(!$this->isBanned()){
$message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : "");
}
}else{
if($reason === ""){
$message = "disconnectionScreen.noReason";
}
}
$this->close($ev->getQuitMessage(), $message);
return true;
}
return false;
}
/**
* Note for plugin developers: use kick() with the isAdmin
* flag set to kick without the "Kicked by admin" part instead of this method.