mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-14 22:01:59 +00:00
ItemFactory: Throw exception on failure to parse string as an item in fromString()
closes #1487
This commit is contained in:
parent
af2435f199
commit
4c583ec8ab
@ -332,6 +332,8 @@ class ItemFactory{
|
|||||||
* @param bool $multiple
|
* @param bool $multiple
|
||||||
*
|
*
|
||||||
* @return Item[]|Item
|
* @return Item[]|Item
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException if the given string cannot be parsed as an item identifier
|
||||||
*/
|
*/
|
||||||
public static function fromString(string $str, bool $multiple = false){
|
public static function fromString(string $str, bool $multiple = false){
|
||||||
if($multiple === true){
|
if($multiple === true){
|
||||||
@ -349,12 +351,12 @@ class ItemFactory{
|
|||||||
$meta = $b[1] & 0xFFFF;
|
$meta = $b[1] & 0xFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(defined(ItemIds::class . "::" . strtoupper($b[0]))){
|
if(is_numeric($b[0])){
|
||||||
$item = self::get(constant(ItemIds::class . "::" . strtoupper($b[0])), $meta);
|
|
||||||
}elseif(is_numeric($b[0])){
|
|
||||||
$item = self::get(((int) $b[0]) & 0xFFFF, $meta);
|
$item = self::get(((int) $b[0]) & 0xFFFF, $meta);
|
||||||
|
}elseif(defined(ItemIds::class . "::" . strtoupper($b[0]))){
|
||||||
|
$item = self::get(constant(ItemIds::class . "::" . strtoupper($b[0])), $meta);
|
||||||
}else{
|
}else{
|
||||||
$item = self::get(Item::AIR, 0, 0);
|
throw new \InvalidArgumentException("Unable to resolve \"" . $str . "\" to a valid item");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user