mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-18 19:55:33 +00:00
AvailableEnchantmentRegistry: reject non-string tags
fixes https://crash.pmmp.io/view/12627328
This commit is contained in:
parent
f661443ec7
commit
2548422973
@ -28,6 +28,7 @@ use pocketmine\item\enchantment\ItemEnchantmentTags as Tags;
|
|||||||
use pocketmine\item\enchantment\VanillaEnchantments as Enchantments;
|
use pocketmine\item\enchantment\VanillaEnchantments as Enchantments;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\utils\SingletonTrait;
|
use pocketmine\utils\SingletonTrait;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use function array_filter;
|
use function array_filter;
|
||||||
use function array_values;
|
use function array_values;
|
||||||
use function count;
|
use function count;
|
||||||
@ -129,6 +130,7 @@ final class AvailableEnchantmentRegistry{
|
|||||||
if(!$this->isRegistered($enchantment)){
|
if(!$this->isRegistered($enchantment)){
|
||||||
throw new \LogicException("Cannot set primary item tags for non-registered enchantment");
|
throw new \LogicException("Cannot set primary item tags for non-registered enchantment");
|
||||||
}
|
}
|
||||||
|
Utils::validateArrayValueType($tags, fn(string $v) => 1);
|
||||||
$this->primaryItemTags[spl_object_id($enchantment)] = array_values($tags);
|
$this->primaryItemTags[spl_object_id($enchantment)] = array_values($tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,6 +154,7 @@ final class AvailableEnchantmentRegistry{
|
|||||||
if(!$this->isRegistered($enchantment)){
|
if(!$this->isRegistered($enchantment)){
|
||||||
throw new \LogicException("Cannot set secondary item tags for non-registered enchantment");
|
throw new \LogicException("Cannot set secondary item tags for non-registered enchantment");
|
||||||
}
|
}
|
||||||
|
Utils::validateArrayValueType($tags, fn(string $v) => 1);
|
||||||
$this->secondaryItemTags[spl_object_id($enchantment)] = array_values($tags);
|
$this->secondaryItemTags[spl_object_id($enchantment)] = array_values($tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,7 +584,7 @@ final class Utils{
|
|||||||
/**
|
/**
|
||||||
* @phpstan-template TMemberType
|
* @phpstan-template TMemberType
|
||||||
* @phpstan-param array<mixed, TMemberType> $array
|
* @phpstan-param array<mixed, TMemberType> $array
|
||||||
* @phpstan-param \Closure(TMemberType) : void $validator
|
* @phpstan-param \Closure(TMemberType) : mixed $validator
|
||||||
*/
|
*/
|
||||||
public static function validateArrayValueType(array $array, \Closure $validator) : void{
|
public static function validateArrayValueType(array $array, \Closure $validator) : void{
|
||||||
foreach(Utils::promoteKeys($array) as $k => $v){
|
foreach(Utils::promoteKeys($array) as $k => $v){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user