Generate getters for SkinData, applied suggested change, and fixed an underfined variable in PlayerListPacket

This commit is contained in:
Stephen 2019-11-21 13:52:27 -05:00
parent 6105198313
commit 4340349db7
4 changed files with 108 additions and 30 deletions

View File

@ -104,22 +104,22 @@ class NetworkBinaryStream extends BinaryStream{
} }
public function putSkin(SkinData $skin){ public function putSkin(SkinData $skin){
$this->putString($skin->skinId); $this->putString($skin->getSkinId());
$this->putString($skin->resourcePatch); //resource patch $this->putString($skin->getResourcePatch());
$this->putSkinImage($skin->skinImage); $this->putSkinImage($skin->getSkinImage());
$this->putLInt(count($skin->animations)); $this->putLInt(count($skin->getAnimations()));
foreach($skin->animations as $animation){ foreach($skin->getAnimations() as $animation){
$this->putSkinImage($animation->getImage()); $this->putSkinImage($animation->getImage());
$this->putLInt($animation->getType()); $this->putLInt($animation->getType());
$this->putLFloat($animation->getFrames()); $this->putLFloat($animation->getFrames());
} }
$this->putSkinImage($skin->capeImage); $this->putSkinImage($skin->getCapeImage());
$this->putString($skin->geometryData); $this->putString($skin->getGeometryData());
$this->putString($skin->animationData); $this->putString($skin->getAnimationData());
$this->putBool($skin->premium); $this->putBool($skin->isPremium());
$this->putBool($skin->persona); $this->putBool($skin->isPersona());
$this->putBool($skin->capeOnClassic); $this->putBool($skin->isPersonaCapeOnClassic());
$this->putString($skin->capeId); $this->putString($skin->getCapeId());
//this has to be unique or the client will do stupid things //this has to be unique or the client will do stupid things
$this->putString(UUID::fromRandom()->toString()); //full skin ID $this->putString(UUID::fromRandom()->toString()); //full skin ID

View File

@ -60,7 +60,7 @@ class PlayerListPacket extends DataPacket{
$entry->xboxUserId = $this->getString(); $entry->xboxUserId = $this->getString();
$entry->platformChatId = $this->getString(); $entry->platformChatId = $this->getString();
$entry->buildPlatform = $this->getLInt(); $entry->buildPlatform = $this->getLInt();
$entry->skin = $this->getSkin(); $entry->skinData = $this->getSkin();
$entry->isTeacher = $this->getBool(); $entry->isTeacher = $this->getBool();
$entry->isHost = $this->getBool(); $entry->isHost = $this->getBool();
}else{ }else{

View File

@ -32,10 +32,10 @@ class LegacySkinAdapter implements SkinAdapter{
} }
public function fromSkinData(SkinData $data) : Skin{ public function fromSkinData(SkinData $data) : Skin{
$skinData = $data->skinImage->getData(); $skinData = $data->getSkinImage()->getData();
if($data->persona){ if($data->isPersona()){
$skinData = str_repeat(random_bytes(3) . "\xff", 2048); return new Skin("Standard_Custom", str_repeat(random_bytes(3) . "\xff", 2048), "", "geometry.humanoid.custom");
} }
return new Skin($data->skinId, $skinData, $data->capeImage->getData(), json_decode($data->resourcePatch, true)["geometry"]["default"], $data->geometryData); return new Skin($data->getSkinId(), $skinData, $data->getCapeImage()->getData(), json_decode($data->getResourcePatch(), true)["geometry"]["default"], $data->getGeometryData());
} }
} }

View File

@ -26,29 +26,29 @@ namespace pocketmine\network\mcpe\protocol\types;
class SkinData{ class SkinData{
/** @var string */ /** @var string */
public $skinId; private $skinId;
/** @var string */ /** @var string */
public $resourcePatch; private $resourcePatch;
/** @var SkinImage */ /** @var SkinImage */
public $skinImage; private $skinImage;
/** @var SkinAnimation[] */ /** @var SkinAnimation[] */
public $animations; private $animations;
/** @var SkinImage */ /** @var SkinImage */
public $capeImage; private $capeImage;
/** @var string */ /** @var string */
public $geometryData; private $geometryData;
/** @var string */ /** @var string */
public $animationData; private $animationData;
/** @var bool */ /** @var bool */
public $persona; private $persona;
/** @var bool */ /** @var bool */
public $premium; private $premium;
/** @var bool */ /** @var bool */
public $capeOnClassic; private $personaCapeOnClassic;
/** @var string */ /** @var string */
public $capeId; private $capeId;
public function __construct(string $skinId, string $resourcePatch, SkinImage $skinImage, array $animations = [], SkinImage $capeImage = null, string $geometryData = "", string $animationData = "", bool $premium = false, bool $persona = false, bool $capeOnClassic = false, string $capeId = ""){ public function __construct(string $skinId, string $resourcePatch, SkinImage $skinImage, array $animations = [], SkinImage $capeImage = null, string $geometryData = "", string $animationData = "", bool $premium = false, bool $persona = false, bool $personaCapeOnClassic = false, string $capeId = ""){
$this->skinId = $skinId; $this->skinId = $skinId;
$this->resourcePatch = $resourcePatch; $this->resourcePatch = $resourcePatch;
$this->skinImage = $skinImage; $this->skinImage = $skinImage;
@ -58,7 +58,85 @@ class SkinData{
$this->animationData = $animationData; $this->animationData = $animationData;
$this->premium = $premium; $this->premium = $premium;
$this->persona = $persona; $this->persona = $persona;
$this->capeOnClassic = $capeOnClassic; $this->personaCapeOnClassic = $personaCapeOnClassic;
$this->capeId = $capeId; $this->capeId = $capeId;
} }
/**
* @return string
*/
public function getSkinId() : string{
return $this->skinId;
}
/**
* @return string
*/
public function getResourcePatch() : string{
return $this->resourcePatch;
}
/**
* @return SkinImage
*/
public function getSkinImage() : SkinImage{
return $this->skinImage;
}
/**
* @return SkinAnimation[]
*/
public function getAnimations() : array{
return $this->animations;
}
/**
* @return SkinImage
*/
public function getCapeImage() : SkinImage{
return $this->capeImage;
}
/**
* @return string
*/
public function getGeometryData() : string{
return $this->geometryData;
}
/**
* @return string
*/
public function getAnimationData() : string{
return $this->animationData;
}
/**
* @return bool
*/
public function isPersona() : bool{
return $this->persona;
}
/**
* @return bool
*/
public function isPremium() : bool{
return $this->premium;
}
/**
* @return bool
*/
public function isPersonaCapeOnClassic() : bool{
return $this->personaCapeOnClassic;
}
/**
* @return string
*/
public function getCapeId() : string{
return $this->capeId;
}
} }