Update to latest NBT lib version

This commit is contained in:
Dylan K. Taylor 2018-10-23 16:47:00 +01:00
parent a49abff099
commit 011b9ae159
10 changed files with 23 additions and 43 deletions

View File

@ -30,7 +30,7 @@
"pocketmine/raklib": "^0.12.0",
"pocketmine/spl": "^0.3.0",
"pocketmine/binaryutils": "^0.1.0",
"pocketmine/nbt": "^0.2.1",
"pocketmine/nbt": "dev-master",
"pocketmine/math": "dev-master",
"pocketmine/snooze": "^0.1.0"
},

15
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "cef68cbc2596130f6b20e6f2ecdfd58d",
"content-hash": "28f054aefede2c0dc4f220d5c4a918a0",
"packages": [
{
"name": "fgrosse/phpasn1",
@ -222,16 +222,16 @@
},
{
"name": "pocketmine/nbt",
"version": "0.2.2",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/pmmp/NBT.git",
"reference": "474f0cf0a47656d0122b4f3f71302e694ed6977b"
"reference": "db491f3309231e56f2640a047f665a0131c23538"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pmmp/NBT/zipball/474f0cf0a47656d0122b4f3f71302e694ed6977b",
"reference": "474f0cf0a47656d0122b4f3f71302e694ed6977b",
"url": "https://api.github.com/repos/pmmp/NBT/zipball/db491f3309231e56f2640a047f665a0131c23538",
"reference": "db491f3309231e56f2640a047f665a0131c23538",
"shasum": ""
},
"require": {
@ -255,10 +255,10 @@
],
"description": "PHP library for working with Named Binary Tags",
"support": {
"source": "https://github.com/pmmp/NBT/tree/0.2.2",
"source": "https://github.com/pmmp/NBT/tree/master",
"issues": "https://github.com/pmmp/NBT/issues"
},
"time": "2018-10-12T08:26:44+00:00"
"time": "2018-10-23T15:23:36+00:00"
},
{
"name": "pocketmine/raklib",
@ -373,6 +373,7 @@
"minimum-stability": "stable",
"stability-flags": {
"ext-pthreads": 20,
"pocketmine/nbt": 20,
"pocketmine/math": 20
},
"prefer-stable": false,

View File

@ -2435,10 +2435,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if($t instanceof Spawnable){
$nbt = new NetworkLittleEndianNBTStream();
$compound = $nbt->read($packet->namedtag);
if(!($compound instanceof CompoundTag)){
throw new \InvalidArgumentException("Expected " . CompoundTag::class . " in block entity NBT, got " . (is_object($compound) ? get_class($compound) : gettype($compound)));
}
if(!$t->updateCompoundTag($compound, $this)){
$t->spawnTo($this);
}

View File

@ -751,12 +751,7 @@ class Server{
if(file_exists($path . "$name.dat")){
try{
$nbt = new BigEndianNBTStream();
$compound = $nbt->readCompressed(file_get_contents($path . "$name.dat"));
if(!($compound instanceof CompoundTag)){
throw new \RuntimeException("Invalid data found in \"$name.dat\", expected " . CompoundTag::class . ", got " . (is_object($compound) ? get_class($compound) : gettype($compound)));
}
return $compound;
return $nbt->readCompressed(file_get_contents($path . "$name.dat"));
}catch(\Throwable $e){ //zlib decode error / corrupt data
rename($path . "$name.dat", $path . "$name.dat.bak");
$this->logger->notice($this->getLanguage()->translateString("pocketmine.data.playerCorrupted", [$name]));

View File

@ -65,12 +65,7 @@ class Item implements ItemIds, \JsonSerializable{
self::$cachedParser = new LittleEndianNBTStream();
}
$data = self::$cachedParser->read($tag);
if(!($data instanceof CompoundTag)){
throw new \InvalidArgumentException("Invalid item NBT string given, it could not be deserialized");
}
return $data;
return self::$cachedParser->read($tag);
}
private static function writeCompoundTag(CompoundTag $tag) : string{

View File

@ -100,15 +100,13 @@ class BedrockLevelData extends BaseNbtLevelData{
protected function load() : ?CompoundTag{
$nbt = new LittleEndianNBTStream();
$levelData = $nbt->read(substr(file_get_contents($this->dataPath), 8));
if($levelData instanceof CompoundTag){
$version = $levelData->getInt("StorageVersion", INT32_MAX, true);
if($version > self::CURRENT_STORAGE_VERSION){
throw new UnsupportedLevelFormatException("Specified LevelDB world format version ($version) is not supported by " . \pocketmine\NAME);
}
return $levelData;
$version = $levelData->getInt("StorageVersion", INT32_MAX, true);
if($version > self::CURRENT_STORAGE_VERSION){
throw new UnsupportedLevelFormatException("Specified LevelDB world format version ($version) is not supported by " . \pocketmine\NAME);
}
return null;
return $levelData;
}
protected function fix() : void{

View File

@ -67,7 +67,7 @@ class JavaLevelData extends BaseNbtLevelData{
protected function load() : ?CompoundTag{
$nbt = new BigEndianNBTStream();
$levelData = $nbt->readCompressed(file_get_contents($this->dataPath));
if($levelData instanceof CompoundTag and $levelData->hasTag("Data", CompoundTag::class)){
if($levelData->hasTag("Data", CompoundTag::class)){
return $levelData->getCompoundTag("Data");
}
return null;

View File

@ -225,10 +225,7 @@ class LevelDB extends BaseLevelProvider{
/** @var CompoundTag[] $entities */
$entities = [];
if(($entityData = $this->db->get($index . self::TAG_ENTITY)) !== false and $entityData !== ""){
$entities = $nbt->read($entityData, true);
if(!is_array($entities)){
$entities = [$entities];
}
$entities = $nbt->readMultiple($entityData);
}
/** @var CompoundTag $entityNBT */
@ -238,12 +235,10 @@ class LevelDB extends BaseLevelProvider{
}
}
/** @var CompoundTag[] $tiles */
$tiles = [];
if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false and $tileData !== ""){
$tiles = $nbt->read($tileData, true);
if(!is_array($tiles)){
$tiles = [$tiles];
}
$tiles = $nbt->readMultiple($tileData);
}
//TODO: extra data should be converted into blockstorage layers (first they need to be implemented!)
@ -326,7 +321,7 @@ class LevelDB extends BaseLevelProvider{
private function writeTags(array $targets, string $index) : void{
if(!empty($targets)){
$nbt = new LittleEndianNBTStream();
$this->db->put($index, $nbt->write($targets));
$this->db->put($index, $nbt->writeMultiple($targets));
}else{
$this->db->delete($index);
}

View File

@ -98,7 +98,7 @@ trait LegacyAnvilChunkTrait{
protected function deserializeChunk(string $data) : Chunk{
$nbt = new BigEndianNBTStream();
$chunk = $nbt->readCompressed($data);
if(!($chunk instanceof CompoundTag) or !$chunk->hasTag("Level")){
if(!$chunk->hasTag("Level")){
throw new ChunkException("Invalid NBT format");
}

View File

@ -102,7 +102,7 @@ class McRegion extends RegionLevelProvider{
protected function deserializeChunk(string $data) : Chunk{
$nbt = new BigEndianNBTStream();
$chunk = $nbt->readCompressed($data);
if(!($chunk instanceof CompoundTag) or !$chunk->hasTag("Level")){
if(!$chunk->hasTag("Level")){
throw new ChunkException("Invalid NBT format");
}