mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Added API for transferring players to other servers (#355)
* Added API method `Player->transfer()` and PlayerTransferEvent
This commit is contained in:
@ -64,6 +64,7 @@ use pocketmine\event\player\PlayerRespawnEvent;
|
||||
use pocketmine\event\player\PlayerToggleFlightEvent;
|
||||
use pocketmine\event\player\PlayerToggleSneakEvent;
|
||||
use pocketmine\event\player\PlayerToggleSprintEvent;
|
||||
use pocketmine\event\player\PlayerTransferEvent;
|
||||
use pocketmine\event\server\DataPacketReceiveEvent;
|
||||
use pocketmine\event\server\DataPacketSendEvent;
|
||||
use pocketmine\event\TextContainer;
|
||||
@ -127,6 +128,7 @@ use pocketmine\network\protocol\SetTimePacket;
|
||||
use pocketmine\network\protocol\StartGamePacket;
|
||||
use pocketmine\network\protocol\TakeItemEntityPacket;
|
||||
use pocketmine\network\protocol\TextPacket;
|
||||
use pocketmine\network\protocol\TransferPacket;
|
||||
use pocketmine\network\protocol\UpdateAttributesPacket;
|
||||
use pocketmine\network\protocol\UpdateBlockPacket;
|
||||
use pocketmine\network\SourceInterface;
|
||||
@ -2987,6 +2989,31 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$timings->stopTiming();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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{
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerTransferEvent($this, $address, $port, $message));
|
||||
|
||||
if(!$ev->isCancelled()){
|
||||
$pk = new TransferPacket();
|
||||
$pk->address = $ev->getAddress();
|
||||
$pk->port = $ev->getPort();
|
||||
$this->dataPacket($pk);
|
||||
$this->close("", $ev->getMessage(), false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicks a player from the server
|
||||
*
|
||||
|
Reference in New Issue
Block a user