From 7b152def7db154ef86c4581062e0f4d1ab79d9c1 Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 11 Nov 2019 15:23:48 -0500 Subject: [PATCH 1/7] Move SkinAnimation and changed SerializedImage to SkinImage Also change putImage and getImage to getSkinImage and putSkinImage --- src/pocketmine/Player.php | 2 -- .../network/mcpe/NetworkBinaryStream.php | 22 +++++++++---------- .../mcpe/protocol/PlayerSkinPacket.php | 2 -- .../mcpe/protocol/types}/SkinAnimation.php | 10 ++++----- .../mcpe/protocol/types/SkinImage.php} | 6 ++--- 5 files changed, 19 insertions(+), 23 deletions(-) rename src/pocketmine/{utils => network/mcpe/protocol/types}/SkinAnimation.php (86%) rename src/pocketmine/{utils/SerializedImage.php => network/mcpe/protocol/types/SkinImage.php} (92%) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index f3930e136..c70e17772 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -160,8 +160,6 @@ use pocketmine\tile\ItemFrame; use pocketmine\tile\Spawnable; use pocketmine\tile\Tile; use pocketmine\timings\Timings; -use pocketmine\utils\SerializedImage; -use pocketmine\utils\SkinAnimation; use pocketmine\utils\TextFormat; use pocketmine\utils\UUID; use function abs; diff --git a/src/pocketmine/network/mcpe/NetworkBinaryStream.php b/src/pocketmine/network/mcpe/NetworkBinaryStream.php index 890a57a19..c05b365bf 100644 --- a/src/pocketmine/network/mcpe/NetworkBinaryStream.php +++ b/src/pocketmine/network/mcpe/NetworkBinaryStream.php @@ -38,10 +38,10 @@ use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; use pocketmine\network\mcpe\protocol\types\CommandOriginData; use pocketmine\network\mcpe\protocol\types\EntityLink; +use pocketmine\network\mcpe\protocol\types\SkinImage; +use pocketmine\network\mcpe\protocol\types\SkinAnimation; use pocketmine\network\mcpe\protocol\types\StructureSettings; use pocketmine\utils\BinaryStream; -use pocketmine\utils\SerializedImage; -use pocketmine\utils\SkinAnimation; use pocketmine\utils\UUID; use function count; use function strlen; @@ -80,13 +80,13 @@ class NetworkBinaryStream extends BinaryStream{ public function getSkin() : Skin{ $skinId = $this->getString(); $skinResourcePatch = $this->getString(); - $skinData = $this->getImage(); + $skinData = $this->getSkinImage(); $animationCount = $this->getLInt(); $animations = []; for($i = 0; $i < $animationCount; ++$i){ - $animations[] = new SkinAnimation($this->getImage(), $this->getLInt(), $this->getLFloat()); + $animations[] = new SkinAnimation($this->getSkinImage(), $this->getLInt(), $this->getLFloat()); } - $capeData = $this->getImage(); + $capeData = $this->getSkinImage(); $geometryData = $this->getString(); $animationData = $this->getString(); $premium = $this->getBool(); @@ -101,16 +101,16 @@ class NetworkBinaryStream extends BinaryStream{ public function putSkin(Skin $skin){ $this->putString($skin->getSkinId()); $this->putString($skin->getGeometryName()); //resource patch - $this->putImage(SerializedImage::fromLegacy($skin->getSkinData())); + $this->putSkinImage(SkinImage::fromLegacy($skin->getSkinData())); /** @var SkinAnimation[] $animations */ $animations = []; $this->putLInt(count($animations)); foreach($animations as $animation){ - $this->putImage($animation->getImage()); + $this->putSkinImage($animation->getImage()); $this->putLInt($animation->getType()); $this->putLFloat($animation->getFrames()); } - $this->putImage(new SerializedImage(0, 0, $skin->getCapeData())); + $this->putSkinImage(new SkinImage(0, 0, $skin->getCapeData())); $this->putString($skin->getGeometryData()); $this->putString(""); //animation data $this->putBool(false); //isPremium @@ -120,14 +120,14 @@ class NetworkBinaryStream extends BinaryStream{ $this->putString(""); //fullskinId } - public function getImage() : SerializedImage{ + public function getSkinImage() : SkinImage{ $width = $this->getLInt(); $height = $this->getLInt(); $data = $this->getString(); - return new SerializedImage($height, $width, $data); + return new SkinImage($height, $width, $data); } - public function putImage(SerializedImage $image) : void{ + public function putSkinImage(SkinImage $image) : void{ $this->putLInt($image->getWidth()); $this->putLInt($image->getHeight()); $this->putString($image->getData()); diff --git a/src/pocketmine/network/mcpe/protocol/PlayerSkinPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerSkinPacket.php index bbe513bd6..219e7fbf0 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayerSkinPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerSkinPacket.php @@ -27,8 +27,6 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\entity\Skin; use pocketmine\network\mcpe\NetworkSession; -use pocketmine\utils\SerializedImage; -use pocketmine\utils\SkinAnimation; use pocketmine\utils\UUID; class PlayerSkinPacket extends DataPacket{ diff --git a/src/pocketmine/utils/SkinAnimation.php b/src/pocketmine/network/mcpe/protocol/types/SkinAnimation.php similarity index 86% rename from src/pocketmine/utils/SkinAnimation.php rename to src/pocketmine/network/mcpe/protocol/types/SkinAnimation.php index b35c41cea..0f6726cf7 100644 --- a/src/pocketmine/utils/SkinAnimation.php +++ b/src/pocketmine/network/mcpe/protocol/types/SkinAnimation.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\utils; +namespace pocketmine\network\mcpe\protocol\types; class SkinAnimation{ @@ -29,14 +29,14 @@ class SkinAnimation{ public const TYPE_BODY_32 = 2; public const TYPE_BODY_64 = 3; - /** @var SerializedImage */ + /** @var SkinImage */ private $image; /** @var int */ private $type; /** @var float */ private $frames; - public function __construct(SerializedImage $image, int $type, float $frames){ + public function __construct(SkinImage $image, int $type, float $frames){ $this->image = $image; $this->type = $type; $this->frames = $frames; @@ -45,9 +45,9 @@ class SkinAnimation{ /** * Image of the animation. * - * @return SerializedImage + * @return SkinImage */ - public function getImage() : SerializedImage{ + public function getImage() : SkinImage{ return $this->image; } diff --git a/src/pocketmine/utils/SerializedImage.php b/src/pocketmine/network/mcpe/protocol/types/SkinImage.php similarity index 92% rename from src/pocketmine/utils/SerializedImage.php rename to src/pocketmine/network/mcpe/protocol/types/SkinImage.php index 6996e2208..cbd7ebc16 100644 --- a/src/pocketmine/utils/SerializedImage.php +++ b/src/pocketmine/network/mcpe/protocol/types/SkinImage.php @@ -21,9 +21,9 @@ declare(strict_types=1); -namespace pocketmine\utils; +namespace pocketmine\network\mcpe\protocol\types; -class SerializedImage{ +class SkinImage{ /** @var int */ private $height; @@ -38,7 +38,7 @@ class SerializedImage{ $this->data = $data; } - public static function fromLegacy(string $data) : SerializedImage{ + public static function fromLegacy(string $data) : SkinImage{ switch(strlen($data)){ case 64 * 32 * 4: return new self(64, 32, $data); From 49a9e0a8809484060b88ce3e0dae003e68359cb0 Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 11 Nov 2019 15:26:36 -0500 Subject: [PATCH 2/7] Remove changes to FloatingTextParticle --- src/pocketmine/level/particle/FloatingTextParticle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/level/particle/FloatingTextParticle.php b/src/pocketmine/level/particle/FloatingTextParticle.php index 8c6f6df83..d12282874 100644 --- a/src/pocketmine/level/particle/FloatingTextParticle.php +++ b/src/pocketmine/level/particle/FloatingTextParticle.php @@ -96,7 +96,7 @@ class FloatingTextParticle extends Particle{ $add = new PlayerListPacket(); $add->type = PlayerListPacket::TYPE_ADD; - $add->entries = [PlayerListEntry::createAdditionEntry($uuid, $this->entityId, $name, new Skin("Standard_Custom", str_repeat("\x00", 8192), "", Skin::convertToLegacyName("geometry.humanoid.custom"), ""))]; + $add->entries = [PlayerListEntry::createAdditionEntry($uuid, $this->entityId, $name, new Skin("Standard_Custom", str_repeat("\x00", 8192)))]; $p[] = $add; $pk = new AddPlayerPacket(); From 99d350914ec71b3613d95c515081f606514f12fc Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 11 Nov 2019 15:29:42 -0500 Subject: [PATCH 3/7] Remove convertToLegacyName --- src/pocketmine/entity/Skin.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/pocketmine/entity/Skin.php b/src/pocketmine/entity/Skin.php index 5164e4e51..d5a1477ea 100644 --- a/src/pocketmine/entity/Skin.php +++ b/src/pocketmine/entity/Skin.php @@ -55,10 +55,6 @@ class Skin{ $this->geometryData = $geometryData; } - public static function convertToLegacyName(string $name) : string{ - return '{"geometry" : {"default" : "' . $name . '"}}'; - } - /** * @deprecated * @return bool From 1c67f094e37c6a619b482cb606a144bd8d2c884b Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 11 Nov 2019 15:29:57 -0500 Subject: [PATCH 4/7] Change get and put SkinImage visibility to private --- src/pocketmine/network/mcpe/NetworkBinaryStream.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/network/mcpe/NetworkBinaryStream.php b/src/pocketmine/network/mcpe/NetworkBinaryStream.php index c05b365bf..03b36a544 100644 --- a/src/pocketmine/network/mcpe/NetworkBinaryStream.php +++ b/src/pocketmine/network/mcpe/NetworkBinaryStream.php @@ -120,14 +120,14 @@ class NetworkBinaryStream extends BinaryStream{ $this->putString(""); //fullskinId } - public function getSkinImage() : SkinImage{ + private function getSkinImage() : SkinImage{ $width = $this->getLInt(); $height = $this->getLInt(); $data = $this->getString(); return new SkinImage($height, $width, $data); } - public function putSkinImage(SkinImage $image) : void{ + private function putSkinImage(SkinImage $image) : void{ $this->putLInt($image->getWidth()); $this->putLInt($image->getHeight()); $this->putString($image->getData()); From 5bcbef90ea88d4174afc17bd43250c3865103516 Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 11 Nov 2019 15:32:48 -0500 Subject: [PATCH 5/7] Added variables for getSkin's animation for easier readability --- src/pocketmine/network/mcpe/NetworkBinaryStream.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/network/mcpe/NetworkBinaryStream.php b/src/pocketmine/network/mcpe/NetworkBinaryStream.php index 03b36a544..4c5bb7b8d 100644 --- a/src/pocketmine/network/mcpe/NetworkBinaryStream.php +++ b/src/pocketmine/network/mcpe/NetworkBinaryStream.php @@ -84,7 +84,11 @@ class NetworkBinaryStream extends BinaryStream{ $animationCount = $this->getLInt(); $animations = []; for($i = 0; $i < $animationCount; ++$i){ - $animations[] = new SkinAnimation($this->getSkinImage(), $this->getLInt(), $this->getLFloat()); + $animations[] = new SkinAnimation( + $skinImage = $this->getSkinImage(), + $animationType = $this->getLInt(), + $animationFrames = $this->getLFloat() + ); } $capeData = $this->getSkinImage(); $geometryData = $this->getString(); From a81d8dd6d53788ac59cc3cd52075ccdba72aecee Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 11 Nov 2019 16:25:53 -0500 Subject: [PATCH 6/7] Return false in unexpected condition --- src/pocketmine/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index c70e17772..2be8043a0 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2914,7 +2914,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->sendRespawnPacket($this, RespawnPacket::READY_TO_SPAWN); } - return true; + return false; } /** From ba5a5981a034ead001b9eeefc735904f5c607841 Mon Sep 17 00:00:00 2001 From: Dylan T Date: Tue, 12 Nov 2019 08:19:05 +0000 Subject: [PATCH 7/7] Update Player.php --- src/pocketmine/Player.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 2be8043a0..f60ecc736 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2912,6 +2912,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ public function handleRespawn(RespawnPacket $packet) : bool{ if(!$this->isAlive() && $packet->respawnState === RespawnPacket::CLIENT_READY_TO_SPAWN){ $this->sendRespawnPacket($this, RespawnPacket::READY_TO_SPAWN); + return true; } return false;