35 public const ACCEPTED_SKIN_SIZES = [
41 private string $skinId;
42 private string $skinData;
43 private string $capeData;
44 private string $geometryName;
45 private string $geometryData;
47 private static function checkLength(
string $string,
string $name,
int $maxLength) :
void{
48 if(strlen($string) > $maxLength){
49 throw new InvalidSkinException(
"$name must be at most $maxLength bytes, but have " . strlen($string) .
" bytes");
53 public function __construct(
string $skinId,
string $skinData,
string $capeData =
"",
string $geometryName =
"",
string $geometryData =
""){
54 self::checkLength($skinId,
"Skin ID", Limits::INT16_MAX);
55 self::checkLength($geometryName,
"Geometry name", Limits::INT16_MAX);
56 self::checkLength($geometryData,
"Geometry data", Limits::INT32_MAX);
61 $len = strlen($skinData);
62 if(!in_array($len, self::ACCEPTED_SKIN_SIZES,
true)){
63 throw new InvalidSkinException(
"Invalid skin data size $len bytes (allowed sizes: " . implode(
", ", self::ACCEPTED_SKIN_SIZES) .
")");
65 if($capeData !==
"" && strlen($capeData) !== 8192){
66 throw new InvalidSkinException(
"Invalid cape data size " . strlen($capeData) .
" bytes (must be exactly 8192 bytes)");
69 if($geometryData !==
""){
71 $decodedGeometry = (
new CommentedJsonDecoder())->decode($geometryData);
72 }
catch(\RuntimeException $e){
83 $geometryData = json_encode($decodedGeometry, JSON_THROW_ON_ERROR);
86 $this->skinId = $skinId;
87 $this->skinData = $skinData;
88 $this->capeData = $capeData;
89 $this->geometryName = $geometryName;
90 $this->geometryData = $geometryData;
93 public function getSkinId() :
string{
97 public function getSkinData() :
string{
98 return $this->skinData;
101 public function getCapeData() :
string{
102 return $this->capeData;
105 public function getGeometryName() :
string{
106 return $this->geometryName;
109 public function getGeometryData() :
string{
110 return $this->geometryData;