mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-08 04:38:35 +00:00
added a dedicated InvalidSkinException
This commit is contained in:
parent
cf06b5b8cf
commit
62ea7c93a9
28
src/pocketmine/entity/InvalidSkinException.php
Normal file
28
src/pocketmine/entity/InvalidSkinException.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\entity;
|
||||||
|
|
||||||
|
final class InvalidSkinException extends \InvalidArgumentException{
|
||||||
|
|
||||||
|
}
|
@ -62,24 +62,24 @@ class Skin{
|
|||||||
try{
|
try{
|
||||||
$this->validate();
|
$this->validate();
|
||||||
return true;
|
return true;
|
||||||
}catch(\InvalidArgumentException $e){
|
}catch(InvalidSkinException $e){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \InvalidArgumentException
|
* @throws InvalidSkinException
|
||||||
*/
|
*/
|
||||||
public function validate() : void{
|
public function validate() : void{
|
||||||
if($this->skinId === ""){
|
if($this->skinId === ""){
|
||||||
throw new \InvalidArgumentException("Skin ID must not be empty");
|
throw new InvalidSkinException("Skin ID must not be empty");
|
||||||
}
|
}
|
||||||
$len = strlen($this->skinData);
|
$len = strlen($this->skinData);
|
||||||
if(!in_array($len, self::ACCEPTED_SKIN_SIZES, true)){
|
if(!in_array($len, self::ACCEPTED_SKIN_SIZES, true)){
|
||||||
throw new \InvalidArgumentException("Invalid skin data size $len bytes (allowed sizes: " . implode(", ", self::ACCEPTED_SKIN_SIZES) . ")");
|
throw new InvalidSkinException("Invalid skin data size $len bytes (allowed sizes: " . implode(", ", self::ACCEPTED_SKIN_SIZES) . ")");
|
||||||
}
|
}
|
||||||
if($this->capeData !== "" and strlen($this->capeData) !== 8192){
|
if($this->capeData !== "" and strlen($this->capeData) !== 8192){
|
||||||
throw new \InvalidArgumentException("Invalid cape data size " . strlen($this->capeData) . " bytes (must be exactly 8192 bytes)");
|
throw new InvalidSkinException("Invalid cape data size " . strlen($this->capeData) . " bytes (must be exactly 8192 bytes)");
|
||||||
}
|
}
|
||||||
//TODO: validate geometry
|
//TODO: validate geometry
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user