mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 09:10:00 +00:00
Updated PocketMine-NBT dependency
This commit is contained in:
parent
3f41628bf3
commit
093cb5b39e
@ -24,7 +24,7 @@
|
|||||||
"pocketmine/raklib": "dev-master#9b50878021ca545684fc1fd2d9333911ab2988e1",
|
"pocketmine/raklib": "dev-master#9b50878021ca545684fc1fd2d9333911ab2988e1",
|
||||||
"pocketmine/pocketmine-spl": "^0.2.0",
|
"pocketmine/pocketmine-spl": "^0.2.0",
|
||||||
"pocketmine/pocketmine-binaryutils": "dev-master#a7cd5303a3b215d26bf9be76682ce9311f40e887",
|
"pocketmine/pocketmine-binaryutils": "dev-master#a7cd5303a3b215d26bf9be76682ce9311f40e887",
|
||||||
"pocketmine/pocketmine-nbt": "dev-master#7186c4a47243f7eb374cbafc31cc797686b61db6"
|
"pocketmine/pocketmine-nbt": "dev-master#33aaaebab10b501d233b6208d6a170b82f40c3b4"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
10
composer.lock
generated
10
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "c7e83c674d1c7756afa995b7f595d790",
|
"content-hash": "b649f9dd4cf9477cfe9027cdb75858e0",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "pocketmine/pocketmine-binaryutils",
|
"name": "pocketmine/pocketmine-binaryutils",
|
||||||
@ -45,12 +45,12 @@
|
|||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/pmmp/PocketMine-NBT.git",
|
"url": "https://github.com/pmmp/PocketMine-NBT.git",
|
||||||
"reference": "7186c4a47243f7eb374cbafc31cc797686b61db6"
|
"reference": "33aaaebab10b501d233b6208d6a170b82f40c3b4"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/pmmp/PocketMine-NBT/zipball/7186c4a47243f7eb374cbafc31cc797686b61db6",
|
"url": "https://api.github.com/repos/pmmp/PocketMine-NBT/zipball/33aaaebab10b501d233b6208d6a170b82f40c3b4",
|
||||||
"reference": "7186c4a47243f7eb374cbafc31cc797686b61db6",
|
"reference": "33aaaebab10b501d233b6208d6a170b82f40c3b4",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -76,7 +76,7 @@
|
|||||||
"source": "https://github.com/pmmp/PocketMine-NBT/tree/master",
|
"source": "https://github.com/pmmp/PocketMine-NBT/tree/master",
|
||||||
"issues": "https://github.com/pmmp/PocketMine-NBT/issues"
|
"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",
|
"name": "pocketmine/pocketmine-spl",
|
||||||
|
@ -2789,9 +2789,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
$t = $this->level->getTile($pos);
|
$t = $this->level->getTile($pos);
|
||||||
if($t instanceof Spawnable){
|
if($t instanceof Spawnable){
|
||||||
$nbt = new NetworkLittleEndianNBTStream();
|
$nbt = new NetworkLittleEndianNBTStream();
|
||||||
$nbt->read($packet->namedtag);
|
$compound = $nbt->read($packet->namedtag);
|
||||||
$nbt = $nbt->getData();
|
|
||||||
if(!$t->updateCompoundTag($nbt, $this)){
|
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);
|
$t->spawnTo($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -752,9 +752,12 @@ class Server{
|
|||||||
if(file_exists($path . "$name.dat")){
|
if(file_exists($path . "$name.dat")){
|
||||||
try{
|
try{
|
||||||
$nbt = new BigEndianNBTStream();
|
$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
|
}catch(\Throwable $e){ //zlib decode error / corrupt data
|
||||||
rename($path . "$name.dat", $path . "$name.dat.bak");
|
rename($path . "$name.dat", $path . "$name.dat.bak");
|
||||||
$this->logger->notice($this->getLanguage()->translateString("pocketmine.data.playerCorrupted", [$name]));
|
$this->logger->notice($this->getLanguage()->translateString("pocketmine.data.playerCorrupted", [$name]));
|
||||||
@ -819,12 +822,10 @@ class Server{
|
|||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$nbt = new BigEndianNBTStream();
|
$nbt = new BigEndianNBTStream();
|
||||||
try{
|
try{
|
||||||
$nbt->setData($ev->getSaveData());
|
|
||||||
|
|
||||||
if($async){
|
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{
|
}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){
|
}catch(\Throwable $e){
|
||||||
$this->logger->critical($this->getLanguage()->translateString("pocketmine.data.saveError", [$name, $e->getMessage()]));
|
$this->logger->critical($this->getLanguage()->translateString("pocketmine.data.saveError", [$name, $e->getMessage()]));
|
||||||
|
@ -66,9 +66,7 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
self::$cachedParser = new LittleEndianNBTStream();
|
self::$cachedParser = new LittleEndianNBTStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$cachedParser->read($tag);
|
$data = self::$cachedParser->read($tag);
|
||||||
$data = self::$cachedParser->getData();
|
|
||||||
|
|
||||||
if(!($data instanceof CompoundTag)){
|
if(!($data instanceof CompoundTag)){
|
||||||
throw new \InvalidArgumentException("Invalid item NBT string given, it could not be deserialized");
|
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 = new LittleEndianNBTStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$cachedParser->setData($tag);
|
return self::$cachedParser->write($tag);
|
||||||
return self::$cachedParser->write();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,14 +43,14 @@ abstract class BaseLevelProvider implements LevelProvider{
|
|||||||
mkdir($this->path, 0777, true);
|
mkdir($this->path, 0777, true);
|
||||||
}
|
}
|
||||||
$nbt = new BigEndianNBTStream();
|
$nbt = new BigEndianNBTStream();
|
||||||
$nbt->readCompressed(file_get_contents($this->getPath() . "level.dat"));
|
$levelData = $nbt->readCompressed(file_get_contents($this->getPath() . "level.dat"));
|
||||||
$levelData = $nbt->getData()->getCompoundTag("Data");
|
|
||||||
if($levelData !== null){
|
if(!($levelData instanceof CompoundTag) or !$levelData->hasTag("Data", CompoundTag::class)){
|
||||||
$this->levelData = $levelData;
|
|
||||||
}else{
|
|
||||||
throw new LevelException("Invalid level.dat");
|
throw new LevelException("Invalid level.dat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->levelData = $levelData->getCompoundTag("Data");
|
||||||
|
|
||||||
if(!$this->levelData->hasTag("generatorName", StringTag::class)){
|
if(!$this->levelData->hasTag("generatorName", StringTag::class)){
|
||||||
$this->levelData->setString("generatorName", (string) Generator::getGenerator("DEFAULT"), true);
|
$this->levelData->setString("generatorName", (string) Generator::getGenerator("DEFAULT"), true);
|
||||||
}
|
}
|
||||||
@ -107,10 +107,9 @@ abstract class BaseLevelProvider implements LevelProvider{
|
|||||||
|
|
||||||
public function saveLevelData(){
|
public function saveLevelData(){
|
||||||
$nbt = new BigEndianNBTStream();
|
$nbt = new BigEndianNBTStream();
|
||||||
$nbt->setData(new CompoundTag("", [
|
$buffer = $nbt->writeCompressed(new CompoundTag("", [
|
||||||
$this->levelData
|
$this->levelData
|
||||||
]));
|
]));
|
||||||
$buffer = $nbt->writeCompressed();
|
|
||||||
file_put_contents($this->getPath() . "level.dat", $buffer);
|
file_put_contents($this->getPath() . "level.dat", $buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,8 +95,7 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
mkdir($this->path, 0777, true);
|
mkdir($this->path, 0777, true);
|
||||||
}
|
}
|
||||||
$nbt = new LittleEndianNBTStream();
|
$nbt = new LittleEndianNBTStream();
|
||||||
$nbt->read(substr(file_get_contents($this->getPath() . "level.dat"), 8));
|
$levelData = $nbt->read(substr(file_get_contents($this->getPath() . "level.dat"), 8));
|
||||||
$levelData = $nbt->getData();
|
|
||||||
if($levelData instanceof CompoundTag){
|
if($levelData instanceof CompoundTag){
|
||||||
$this->levelData = $levelData;
|
$this->levelData = $levelData;
|
||||||
}else{
|
}else{
|
||||||
@ -210,8 +209,7 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$nbt = new LittleEndianNBTStream();
|
$nbt = new LittleEndianNBTStream();
|
||||||
$nbt->setData($levelData);
|
$buffer = $nbt->write($levelData);
|
||||||
$buffer = $nbt->write();
|
|
||||||
file_put_contents($path . "level.dat", Binary::writeLInt(self::CURRENT_STORAGE_VERSION) . Binary::writeLInt(strlen($buffer)) . $buffer);
|
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);
|
$this->levelData->setInt("StorageVersion", self::CURRENT_STORAGE_VERSION);
|
||||||
|
|
||||||
$nbt = new LittleEndianNBTStream();
|
$nbt = new LittleEndianNBTStream();
|
||||||
$nbt->setData($this->levelData);
|
$buffer = $nbt->write($this->levelData);
|
||||||
$buffer = $nbt->write();
|
|
||||||
file_put_contents($this->getPath() . "level.dat", Binary::writeLInt(self::CURRENT_STORAGE_VERSION) . Binary::writeLInt(strlen($buffer)) . $buffer);
|
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 */
|
/** @var CompoundTag[] $entities */
|
||||||
$entities = [];
|
$entities = [];
|
||||||
if(($entityData = $this->db->get($index . self::TAG_ENTITY)) !== false and strlen($entityData) > 0){
|
if(($entityData = $this->db->get($index . self::TAG_ENTITY)) !== false and strlen($entityData) > 0){
|
||||||
$nbt->read($entityData, true);
|
$entities = $nbt->read($entityData, true);
|
||||||
$entities = $nbt->getData();
|
|
||||||
if(!is_array($entities)){
|
if(!is_array($entities)){
|
||||||
$entities = [$entities];
|
$entities = [$entities];
|
||||||
}
|
}
|
||||||
@ -387,8 +383,7 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
|
|
||||||
$tiles = [];
|
$tiles = [];
|
||||||
if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false and strlen($tileData) > 0){
|
if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false and strlen($tileData) > 0){
|
||||||
$nbt->read($tileData, true);
|
$tiles = $nbt->read($tileData, true);
|
||||||
$tiles = $nbt->getData();
|
|
||||||
if(!is_array($tiles)){
|
if(!is_array($tiles)){
|
||||||
$tiles = [$tiles];
|
$tiles = [$tiles];
|
||||||
}
|
}
|
||||||
@ -506,8 +501,7 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
private function writeTags(array $targets, string $index){
|
private function writeTags(array $targets, string $index){
|
||||||
if(!empty($targets)){
|
if(!empty($targets)){
|
||||||
$nbt = new LittleEndianNBTStream();
|
$nbt = new LittleEndianNBTStream();
|
||||||
$nbt->setData($targets);
|
$this->db->put($index, $nbt->write($targets));
|
||||||
$this->db->put($index, $nbt->write());
|
|
||||||
}else{
|
}else{
|
||||||
$this->db->delete($index);
|
$this->db->delete($index);
|
||||||
}
|
}
|
||||||
|
@ -85,10 +85,7 @@ class Anvil extends McRegion{
|
|||||||
//TODO: TileTicks
|
//TODO: TileTicks
|
||||||
|
|
||||||
$writer = new BigEndianNBTStream();
|
$writer = new BigEndianNBTStream();
|
||||||
$nbt->setName("Level");
|
return $writer->writeCompressed(new CompoundTag("", [$nbt]), ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
|
||||||
$writer->setData(new CompoundTag("", [$nbt]));
|
|
||||||
|
|
||||||
return $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function serializeSubChunk(SubChunk $subChunk) : CompoundTag{
|
protected function serializeSubChunk(SubChunk $subChunk) : CompoundTag{
|
||||||
@ -103,14 +100,13 @@ class Anvil extends McRegion{
|
|||||||
public function nbtDeserialize(string $data){
|
public function nbtDeserialize(string $data){
|
||||||
$nbt = new BigEndianNBTStream();
|
$nbt = new BigEndianNBTStream();
|
||||||
try{
|
try{
|
||||||
$nbt->readCompressed($data);
|
$chunk = $nbt->readCompressed($data);
|
||||||
|
if(!($chunk instanceof CompoundTag) or !$chunk->hasTag("Level")){
|
||||||
$chunk = $nbt->getData()->getCompoundTag("Level");
|
|
||||||
|
|
||||||
if($chunk === null){
|
|
||||||
throw new ChunkException("Invalid NBT format");
|
throw new ChunkException("Invalid NBT format");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$chunk = $chunk->getCompoundTag("Level");
|
||||||
|
|
||||||
$subChunks = [];
|
$subChunks = [];
|
||||||
$subChunksTag = $chunk->getListTag("Sections") ?? [];
|
$subChunksTag = $chunk->getListTag("Sections") ?? [];
|
||||||
foreach($subChunksTag as $subChunk){
|
foreach($subChunksTag as $subChunk){
|
||||||
|
@ -101,10 +101,7 @@ class McRegion extends BaseLevelProvider{
|
|||||||
$nbt->setTag(new ListTag("TileEntities", $tiles, NBT::TAG_Compound));
|
$nbt->setTag(new ListTag("TileEntities", $tiles, NBT::TAG_Compound));
|
||||||
|
|
||||||
$writer = new BigEndianNBTStream();
|
$writer = new BigEndianNBTStream();
|
||||||
$nbt->setName("Level");
|
return $writer->writeCompressed(new CompoundTag("", [$nbt]), ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
|
||||||
$writer->setData(new CompoundTag("", [$nbt]));
|
|
||||||
|
|
||||||
return $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,14 +112,13 @@ class McRegion extends BaseLevelProvider{
|
|||||||
public function nbtDeserialize(string $data){
|
public function nbtDeserialize(string $data){
|
||||||
$nbt = new BigEndianNBTStream();
|
$nbt = new BigEndianNBTStream();
|
||||||
try{
|
try{
|
||||||
$nbt->readCompressed($data);
|
$chunk = $nbt->readCompressed($data);
|
||||||
|
if(!($chunk instanceof CompoundTag) or !$chunk->hasTag("Level")){
|
||||||
$chunk = $nbt->getData()->getCompoundTag("Level");
|
throw new ChunkException("Invalid NBT format");
|
||||||
|
|
||||||
if($chunk === null){
|
|
||||||
throw new ChunkException("Invalid NBT format, 'Level' key not found");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$chunk = $chunk->getCompoundTag("Level");
|
||||||
|
|
||||||
$subChunks = [];
|
$subChunks = [];
|
||||||
$fullIds = $chunk->hasTag("Blocks", ByteArrayTag::class) ? $chunk->getByteArray("Blocks") : str_repeat("\x00", 32768);
|
$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);
|
$fullData = $chunk->hasTag("Data", ByteArrayTag::class) ? $chunk->getByteArray("Data") : str_repeat("\x00", 16384);
|
||||||
@ -257,10 +253,9 @@ class McRegion extends BaseLevelProvider{
|
|||||||
new CompoundTag("GameRules", [])
|
new CompoundTag("GameRules", [])
|
||||||
]);
|
]);
|
||||||
$nbt = new BigEndianNBTStream();
|
$nbt = new BigEndianNBTStream();
|
||||||
$nbt->setData(new CompoundTag("", [
|
$buffer = $nbt->writeCompressed(new CompoundTag("", [
|
||||||
$levelData
|
$levelData
|
||||||
]));
|
]));
|
||||||
$buffer = $nbt->writeCompressed();
|
|
||||||
file_put_contents($path . "level.dat", $buffer);
|
file_put_contents($path . "level.dat", $buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,8 +95,7 @@ abstract class Spawnable extends Tile{
|
|||||||
self::$nbtWriter = new NetworkLittleEndianNBTStream();
|
self::$nbtWriter = new NetworkLittleEndianNBTStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$nbtWriter->setData($this->getSpawnCompound());
|
$this->spawnCompoundCache = self::$nbtWriter->write($this->getSpawnCompound());
|
||||||
$this->spawnCompoundCache = self::$nbtWriter->write();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->spawnCompoundCache;
|
return $this->spawnCompoundCache;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user