mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +00:00
Item: make nbtDeserialize() return AIR when reading an unknown PC item
This is scummy, but it's better than crashing the whole server just because a chest contained an unknown item.
This commit is contained in:
parent
8085b81f5c
commit
5d56030afa
@ -73,6 +73,9 @@ class ItemEntity extends Entity{
|
||||
}
|
||||
|
||||
$this->item = Item::nbtDeserialize($itemTag);
|
||||
if($this->item->isNull()){
|
||||
throw new \UnexpectedValueException("Item for " . get_class($this) . " is invalid");
|
||||
}
|
||||
|
||||
|
||||
$this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
|
||||
|
@ -953,7 +953,12 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
if($idTag instanceof ShortTag){
|
||||
$item = ItemFactory::get(Binary::unsignShort($idTag->getValue()), $meta, $count);
|
||||
}elseif($idTag instanceof StringTag){ //PC item save format
|
||||
$item = ItemFactory::fromString($idTag->getValue());
|
||||
try{
|
||||
$item = ItemFactory::fromString($idTag->getValue());
|
||||
}catch(\InvalidArgumentException $e){
|
||||
//TODO: improve error handling
|
||||
return ItemFactory::get(Item::AIR, 0, 0);
|
||||
}
|
||||
$item->setDamage($meta);
|
||||
$item->setCount($count);
|
||||
}else{
|
||||
|
Loading…
x
Reference in New Issue
Block a user