mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
ItemDeserializer: throw a more specific exception on unknown items
This commit is contained in:
parent
eb8fb63409
commit
b4ce5ed515
@ -30,6 +30,7 @@ use pocketmine\block\utils\TreeType;
|
|||||||
use pocketmine\block\VanillaBlocks as Blocks;
|
use pocketmine\block\VanillaBlocks as Blocks;
|
||||||
use pocketmine\data\bedrock\block\BlockStateDeserializeException;
|
use pocketmine\data\bedrock\block\BlockStateDeserializeException;
|
||||||
use pocketmine\data\bedrock\block\BlockStateDeserializer;
|
use pocketmine\data\bedrock\block\BlockStateDeserializer;
|
||||||
|
use pocketmine\data\bedrock\block\convert\UnsupportedBlockStateException;
|
||||||
use pocketmine\data\bedrock\CompoundTypeIds;
|
use pocketmine\data\bedrock\CompoundTypeIds;
|
||||||
use pocketmine\data\bedrock\DyeColorIdMap;
|
use pocketmine\data\bedrock\DyeColorIdMap;
|
||||||
use pocketmine\data\bedrock\EntityLegacyIds;
|
use pocketmine\data\bedrock\EntityLegacyIds;
|
||||||
@ -71,6 +72,8 @@ final class ItemDeserializer{
|
|||||||
//TODO: this is rough duct tape; we need a better way to deal with this
|
//TODO: this is rough duct tape; we need a better way to deal with this
|
||||||
try{
|
try{
|
||||||
$block = $this->blockStateDeserializer->deserialize($blockData);
|
$block = $this->blockStateDeserializer->deserialize($blockData);
|
||||||
|
}catch(UnsupportedBlockStateException $e){
|
||||||
|
throw new UnsupportedItemTypeException($e->getMessage(), 0, $e);
|
||||||
}catch(BlockStateDeserializeException $e){
|
}catch(BlockStateDeserializeException $e){
|
||||||
throw new ItemTypeDeserializeException("Failed to deserialize item data: " . $e->getMessage(), 0, $e);
|
throw new ItemTypeDeserializeException("Failed to deserialize item data: " . $e->getMessage(), 0, $e);
|
||||||
}
|
}
|
||||||
@ -80,7 +83,7 @@ final class ItemDeserializer{
|
|||||||
}
|
}
|
||||||
$id = $data->getName();
|
$id = $data->getName();
|
||||||
if(!isset($this->deserializers[$id])){
|
if(!isset($this->deserializers[$id])){
|
||||||
throw new ItemTypeDeserializeException("No deserializer found for ID $id");
|
throw new UnsupportedItemTypeException("No deserializer found for ID $id");
|
||||||
}
|
}
|
||||||
|
|
||||||
return ($this->deserializers[$id])($data);
|
return ($this->deserializers[$id])($data);
|
||||||
|
@ -23,6 +23,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\data\bedrock\item;
|
namespace pocketmine\data\bedrock\item;
|
||||||
|
|
||||||
final class ItemTypeDeserializeException extends \RuntimeException{
|
class ItemTypeDeserializeException extends \RuntimeException{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
28
src/data/bedrock/item/UnsupportedItemTypeException.php
Normal file
28
src/data/bedrock/item/UnsupportedItemTypeException.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\data\bedrock\item;
|
||||||
|
|
||||||
|
final class UnsupportedItemTypeException extends ItemTypeDeserializeException{
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user