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){
$this->putString($skin->skinId);
$this->putString($skin->resourcePatch); //resource patch
$this->putSkinImage($skin->skinImage);
$this->putLInt(count($skin->animations));
foreach($skin->animations as $animation){
$this->putString($skin->getSkinId());
$this->putString($skin->getResourcePatch());
$this->putSkinImage($skin->getSkinImage());
$this->putLInt(count($skin->getAnimations()));
foreach($skin->getAnimations() as $animation){
$this->putSkinImage($animation->getImage());
$this->putLInt($animation->getType());
$this->putLFloat($animation->getFrames());
}
$this->putSkinImage($skin->capeImage);
$this->putString($skin->geometryData);
$this->putString($skin->animationData);
$this->putBool($skin->premium);
$this->putBool($skin->persona);
$this->putBool($skin->capeOnClassic);
$this->putString($skin->capeId);
$this->putSkinImage($skin->getCapeImage());
$this->putString($skin->getGeometryData());
$this->putString($skin->getAnimationData());
$this->putBool($skin->isPremium());
$this->putBool($skin->isPersona());
$this->putBool($skin->isPersonaCapeOnClassic());
$this->putString($skin->getCapeId());
//this has to be unique or the client will do stupid things
$this->putString(UUID::fromRandom()->toString()); //full skin ID

View File

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

View File

@ -32,10 +32,10 @@ class LegacySkinAdapter implements SkinAdapter{
}
public function fromSkinData(SkinData $data) : Skin{
$skinData = $data->skinImage->getData();
if($data->persona){
$skinData = str_repeat(random_bytes(3) . "\xff", 2048);
$skinData = $data->getSkinImage()->getData();
if($data->isPersona()){
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{
/** @var string */
public $skinId;
private $skinId;
/** @var string */
public $resourcePatch;
private $resourcePatch;
/** @var SkinImage */
public $skinImage;
private $skinImage;
/** @var SkinAnimation[] */
public $animations;
private $animations;
/** @var SkinImage */
public $capeImage;
private $capeImage;
/** @var string */
public $geometryData;
private $geometryData;
/** @var string */
public $animationData;
private $animationData;
/** @var bool */
public $persona;
private $persona;
/** @var bool */
public $premium;
private $premium;
/** @var bool */
public $capeOnClassic;
private $personaCapeOnClassic;
/** @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->resourcePatch = $resourcePatch;
$this->skinImage = $skinImage;
@ -58,7 +58,85 @@ class SkinData{
$this->animationData = $animationData;
$this->premium = $premium;
$this->persona = $persona;
$this->capeOnClassic = $capeOnClassic;
$this->personaCapeOnClassic = $personaCapeOnClassic;
$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;
}
}