mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 01:09:44 +00:00
move PlayerListPacket sending responsibility to NetworkSession
This commit is contained in:
parent
89d4f596bd
commit
6f29fe063f
@ -802,9 +802,6 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
||||
*/
|
||||
public function setDisplayName(string $name){
|
||||
$this->displayName = $name;
|
||||
if($this->spawned){
|
||||
$this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $this->getSkin(), $this->getXuid());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,6 @@ use pocketmine\command\ConsoleCommandSender;
|
||||
use pocketmine\command\PluginIdentifiableCommand;
|
||||
use pocketmine\command\SimpleCommandMap;
|
||||
use pocketmine\entity\EntityFactory;
|
||||
use pocketmine\entity\Skin;
|
||||
use pocketmine\event\HandlerList;
|
||||
use pocketmine\event\player\PlayerDataSaveEvent;
|
||||
use pocketmine\event\server\CommandEvent;
|
||||
@ -61,9 +60,7 @@ use pocketmine\network\mcpe\NetworkCompression;
|
||||
use pocketmine\network\mcpe\NetworkSession;
|
||||
use pocketmine\network\mcpe\PacketBatch;
|
||||
use pocketmine\network\mcpe\protocol\ClientboundPacket;
|
||||
use pocketmine\network\mcpe\protocol\PlayerListPacket;
|
||||
use pocketmine\network\mcpe\protocol\ProtocolInfo;
|
||||
use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
|
||||
use pocketmine\network\mcpe\RakLibInterface;
|
||||
use pocketmine\network\Network;
|
||||
use pocketmine\network\query\QueryHandler;
|
||||
@ -1813,8 +1810,9 @@ class Server{
|
||||
}
|
||||
|
||||
public function addOnlinePlayer(Player $player) : void{
|
||||
$this->updatePlayerListData($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkin(), $player->getXuid());
|
||||
|
||||
foreach($this->playerList as $p){
|
||||
$p->getNetworkSession()->onPlayerAdded($player);
|
||||
}
|
||||
$this->playerList[$player->getRawUniqueId()] = $player;
|
||||
|
||||
if($this->sendUsageTicker > 0){
|
||||
@ -1825,52 +1823,12 @@ class Server{
|
||||
public function removeOnlinePlayer(Player $player) : void{
|
||||
if(isset($this->playerList[$player->getRawUniqueId()])){
|
||||
unset($this->playerList[$player->getRawUniqueId()]);
|
||||
|
||||
$this->removePlayerListData($player->getUniqueId());
|
||||
foreach($this->playerList as $p){
|
||||
$p->getNetworkSession()->onPlayerRemoved($player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UUID $uuid
|
||||
* @param int $entityId
|
||||
* @param string $name
|
||||
* @param Skin $skin
|
||||
* @param string $xboxUserId
|
||||
* @param Player[]|null $players
|
||||
*/
|
||||
public function updatePlayerListData(UUID $uuid, int $entityId, string $name, Skin $skin, string $xboxUserId = "", ?array $players = null) : void{
|
||||
$pk = new PlayerListPacket();
|
||||
$pk->type = PlayerListPacket::TYPE_ADD;
|
||||
|
||||
$pk->entries[] = PlayerListEntry::createAdditionEntry($uuid, $entityId, $name, $skin, $xboxUserId);
|
||||
|
||||
$this->broadcastPacket($players ?? $this->playerList, $pk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UUID $uuid
|
||||
* @param Player[]|null $players
|
||||
*/
|
||||
public function removePlayerListData(UUID $uuid, ?array $players = null) : void{
|
||||
$pk = new PlayerListPacket();
|
||||
$pk->type = PlayerListPacket::TYPE_REMOVE;
|
||||
$pk->entries[] = PlayerListEntry::createRemovalEntry($uuid);
|
||||
$this->broadcastPacket($players ?? $this->playerList, $pk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player $p
|
||||
*/
|
||||
public function sendFullPlayerListData(Player $p) : void{
|
||||
$pk = new PlayerListPacket();
|
||||
$pk->type = PlayerListPacket::TYPE_ADD;
|
||||
foreach($this->playerList as $player){
|
||||
$pk->entries[] = PlayerListEntry::createAdditionEntry($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkin(), $player->getXuid());
|
||||
}
|
||||
|
||||
$p->sendDataPacket($pk);
|
||||
}
|
||||
|
||||
public function sendUsage(int $type = SendUsageTask::TYPE_STATUS) : void{
|
||||
if((bool) $this->getProperty("anonymous-statistics.enabled", true)){
|
||||
$this->asyncPool->submitTask(new SendUsageTask($this, $type, $this->uniquePlayers));
|
||||
|
@ -55,6 +55,7 @@ use pocketmine\network\mcpe\protocol\ModalFormRequestPacket;
|
||||
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
|
||||
use pocketmine\network\mcpe\protocol\NetworkChunkPublisherUpdatePacket;
|
||||
use pocketmine\network\mcpe\protocol\Packet;
|
||||
use pocketmine\network\mcpe\protocol\PlayerListPacket;
|
||||
use pocketmine\network\mcpe\protocol\PlayStatusPacket;
|
||||
use pocketmine\network\mcpe\protocol\ServerboundPacket;
|
||||
use pocketmine\network\mcpe\protocol\ServerToClientHandshakePacket;
|
||||
@ -66,6 +67,7 @@ use pocketmine\network\mcpe\protocol\types\CommandData;
|
||||
use pocketmine\network\mcpe\protocol\types\CommandEnum;
|
||||
use pocketmine\network\mcpe\protocol\types\CommandParameter;
|
||||
use pocketmine\network\mcpe\protocol\types\ContainerIds;
|
||||
use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
|
||||
use pocketmine\network\mcpe\protocol\types\PlayerPermissions;
|
||||
use pocketmine\network\mcpe\protocol\UpdateAttributesPacket;
|
||||
use pocketmine\network\NetworkInterface;
|
||||
@ -843,6 +845,32 @@ class NetworkSession{
|
||||
$this->sendDataPacket($pk);
|
||||
}
|
||||
|
||||
public function syncPlayerList() : void{
|
||||
$pk = new PlayerListPacket();
|
||||
$pk->type = PlayerListPacket::TYPE_ADD;
|
||||
foreach($this->server->getOnlinePlayers() as $player){
|
||||
$pk->entries[] = PlayerListEntry::createAdditionEntry($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->getSkin(), $player->getXuid());
|
||||
}
|
||||
|
||||
$this->sendDataPacket($pk);
|
||||
}
|
||||
|
||||
public function onPlayerAdded(Player $p) : void{
|
||||
$pk = new PlayerListPacket();
|
||||
$pk->type = PlayerListPacket::TYPE_ADD;
|
||||
$pk->entries[] = PlayerListEntry::createAdditionEntry($p->getUniqueId(), $p->getId(), $p->getName(), $p->getSkin(), $p->getXuid());
|
||||
$this->sendDataPacket($pk);
|
||||
}
|
||||
|
||||
public function onPlayerRemoved(Player $p) : void{
|
||||
if($p !== $this->player){
|
||||
$pk = new PlayerListPacket();
|
||||
$pk->type = PlayerListPacket::TYPE_REMOVE;
|
||||
$pk->entries[] = PlayerListEntry::createRemovalEntry($p->getUniqueId());
|
||||
$this->sendDataPacket($pk);
|
||||
}
|
||||
}
|
||||
|
||||
public function tick() : bool{
|
||||
if($this->handler instanceof LoginSessionHandler){
|
||||
if(time() >= $this->connectTime + 10){
|
||||
|
@ -96,7 +96,7 @@ class PreSpawnSessionHandler extends SessionHandler{
|
||||
$this->player->getInventory()->sendHeldItem($this->player);
|
||||
$this->session->queueCompressed($this->server->getCraftingManager()->getCraftingDataPacket());
|
||||
|
||||
$this->server->sendFullPlayerListData($this->player);
|
||||
$this->session->syncPlayerList();
|
||||
}
|
||||
|
||||
public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{
|
||||
|
Loading…
x
Reference in New Issue
Block a user