本文整理汇总了PHP中pocketmine\nbt\NBT::writeCompressed方法的典型用法代码示例。如果您正苦于以下问题:PHP NBT::writeCompressed方法的具体用法?PHP NBT::writeCompressed怎么用?PHP NBT::writeCompressed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\nbt\NBT
的用法示例。
在下文中一共展示了NBT::writeCompressed方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveMacro
public function saveMacro($name, Macro $macro)
{
$tag = new tag\Compound();
$tag["author"] = new tag\String("author", $macro->getAuthor());
$tag["description"] = new tag\String("description", $macro->getDescription());
$tag["ops"] = new tag\Enum("ops");
foreach ($macro->getOperations() as $i => $log) {
$tag["ops"][$i] = $log->toTag();
}
$nbt = new NBT();
$nbt->setData($tag);
$file = $this->getFile($name);
$stream = fopen($file, "wb");
if (!is_resource($stream)) {
throw new \RuntimeException("Unable to open stream. Maybe the macro name is not a valid filename?");
}
$compression = $this->getMain()->getConfig()->getAll()["data providers"]["macro"]["mcr"]["compression"];
if ($compression === 0) {
$data = $nbt->write();
} else {
$data = $nbt->writeCompressed($compression);
}
fwrite($stream, chr($compression) . $data);
fclose($stream);
}
示例2: generateChunk
public function generateChunk($x, $z)
{
$nbt = new Compound("Level", []);
$nbt->xPos = new Int("xPos", $this->getX() * 32 + $x);
$nbt->zPos = new Int("zPos", $this->getZ() * 32 + $z);
$nbt->LastUpdate = new Long("LastUpdate", 0);
$nbt->LightPopulated = new Byte("LightPopulated", 0);
$nbt->TerrainPopulated = new Byte("TerrainPopulated", 0);
$nbt->V = new Byte("V", self::VERSION);
$nbt->InhabitedTime = new Long("InhabitedTime", 0);
$biomes = str_repeat(Binary::writeByte(-1), 256);
$nbt->Biomes = new ByteArray("Biomes", $biomes);
$nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 156, Binary::readInt("…²J")));
$nbt->HeightMap = new IntArray("HeightMap", array_fill(0, 256, 127));
$nbt->Sections = new Enum("Sections", []);
$nbt->Sections->setTagType(NBT::TAG_Compound);
$nbt->Entities = new Enum("Entities", []);
$nbt->Entities->setTagType(NBT::TAG_Compound);
$nbt->TileEntities = new Enum("TileEntities", []);
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
$nbt->TileTicks = new Enum("TileTicks", []);
$nbt->TileTicks->setTagType(NBT::TAG_Compound);
$writer = new NBT(NBT::BIG_ENDIAN);
$nbt->setName("Level");
$writer->setData(new Compound("", ["Level" => $nbt]));
$chunkData = $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
$this->saveChunk($x, $z, $chunkData);
}
示例3: generate
public static function generate($path, $name, $seed, $generator, array $options = [])
{
@mkdir($path, 0777, true);
@mkdir($path . "/region", 0777);
//TODO, add extra details
$levelData = new Compound("Data", ["hardcore" => new Byte("hardcore", 0), "initialized" => new Byte("initialized", 1), "GameType" => new Int("GameType", 0), "generatorVersion" => new Int("generatorVersion", 1), "SpawnX" => new Int("SpawnX", 128), "SpawnY" => new Int("SpawnY", 70), "SpawnZ" => new Int("SpawnZ", 128), "version" => new Int("version", 19133), "DayTime" => new Int("DayTime", 0), "LastPlayed" => new Long("LastPlayed", microtime(true) * 1000), "RandomSeed" => new Long("RandomSeed", $seed), "SizeOnDisk" => new Long("SizeOnDisk", 0), "Time" => new Long("Time", 0), "generatorName" => new String("generatorName", Generator::getGeneratorName($generator)), "generatorOptions" => new String("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""), "LevelName" => new String("LevelName", $name), "GameRules" => new Compound("GameRules", [])]);
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->setData(new Compound(null, ["Data" => $levelData]));
$buffer = $nbt->writeCompressed();
@file_put_contents($path . "level.dat", $buffer);
}
示例4: saveOfflinePlayerData
/**
* @param string $name
* @param Compound $nbtTag
* @param bool $async
*/
public function saveOfflinePlayerData($name, Compound $nbtTag, $async = false)
{
$nbt = new NBT(NBT::BIG_ENDIAN);
try {
$nbt->setData($nbtTag);
if ($async) {
$this->getScheduler()->scheduleAsyncTask(new FileWriteTask($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed()));
} else {
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
}
} catch (\Exception $e) {
$this->logger->critical($this->getLanguage()->translateString("pocketmine.data.saveError", [$name, $e->getMessage()]));
if (\pocketmine\DEBUG > 1 and $this->logger instanceof MainLogger) {
$this->logger->logException($e);
}
}
}
示例5: toBinary
public function toBinary()
{
$nbt = clone $this->getNBT();
$nbt->xPos = new Int("xPos", $this->x);
$nbt->zPos = new Int("zPos", $this->z);
if ($this->isGenerated()) {
$nbt->Blocks = new ByteArray("Blocks", $this->getBlockIdArray());
$nbt->Data = new ByteArray("Data", $this->getBlockDataArray());
$nbt->SkyLight = new ByteArray("SkyLight", $this->getBlockSkyLightArray());
$nbt->BlockLight = new ByteArray("BlockLight", $this->getBlockLightArray());
$nbt->Biomes = new ByteArray("Biomes", $this->getBiomeIdArray());
$nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
$nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray());
}
$entities = [];
foreach ($this->getEntities() as $entity) {
if (!$entity instanceof Player and !$entity->closed) {
$entity->saveNBT();
$entities[] = $entity->namedtag;
}
}
$nbt->Entities = new Enum("Entities", $entities);
$nbt->Entities->setTagType(NBT::TAG_Compound);
$tiles = [];
foreach ($this->getTiles() as $tile) {
$tile->saveNBT();
$tiles[] = $tile->namedtag;
}
$nbt->TileEntities = new Enum("TileEntities", $tiles);
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
$writer = new NBT(NBT::BIG_ENDIAN);
$nbt->setName("Level");
$writer->setData(new Compound("", ["Level" => $nbt]));
return $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
}
示例6: toBinary
public function toBinary()
{
$nbt = clone $this->getNBT();
$nbt->xPos = new Int("xPos", $this->x);
$nbt->zPos = new Int("zPos", $this->z);
$nbt->Sections = new Enum("Sections", []);
$nbt->Sections->setTagType(NBT::TAG_Compound);
foreach ($this->getSections() as $section) {
if ($section instanceof EmptyChunkSection) {
continue;
}
$nbt->Sections[$section->getY()] = new Compound(\null, ["Y" => new Byte("Y", $section->getY()), "Blocks" => new ByteArray("Blocks", $section->getIdArray()), "Data" => new ByteArray("Data", $section->getDataArray()), "BlockLight" => new ByteArray("BlockLight", $section->getLightArray()), "SkyLight" => new ByteArray("SkyLight", $section->getSkyLightArray())]);
}
$nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
$nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray());
$entities = [];
foreach ($this->getEntities() as $entity) {
if (!$entity instanceof Player and !$entity->closed) {
$entity->saveNBT();
$entities[] = $entity->namedtag;
}
}
$nbt->Entities = new Enum("Entities", $entities);
$nbt->Entities->setTagType(NBT::TAG_Compound);
$tiles = [];
foreach ($this->getTiles() as $tile) {
$tile->saveNBT();
$tiles[] = $tile->namedtag;
}
$nbt->TileEntities = new Enum("TileEntities", $tiles);
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
$extraData = new BinaryStream();
$extraData->putInt(\count($this->getBlockExtraDataArray()));
foreach ($this->getBlockExtraDataArray() as $key => $value) {
$extraData->putInt($key);
$extraData->putShort($value);
}
$nbt->ExtraData = new ByteArray("ExtraData", $extraData->getBuffer());
$writer = new NBT(NBT::BIG_ENDIAN);
$nbt->setName("Level");
$writer->setData(new Compound("", ["Level" => $nbt]));
return $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
}
示例7: saveLevelData
public function saveLevelData()
{
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->setData(new Compound("", ["Data" => $this->levelData]));
$buffer = $nbt->writeCompressed();
file_put_contents($this->getPath() . "level.dat", $buffer);
}
示例8: onQuit
/**
* Called when the user logs out
*
* @param PlayerQuitEvent $event
*/
public function onQuit(PlayerQuitEvent $event)
{
if (isset($this->standbyAuth[strtolower($event->getPlayer()->getName())])) {
unset($this->standbyAuth[strtolower($event->getPlayer()->getName())]);
return;
}
if (isset($this->needAuth[strtolower($event->getPlayer()->getName())])) {
unset($this->needAuth[strtolower($event->getPlayer()->getName())]);
return;
}
if ($this->plugin->getConfig()->get("servermode", null) != "slave") {
return;
}
$nbt = new NBT(NBT::BIG_ENDIAN);
try {
$nbt->setData($event->getPlayer()->namedtag);
$nbtFile = mb_convert_encoding($nbt->writeCompressed(), "UTF-8", "ISO-8859-1");
// itemSyncro
// slave->master = [passcode, itemSyncro, username, itemData]
$data = [$this->plugin->getConfig()->get("passcode"), "itemSyncro", $event->getPlayer()->getName(), $nbtFile];
CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data)));
} catch (\Exception $e) {
$this->plugin->getLogger()->critical($this->plugin->getServer()->getLanguage()->translateString("pocketmine.data.saveError", [$event->getPlayer()->getName(), $e->getMessage()]));
if (\pocketmine\DEBUG > 1 and $this->plugin->getServer()->getLogger() instanceof MainLogger) {
$this->plugin->getServer()->getLogger()->logException($e);
}
}
// logoutRequest
// slave->master = [passcode, logoutRequest, username, IP, isUserGenerate]
$data = [$this->plugin->getConfig()->get("passcode"), "logoutRequest", $event->getPlayer()->getName(), $event->getPlayer()->getAddress(), false];
CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data)));
}
示例9: saveOfflinePlayerData
/**
* @param string $name
* @param Compound $nbtTag
*/
public function saveOfflinePlayerData($name, Compound $nbtTag)
{
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->setData($nbtTag);
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
}
示例10: saveOfflinePlayerData
/**
* @param string $name
* @param Compound $nbtTag
*/
public function saveOfflinePlayerData($name, Compound $nbtTag)
{
$nbt = new NBT(NBT::BIG_ENDIAN);
try {
$nbt->setData($nbtTag);
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
} catch (\Exception $e) {
$this->logger->critical("Could not save player " . $name . ": " . $e->getMessage());
if (\pocketmine\DEBUG > 1 and $this->logger instanceof MainLogger) {
$this->logger->logException($e);
}
}
}
示例11: saveArea
public function saveArea(Area $area)
{
$nbt = new NBT(NBT::BIG_ENDIAN);
$data = new Compound();
$data->CaseName = new String("CaseName", $area->getName());
$data->SerializedShape = new String("SerializedShape", serialize($area->getShape()));
$data->UserFlags = new Int("UserFlags", $area->getUserFlags());
$data->NonUserFlags = new Int("NonUserFlags", $area->getNonUserFlags());
$data->Owner = new String("Owner", $area->getOwner());
$data->Users = new Enum("Users", array_map(function ($user) {
return new String("", $user);
}, $area->getUsers()));
$file = str_replace('$${areaname}', strtolower($area->getName()), $this->areaFile);
file_put_contents($file, $nbt->writeCompressed());
}
示例12: toBinary
public function toBinary()
{
$data = new Compound($this->name);
// we will have trouble updating these NBT tags to PHP 7 :(
// But hopefully it will be as simple as search & replace with regex:
// /(String|Int|Byte|blah)/ -> $1Tag
// depends if shoghicp does even more destruction :P
$data->Name = new String("Name", $this->name);
// unique name of the WorldEditSession
$data->Owner = new String("Owner", $this->owner);
// OK, I know that this will no longer work after 2038 January, but who will use this plugin until 2038?
$data->Creation = new Int("Creation", $this->creationTime);
$entries = new Enum("Entries", array_map(function (Block $block) {
$compound = new Compound();
$compound->X = new Int("X", $block->x);
$compound->Y = new Int("Y", $block->y);
$compound->Z = new Int("Z", $block->z);
$compound->Id = new Byte("Id", $block->getId());
$compound->Damage = new Byte("Damage", $block->getDamage());
return $compound;
}, $this->entries));
$data->Entries = $entries;
$nbt = new NBT();
$nbt->setData($data);
return $nbt->writeCompressed();
}
示例13: generateChunk
public function generateChunk($x, $z)
{
$nbt = new Compound("Level", []);
$nbt->xPos = new Int("xPos", $this->getX() * 32 + $x);
$nbt->zPos = new Int("zPos", $this->getZ() * 32 + $z);
$nbt->LastUpdate = new Long("LastUpdate", 0);
$nbt->LightPopulated = new Byte("LightPopulated", 0);
$nbt->TerrainPopulated = new Byte("TerrainPopulated", 0);
$nbt->V = new Byte("V", self::VERSION);
$nbt->InhabitedTime = new Long("InhabitedTime", 0);
$nbt->Biomes = new ByteArray("Biomes", \str_repeat(\chr(-1), 256));
$nbt->HeightMap = new IntArray("HeightMap", \array_fill(0, 256, 127));
$nbt->BiomeColors = new IntArray("BiomeColors", \array_fill(0, 256, \PHP_INT_SIZE === 8 ? \unpack("N", "…²J")[1] << 32 >> 32 : \unpack("N", "…²J")[1]));
$nbt->Blocks = new ByteArray("Blocks", \str_repeat("", 32768));
$nbt->Data = new ByteArray("Data", $half = \str_repeat("", 16384));
$nbt->SkyLight = new ByteArray("SkyLight", $half);
$nbt->BlockLight = new ByteArray("BlockLight", $half);
$nbt->Entities = new Enum("Entities", []);
$nbt->Entities->setTagType(NBT::TAG_Compound);
$nbt->TileEntities = new Enum("TileEntities", []);
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
$nbt->TileTicks = new Enum("TileTicks", []);
$nbt->TileTicks->setTagType(NBT::TAG_Compound);
$writer = new NBT(NBT::BIG_ENDIAN);
$nbt->setName("Level");
$writer->setData(new Compound("", ["Level" => $nbt]));
$chunkData = $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, self::$COMPRESSION_LEVEL);
if ($chunkData !== \false) {
$this->saveChunk($x, $z, $chunkData);
}
}