mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 02:09:42 +00:00
Use SetLocalPlayerAsInitializedPacket for spawning, fixed a bunch of bugs
this should fix forms not working during PlayerJoinEvent, and also removes the spurious PlayerItemHeldEvent firing on spawn bug. The player MUST now send this packet. Bots take note.
This commit is contained in:
parent
25660843c5
commit
a5383b4a82
@ -910,10 +910,19 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
||||
$entity->spawnTo($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}elseif($this->chunkLoadCount >= $this->spawnThreshold){
|
||||
$this->spawned = true;
|
||||
|
||||
if($this->chunkLoadCount >= $this->spawnThreshold and !$this->spawned){
|
||||
$this->doFirstSpawn();
|
||||
foreach($this->usedChunks as $index => $c){
|
||||
Level::getXZ($index, $chunkX, $chunkZ);
|
||||
foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){
|
||||
if($entity !== $this and !$entity->isClosed() and $entity->isAlive() and !$entity->isFlaggedForDespawn()){
|
||||
$entity->spawnTo($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->networkSession->onTerrainReady();
|
||||
}
|
||||
}
|
||||
|
||||
@ -951,9 +960,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
||||
Timings::$playerChunkSendTimer->stopTiming();
|
||||
}
|
||||
|
||||
protected function doFirstSpawn(){
|
||||
$this->spawned = true;
|
||||
|
||||
public function doFirstSpawn(){
|
||||
$this->networkSession->onSpawn();
|
||||
|
||||
if($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)){
|
||||
@ -974,15 +981,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
||||
|
||||
$this->noDamageTicks = 60;
|
||||
|
||||
foreach($this->usedChunks as $index => $c){
|
||||
Level::getXZ($index, $chunkX, $chunkZ);
|
||||
foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){
|
||||
if($entity !== $this and !$entity->isClosed() and $entity->isAlive() and !$entity->isFlaggedForDespawn()){
|
||||
$entity->spawnTo($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->spawnToAll();
|
||||
|
||||
if($this->server->getUpdater()->hasUpdate() and $this->hasPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE) and $this->server->getProperty("auto-updater.on-update.warn-ops", true)){
|
||||
|
@ -317,12 +317,13 @@ class NetworkSession{
|
||||
$this->setHandler(new PreSpawnSessionHandler($this->server, $this->player, $this));
|
||||
}
|
||||
|
||||
public function onSpawn() : void{
|
||||
public function onTerrainReady() : void{
|
||||
$pk = new PlayStatusPacket();
|
||||
$pk->status = PlayStatusPacket::PLAYER_SPAWN;
|
||||
$this->sendDataPacket($pk);
|
||||
}
|
||||
|
||||
//TODO: split this up even further
|
||||
public function onSpawn() : void{
|
||||
$this->setHandler(new SimpleSessionHandler($this->player));
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@ namespace pocketmine\network\mcpe\handler;
|
||||
|
||||
use pocketmine\network\mcpe\NetworkSession;
|
||||
use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
|
||||
use pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket;
|
||||
use pocketmine\network\mcpe\protocol\StartGamePacket;
|
||||
use pocketmine\network\mcpe\protocol\types\DimensionIds;
|
||||
use pocketmine\Player;
|
||||
@ -96,4 +97,10 @@ class PreSpawnSessionHandler extends SessionHandler{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function handleSetLocalPlayerAsInitialized(SetLocalPlayerAsInitializedPacket $packet) : bool{
|
||||
$this->player->doFirstSpawn();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,6 @@ use pocketmine\network\mcpe\protocol\PlayerInputPacket;
|
||||
use pocketmine\network\mcpe\protocol\PlayerSkinPacket;
|
||||
use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
|
||||
use pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket;
|
||||
use pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket;
|
||||
use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket;
|
||||
use pocketmine\network\mcpe\protocol\ShowCreditsPacket;
|
||||
use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket;
|
||||
@ -402,8 +401,4 @@ class SimpleSessionHandler extends SessionHandler{
|
||||
public function handleLabTable(LabTablePacket $packet) : bool{
|
||||
return false; //TODO
|
||||
}
|
||||
|
||||
public function handleSetLocalPlayerAsInitialized(SetLocalPlayerAsInitializedPacket $packet) : bool{
|
||||
return false; //TODO
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user