mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-18 04:00:29 +00:00
LegacyStringToItemParser: Throw more specific exceptions
This commit is contained in:
@@ -680,7 +680,7 @@ class Item implements \JsonSerializable{
|
||||
}elseif($idTag instanceof StringTag){ //PC item save format
|
||||
try{
|
||||
$item = LegacyStringToItemParser::getInstance()->parse($idTag->getValue() . ":$meta");
|
||||
}catch(\InvalidArgumentException $e){
|
||||
}catch(LegacyStringToItemParserException $e){
|
||||
//TODO: improve error handling
|
||||
return ItemFactory::air();
|
||||
}
|
||||
|
@@ -87,7 +87,7 @@ final class LegacyStringToItemParser{
|
||||
* - `minecraft:string`
|
||||
* - `351:4 (lapis lazuli ID:meta)`
|
||||
*
|
||||
* @throws \InvalidArgumentException if the given string cannot be parsed as an item identifier
|
||||
* @throws LegacyStringToItemParserException if the given string cannot be parsed as an item identifier
|
||||
*/
|
||||
public function parse(string $input) : Item{
|
||||
$key = $this->reprocess($input);
|
||||
@@ -98,7 +98,7 @@ final class LegacyStringToItemParser{
|
||||
}elseif(is_numeric($b[1])){
|
||||
$meta = (int) $b[1];
|
||||
}else{
|
||||
throw new \InvalidArgumentException("Unable to parse \"" . $b[1] . "\" from \"" . $input . "\" as a valid meta value");
|
||||
throw new LegacyStringToItemParserException("Unable to parse \"" . $b[1] . "\" from \"" . $input . "\" as a valid meta value");
|
||||
}
|
||||
|
||||
if(is_numeric($b[0])){
|
||||
@@ -106,7 +106,7 @@ final class LegacyStringToItemParser{
|
||||
}elseif(isset($this->map[strtolower($b[0])])){
|
||||
$item = $this->itemFactory->get($this->map[strtolower($b[0])], $meta);
|
||||
}else{
|
||||
throw new \InvalidArgumentException("Unable to resolve \"" . $input . "\" to a valid item");
|
||||
throw new LegacyStringToItemParserException("Unable to resolve \"" . $input . "\" to a valid item");
|
||||
}
|
||||
|
||||
return $item;
|
||||
|
28
src/item/LegacyStringToItemParserException.php
Normal file
28
src/item/LegacyStringToItemParserException.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\item;
|
||||
|
||||
final class LegacyStringToItemParserException extends \UnexpectedValueException{
|
||||
|
||||
}
|
Reference in New Issue
Block a user