Updated PocketMine-NBT dependency

This commit is contained in:
Dylan K. Taylor 2018-02-17 14:29:20 +00:00
parent 3f41628bf3
commit 093cb5b39e
10 changed files with 46 additions and 62 deletions

View File

@ -24,7 +24,7 @@
"pocketmine/raklib": "dev-master#9b50878021ca545684fc1fd2d9333911ab2988e1",
"pocketmine/pocketmine-spl": "^0.2.0",
"pocketmine/pocketmine-binaryutils": "dev-master#a7cd5303a3b215d26bf9be76682ce9311f40e887",
"pocketmine/pocketmine-nbt": "dev-master#7186c4a47243f7eb374cbafc31cc797686b61db6"
"pocketmine/pocketmine-nbt": "dev-master#33aaaebab10b501d233b6208d6a170b82f40c3b4"
},
"autoload": {
"psr-4": {

10
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "c7e83c674d1c7756afa995b7f595d790",
"content-hash": "b649f9dd4cf9477cfe9027cdb75858e0",
"packages": [
{
"name": "pocketmine/pocketmine-binaryutils",
@ -45,12 +45,12 @@
"source": {
"type": "git",
"url": "https://github.com/pmmp/PocketMine-NBT.git",
"reference": "7186c4a47243f7eb374cbafc31cc797686b61db6"
"reference": "33aaaebab10b501d233b6208d6a170b82f40c3b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pmmp/PocketMine-NBT/zipball/7186c4a47243f7eb374cbafc31cc797686b61db6",
"reference": "7186c4a47243f7eb374cbafc31cc797686b61db6",
"url": "https://api.github.com/repos/pmmp/PocketMine-NBT/zipball/33aaaebab10b501d233b6208d6a170b82f40c3b4",
"reference": "33aaaebab10b501d233b6208d6a170b82f40c3b4",
"shasum": ""
},
"require": {
@ -76,7 +76,7 @@
"source": "https://github.com/pmmp/PocketMine-NBT/tree/master",
"issues": "https://github.com/pmmp/PocketMine-NBT/issues"
},
"time": "2018-02-14T17:39:47+00:00"
"time": "2018-02-17T14:20:32+00:00"
},
{
"name": "pocketmine/pocketmine-spl",

View File

@ -2789,9 +2789,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$t = $this->level->getTile($pos);
if($t instanceof Spawnable){
$nbt = new NetworkLittleEndianNBTStream();
$nbt->read($packet->namedtag);
$nbt = $nbt->getData();
if(!$t->updateCompoundTag($nbt, $this)){
$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

@ -752,9 +752,12 @@ class Server{
if(file_exists($path . "$name.dat")){
try{
$nbt = new BigEndianNBTStream();
$nbt->readCompressed(file_get_contents($path . "$name.dat"));
$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 $nbt->getData();
return $compound;
}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]));
@ -819,12 +822,10 @@ class Server{
if(!$ev->isCancelled()){
$nbt = new BigEndianNBTStream();
try{
$nbt->setData($ev->getSaveData());
if($async){
$this->getScheduler()->scheduleAsyncTask(new FileWriteTask($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed()));
$this->getScheduler()->scheduleAsyncTask(new FileWriteTask($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed($ev->getSaveData())));
}else{
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed($ev->getSaveData()));
}
}catch(\Throwable $e){
$this->logger->critical($this->getLanguage()->translateString("pocketmine.data.saveError", [$name, $e->getMessage()]));

View File

@ -66,9 +66,7 @@ class Item implements ItemIds, \JsonSerializable{
self::$cachedParser = new LittleEndianNBTStream();
}
self::$cachedParser->read($tag);
$data = self::$cachedParser->getData();
$data = self::$cachedParser->read($tag);
if(!($data instanceof CompoundTag)){
throw new \InvalidArgumentException("Invalid item NBT string given, it could not be deserialized");
}
@ -81,8 +79,7 @@ class Item implements ItemIds, \JsonSerializable{
self::$cachedParser = new LittleEndianNBTStream();
}
self::$cachedParser->setData($tag);
return self::$cachedParser->write();
return self::$cachedParser->write($tag);
}
/**

View File

@ -43,14 +43,14 @@ abstract class BaseLevelProvider implements LevelProvider{
mkdir($this->path, 0777, true);
}
$nbt = new BigEndianNBTStream();
$nbt->readCompressed(file_get_contents($this->getPath() . "level.dat"));
$levelData = $nbt->getData()->getCompoundTag("Data");
if($levelData !== null){
$this->levelData = $levelData;
}else{
$levelData = $nbt->readCompressed(file_get_contents($this->getPath() . "level.dat"));
if(!($levelData instanceof CompoundTag) or !$levelData->hasTag("Data", CompoundTag::class)){
throw new LevelException("Invalid level.dat");
}
$this->levelData = $levelData->getCompoundTag("Data");
if(!$this->levelData->hasTag("generatorName", StringTag::class)){
$this->levelData->setString("generatorName", (string) Generator::getGenerator("DEFAULT"), true);
}
@ -107,10 +107,9 @@ abstract class BaseLevelProvider implements LevelProvider{
public function saveLevelData(){
$nbt = new BigEndianNBTStream();
$nbt->setData(new CompoundTag("", [
$buffer = $nbt->writeCompressed(new CompoundTag("", [
$this->levelData
]));
$buffer = $nbt->writeCompressed();
file_put_contents($this->getPath() . "level.dat", $buffer);
}

View File

@ -95,8 +95,7 @@ class LevelDB extends BaseLevelProvider{
mkdir($this->path, 0777, true);
}
$nbt = new LittleEndianNBTStream();
$nbt->read(substr(file_get_contents($this->getPath() . "level.dat"), 8));
$levelData = $nbt->getData();
$levelData = $nbt->read(substr(file_get_contents($this->getPath() . "level.dat"), 8));
if($levelData instanceof CompoundTag){
$this->levelData = $levelData;
}else{
@ -210,8 +209,7 @@ class LevelDB extends BaseLevelProvider{
]);
$nbt = new LittleEndianNBTStream();
$nbt->setData($levelData);
$buffer = $nbt->write();
$buffer = $nbt->write($levelData);
file_put_contents($path . "level.dat", Binary::writeLInt(self::CURRENT_STORAGE_VERSION) . Binary::writeLInt(strlen($buffer)) . $buffer);
@ -240,8 +238,7 @@ class LevelDB extends BaseLevelProvider{
$this->levelData->setInt("StorageVersion", self::CURRENT_STORAGE_VERSION);
$nbt = new LittleEndianNBTStream();
$nbt->setData($this->levelData);
$buffer = $nbt->write();
$buffer = $nbt->write($this->levelData);
file_put_contents($this->getPath() . "level.dat", Binary::writeLInt(self::CURRENT_STORAGE_VERSION) . Binary::writeLInt(strlen($buffer)) . $buffer);
}
@ -371,8 +368,7 @@ class LevelDB extends BaseLevelProvider{
/** @var CompoundTag[] $entities */
$entities = [];
if(($entityData = $this->db->get($index . self::TAG_ENTITY)) !== false and strlen($entityData) > 0){
$nbt->read($entityData, true);
$entities = $nbt->getData();
$entities = $nbt->read($entityData, true);
if(!is_array($entities)){
$entities = [$entities];
}
@ -387,8 +383,7 @@ class LevelDB extends BaseLevelProvider{
$tiles = [];
if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false and strlen($tileData) > 0){
$nbt->read($tileData, true);
$tiles = $nbt->getData();
$tiles = $nbt->read($tileData, true);
if(!is_array($tiles)){
$tiles = [$tiles];
}
@ -506,8 +501,7 @@ class LevelDB extends BaseLevelProvider{
private function writeTags(array $targets, string $index){
if(!empty($targets)){
$nbt = new LittleEndianNBTStream();
$nbt->setData($targets);
$this->db->put($index, $nbt->write());
$this->db->put($index, $nbt->write($targets));
}else{
$this->db->delete($index);
}

View File

@ -85,10 +85,7 @@ class Anvil extends McRegion{
//TODO: TileTicks
$writer = new BigEndianNBTStream();
$nbt->setName("Level");
$writer->setData(new CompoundTag("", [$nbt]));
return $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
return $writer->writeCompressed(new CompoundTag("", [$nbt]), ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
}
protected function serializeSubChunk(SubChunk $subChunk) : CompoundTag{
@ -103,14 +100,13 @@ class Anvil extends McRegion{
public function nbtDeserialize(string $data){
$nbt = new BigEndianNBTStream();
try{
$nbt->readCompressed($data);
$chunk = $nbt->getData()->getCompoundTag("Level");
if($chunk === null){
$chunk = $nbt->readCompressed($data);
if(!($chunk instanceof CompoundTag) or !$chunk->hasTag("Level")){
throw new ChunkException("Invalid NBT format");
}
$chunk = $chunk->getCompoundTag("Level");
$subChunks = [];
$subChunksTag = $chunk->getListTag("Sections") ?? [];
foreach($subChunksTag as $subChunk){

View File

@ -101,10 +101,7 @@ class McRegion extends BaseLevelProvider{
$nbt->setTag(new ListTag("TileEntities", $tiles, NBT::TAG_Compound));
$writer = new BigEndianNBTStream();
$nbt->setName("Level");
$writer->setData(new CompoundTag("", [$nbt]));
return $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
return $writer->writeCompressed(new CompoundTag("", [$nbt]), ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
}
/**
@ -115,14 +112,13 @@ class McRegion extends BaseLevelProvider{
public function nbtDeserialize(string $data){
$nbt = new BigEndianNBTStream();
try{
$nbt->readCompressed($data);
$chunk = $nbt->getData()->getCompoundTag("Level");
if($chunk === null){
throw new ChunkException("Invalid NBT format, 'Level' key not found");
$chunk = $nbt->readCompressed($data);
if(!($chunk instanceof CompoundTag) or !$chunk->hasTag("Level")){
throw new ChunkException("Invalid NBT format");
}
$chunk = $chunk->getCompoundTag("Level");
$subChunks = [];
$fullIds = $chunk->hasTag("Blocks", ByteArrayTag::class) ? $chunk->getByteArray("Blocks") : str_repeat("\x00", 32768);
$fullData = $chunk->hasTag("Data", ByteArrayTag::class) ? $chunk->getByteArray("Data") : str_repeat("\x00", 16384);
@ -257,10 +253,9 @@ class McRegion extends BaseLevelProvider{
new CompoundTag("GameRules", [])
]);
$nbt = new BigEndianNBTStream();
$nbt->setData(new CompoundTag("", [
$buffer = $nbt->writeCompressed(new CompoundTag("", [
$levelData
]));
$buffer = $nbt->writeCompressed();
file_put_contents($path . "level.dat", $buffer);
}

View File

@ -95,8 +95,7 @@ abstract class Spawnable extends Tile{
self::$nbtWriter = new NetworkLittleEndianNBTStream();
}
self::$nbtWriter->setData($this->getSpawnCompound());
$this->spawnCompoundCache = self::$nbtWriter->write();
$this->spawnCompoundCache = self::$nbtWriter->write($this->getSpawnCompound());
}
return $this->spawnCompoundCache;