diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 5c1448b2b..523096f85 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -278,7 +278,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** @var int */ protected $spawnThreshold; /** @var int */ - protected $chunkLoadCount = 0; + protected $spawnChunkLoadCount = 0; /** @var int */ protected $chunksPerTick; @@ -964,8 +964,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } $this->usedChunks[Level::chunkHash($x, $z)] = true; - $this->chunkLoadCount++; - $this->dataPacket($payload); if($this->spawned){ @@ -976,8 +974,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - if($this->chunkLoadCount >= $this->spawnThreshold and !$this->spawned){ - $this->doFirstSpawn(); + if($this->spawnChunkLoadCount !== -1 and ++$this->spawnChunkLoadCount >= $this->spawnThreshold){ + $this->sendPlayStatus(PlayStatusPacket::PLAYER_SPAWN); + $this->spawnChunkLoadCount = -1; } } @@ -1015,11 +1014,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ Timings::$playerChunkSendTimer->stopTiming(); } - protected function doFirstSpawn(){ + public function doFirstSpawn(){ + if($this->spawned){ + return; //avoid player spawning twice (this can only happen on 3.x with a custom malicious client) + } $this->spawned = true; - $this->sendPlayStatus(PlayStatusPacket::PLAYER_SPAWN); - if($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)){ PermissionManager::getInstance()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this); } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 02bdfba10..e080c8874 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -637,6 +637,9 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ * @param float $value */ public function setScale(float $value) : void{ + if($value <= 0){ + throw new \InvalidArgumentException("Scale must be greater than 0"); + } $multiplier = $value / $this->getScale(); $this->width *= $multiplier; diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 0f08dc2ad..12807d6a5 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -451,13 +451,14 @@ class Level implements ChunkManager, Metadatable{ if(!is_array($pk)){ $pk = [$pk]; } - - if($players === null){ - foreach($pk as $e){ - $this->broadcastPacketToViewers($sound, $e); + if(!empty($pk)){ + if($players === null){ + foreach($pk as $e){ + $this->broadcastPacketToViewers($sound, $e); + } + }else{ + $this->server->batchPackets($players, $pk, false); } - }else{ - $this->server->batchPackets($players, $pk, false); } } @@ -466,13 +467,14 @@ class Level implements ChunkManager, Metadatable{ if(!is_array($pk)){ $pk = [$pk]; } - - if($players === null){ - foreach($pk as $e){ - $this->broadcastPacketToViewers($particle, $e); + if(!empty($pk)){ + if($players === null){ + foreach($pk as $e){ + $this->broadcastPacketToViewers($particle, $e); + } + }else{ + $this->server->batchPackets($players, $pk, false); } - }else{ - $this->server->batchPackets($players, $pk, false); } } diff --git a/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php b/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php index 119bcfc4e..2c65f05ed 100644 --- a/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php +++ b/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php @@ -59,6 +59,7 @@ use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket; use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket; use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket; 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; @@ -282,6 +283,11 @@ class PlayerNetworkSessionAdapter extends NetworkSession{ return false; //TODO: GUI stuff } + public function handleSetLocalPlayerAsInitialized(SetLocalPlayerAsInitializedPacket $packet) : bool{ + $this->player->doFirstSpawn(); + return true; + } + public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{ return $this->player->handleLevelSoundEvent($packet); }