mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +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
|
||||
*
|
||||
* @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){
|
||||
if($multiple === true){
|
||||
@ -349,12 +351,12 @@ class ItemFactory{
|
||||
$meta = $b[1] & 0xFFFF;
|
||||
}
|
||||
|
||||
if(defined(ItemIds::class . "::" . strtoupper($b[0]))){
|
||||
$item = self::get(constant(ItemIds::class . "::" . strtoupper($b[0])), $meta);
|
||||
}elseif(is_numeric($b[0])){
|
||||
if(is_numeric($b[0])){
|
||||
$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{
|
||||
$item = self::get(Item::AIR, 0, 0);
|
||||
throw new \InvalidArgumentException("Unable to resolve \"" . $str . "\" to a valid item");
|
||||
}
|
||||
|
||||
return $item;
|
||||
|
Loading…
x
Reference in New Issue
Block a user