Exemplo n.º 1
0
 public function import()
 {
     if (file_exists($this->path . "tileEntities.dat")) {
         //OldPM
         $level = unserialize(file_get_contents($this->path . "level.dat"));
         console("[INFO] Importing OldPM level \"" . $level["LevelName"] . "\" to PMF format");
         $entities = new Config($this->path . "entities.yml", CONFIG_YAML, unserialize(file_get_contents($this->path . "entities.dat")));
         $entities->save();
         $tiles = new Config($this->path . "tiles.yml", CONFIG_YAML, unserialize(file_get_contents($this->path . "tileEntities.dat")));
         $tiles->save();
     } elseif (file_exists($this->path . "chunks.dat") and file_exists($this->path . "level.dat")) {
         //Pocket
         $nbt = new NBT();
         $nbt->load(substr(file_get_contents($this->path . "level.dat"), 8));
         $level = array_shift($nbt->tree);
         if ($level["LevelName"] == "") {
             $level["LevelName"] = "world" . time();
         }
         console("[INFO] Importing Pocket level \"" . $level["LevelName"] . "\" to PMF format");
         unset($level["Player"]);
         $nbt->load(substr(file_get_contents($this->path . "entities.dat"), 12));
         $entities = array_shift($nbt->tree);
         if (!isset($entities["TileEntities"])) {
             $entities["TileEntities"] = array();
         }
         $tiles = $entities["TileEntities"];
         $entities = $entities["Entities"];
         $entities = new Config($this->path . "entities.yml", CONFIG_YAML, $entities);
         $entities->save();
         $tiles = new Config($this->path . "tiles.yml", CONFIG_YAML, $tiles);
         $tiles->save();
     } else {
         return false;
     }
     $pmf = new PMFLevel($this->path . "level.pmf", array("name" => $level["LevelName"], "seed" => $level["RandomSeed"], "time" => $level["Time"], "spawnX" => $level["SpawnX"], "spawnY" => $level["SpawnY"], "spawnZ" => $level["SpawnZ"], "extra" => "", "width" => 16, "height" => 8));
     $chunks = new PocketChunkParser();
     $chunks->loadFile($this->path . "chunks.dat");
     $chunks->loadMap();
     for ($Z = 0; $Z < 16; ++$Z) {
         for ($X = 0; $X < 16; ++$X) {
             $chunk = array(0 => "", 1 => "", 2 => "", 3 => "", 4 => "", 5 => "", 6 => "", 7 => "");
             for ($z = 0; $z < 16; ++$z) {
                 for ($x = 0; $x < 16; ++$x) {
                     $block = $chunks->getChunkColumn($X, $Z, $x, $z, 0);
                     $meta = $chunks->getChunkColumn($X, $Z, $x, $z, 1);
                     for ($Y = 0; $Y < 8; ++$Y) {
                         $chunk[$Y] .= substr($block, $Y << 4, 16);
                         $chunk[$Y] .= substr($meta, $Y << 3, 8);
                         $chunk[$Y] .= "";
                     }
                 }
             }
             foreach ($chunk as $Y => $data) {
                 $pmf->setMiniChunk($X, $Z, $Y, $data);
             }
             $pmf->saveChunk($X, $Z);
         }
         console("[NOTICE] Importing level " . ceil(($Z + 1) / 0.16) . "%");
     }
     $chunks->map = null;
     $chunks = null;
     @unlink($this->path . "level.dat");
     @unlink($this->path . "level.dat_old");
     @unlink($this->path . "player.dat");
     @unlink($this->path . "entities.dat");
     @unlink($this->path . "chunks.dat");
     @unlink($this->path . "chunks.dat.gz");
     @unlink($this->path . "tiles.dat");
     unset($chunks, $level, $entities, $tiles, $nbt);
     return true;
 }
 private function initialHuman(Player $player)
 {
     $player->setDataFlag($player::DATA_PLAYER_FLAGS, $player::DATA_PLAYER_FLAG_SLEEP, false);
     $player->setDataProperty($player::DATA_PLAYER_BED_POSITION, $player::DATA_TYPE_POS, [0, 0, 0]);
     $inventory = new PlayerInventory($player);
     $this->setPrivateVariableData($player, 'inventory', $inventory);
     if ($player instanceof Player) {
         $player->addWindow($inventory, 0);
     }
     if (!$player instanceof Player) {
         if (isset($player->namedtag->NameTag)) {
             $player->setNameTag($player->namedtag["NameTag"]);
         }
         if (isset($player->namedtag->Skin) and $player->namedtag->Skin instanceof CompoundTag) {
             $player->setSkin($player->namedtag->Skin["Data"], $player->namedtag->Skin["Slim"] > 0);
         }
         $this->setPrivateVariableData($player, 'uuid', UUID::fromData($player->getId(), $player->getSkinData(), $player->getNameTag()));
     }
     if (isset($player->namedtag->Inventory) and $player->namedtag->Inventory instanceof ListTag) {
         foreach ($player->namedtag->Inventory as $item) {
             if ($item["Slot"] >= 0 and $item["Slot"] < 9) {
                 // Hotbar
                 $player->inventory->setHotbarSlotIndex($item["Slot"], isset($item["TrueSlot"]) ? $item["TrueSlot"] : -1);
             } elseif ($item["Slot"] >= 100 and $item["Slot"] < 104) {
                 // Armor
                 $player->getInventory()->setItem($player->getInventory()->getSize() + $item["Slot"] - 100, NBT::getItemHelper($item));
             } else {
                 $player->getInventory()->setItem($item["Slot"] - 9, NBT::getItemHelper($item));
             }
         }
     }
     $this->initialEntity($player);
 }
Exemplo n.º 3
0
 public function spawn($player)
 {
     if ($this->closed) {
         return false;
     }
     if (!$player instanceof Player) {
         $player = $this->server->api->player->get($player);
     }
     switch ($this->class) {
         case TILE_CHEST:
             $nbt = new NBT();
             $nbt->write(chr(NBT::TAG_COMPOUND) . "");
             $nbt->write(chr(NBT::TAG_STRING));
             $nbt->writeTAG_String("id");
             $nbt->writeTAG_String($this->class);
             $nbt->write(chr(NBT::TAG_INT));
             $nbt->writeTAG_String("x");
             $nbt->writeTAG_Int((int) $this->x);
             $nbt->write(chr(NBT::TAG_INT));
             $nbt->writeTAG_String("y");
             $nbt->writeTAG_Int((int) $this->y);
             $nbt->write(chr(NBT::TAG_INT));
             $nbt->writeTAG_String("z");
             $nbt->writeTAG_Int((int) $this->z);
             if ($this->isPaired()) {
                 $nbt->write(chr(NBT::TAG_INT));
                 $nbt->writeTAG_String("pairx");
                 $nbt->writeTAG_Int((int) $this->data["pairx"]);
                 $nbt->write(chr(NBT::TAG_INT));
                 $nbt->writeTAG_String("pairz");
                 $nbt->writeTAG_Int((int) $this->data["pairz"]);
             }
             $nbt->write(chr(NBT::TAG_END));
             $pk = new EntityDataPacket();
             $pk->x = $this->x;
             $pk->y = $this->y;
             $pk->z = $this->z;
             $pk->namedtag = $nbt->binary;
             $player->dataPacket($pk);
             break;
         case TILE_SIGN:
             $nbt = new NBT();
             $nbt->write(chr(NBT::TAG_COMPOUND) . "");
             $nbt->write(chr(NBT::TAG_STRING));
             $nbt->writeTAG_String("Text1");
             $nbt->writeTAG_String($this->data["Text1"]);
             $nbt->write(chr(NBT::TAG_STRING));
             $nbt->writeTAG_String("Text2");
             $nbt->writeTAG_String($this->data["Text2"]);
             $nbt->write(chr(NBT::TAG_STRING));
             $nbt->writeTAG_String("Text3");
             $nbt->writeTAG_String($this->data["Text3"]);
             $nbt->write(chr(NBT::TAG_STRING));
             $nbt->writeTAG_String("Text4");
             $nbt->writeTAG_String($this->data["Text4"]);
             $nbt->write(chr(NBT::TAG_STRING));
             $nbt->writeTAG_String("id");
             $nbt->writeTAG_String($this->class);
             $nbt->write(chr(NBT::TAG_INT));
             $nbt->writeTAG_String("x");
             $nbt->writeTAG_Int((int) $this->x);
             $nbt->write(chr(NBT::TAG_INT));
             $nbt->writeTAG_String("y");
             $nbt->writeTAG_Int((int) $this->y);
             $nbt->write(chr(NBT::TAG_INT));
             $nbt->writeTAG_String("z");
             $nbt->writeTAG_Int((int) $this->z);
             $nbt->write(chr(NBT::TAG_END));
             $pk = new EntityDataPacket();
             $pk->x = $this->x;
             $pk->y = $this->y;
             $pk->z = $this->z;
             $pk->namedtag = $nbt->binary;
             $player->dataPacket($pk);
             break;
     }
 }
Exemplo n.º 4
0
 public function exportLevel(Level $level)
 {
     $level->save(false, true);
     @mkdir($this->api->plugin->configPath($this) . "export/");
     $path = $this->api->plugin->configPath($this) . "export/" . $level->getName() . "/";
     @mkdir($path);
     $chunks = fopen($path . "chunks.dat", "w");
     fwrite($chunks, self::$chunkHeader);
     for ($Z = 0; $Z < 16; ++$Z) {
         for ($X = 0; $X < 16; ++$X) {
             $chunk = "";
             $miniChunks = array();
             for ($Y = 0; $Y < 8; ++$Y) {
                 $miniChunks[$Y] = $level->level->getMiniChunk($X, $Z, $Y);
             }
             $columns = array();
             for ($x = 0; $x < 16; ++$x) {
                 for ($z = 0; $z < 16; ++$z) {
                     $index = ($x << 4) + $z;
                     $j = ($z << 9) + ($x << 5);
                     $columns[$index] = array("", "", str_repeat("", 64), str_repeat("", 64));
                     foreach ($miniChunks as $raw) {
                         $columns[$index][0] .= substr($raw, $j, 16);
                         //Block IDs
                         $columns[$index][1] .= substr($raw, $j + 16, 8);
                         //Block Metadata
                     }
                 }
             }
             for ($i = 0; $i < 4; ++$i) {
                 for ($x = 0; $x < 16; ++$x) {
                     for ($z = 0; $z < 16; ++$z) {
                         $chunk .= $columns[($x << 4) + $z][$i];
                     }
                 }
             }
             unset($columns, $miniChunks);
             $chunk = str_pad($chunk, 86012, "", STR_PAD_RIGHT);
             fwrite($chunks, Utils::writeLInt(strlen($chunk)) . $chunk);
         }
     }
     fclose($chunks);
     $nbt = new NBT();
     $nbt->write(chr(NBT::TAG_COMPOUND) . "");
     $nbt->write(chr(NBT::TAG_INT));
     $nbt->writeTAG_String("GameType");
     $nbt->writeTAG_Int(0);
     //$nbt->writeTAG_Int((int) $level->getGamemode());
     $nbt->write(chr(NBT::TAG_INT));
     $nbt->writeTAG_String("LastPlayed");
     $nbt->writeTAG_Int(time());
     $nbt->write(chr(NBT::TAG_STRING));
     $nbt->writeTAG_String("LevelName");
     $nbt->writeTAG_String($level->getName());
     $nbt->write(chr(NBT::TAG_INT));
     $nbt->writeTAG_String("Platform");
     $nbt->writeTAG_Int(2);
     $nbt->write(chr(NBT::TAG_COMPOUND));
     $nbt->writeTAG_String("Player");
     //Nothing here!
     $nbt->write(chr(NBT::TAG_END));
     $nbt->write(chr(NBT::TAG_LONG));
     $nbt->writeTAG_String("RandomSeed");
     $nbt->writeTAG_Long($level->getSeed());
     $nbt->write(chr(NBT::TAG_LONG));
     $nbt->writeTAG_String("SizeOnDisk");
     $nbt->writeTAG_Long(filesize($path . "chunks.dat"));
     $nbt->write(chr(NBT::TAG_INT));
     $nbt->writeTAG_String("SpawnX");
     $nbt->writeTAG_Int((int) $level->getSpawn()->x);
     $nbt->write(chr(NBT::TAG_INT));
     $nbt->writeTAG_String("SpawnY");
     $nbt->writeTAG_Int((int) $level->getSpawn()->y);
     $nbt->write(chr(NBT::TAG_INT));
     $nbt->writeTAG_String("SpawnZ");
     $nbt->writeTAG_Int((int) $level->getSpawn()->z);
     $nbt->write(chr(NBT::TAG_INT));
     $nbt->writeTAG_String("StorageVersion");
     $nbt->writeTAG_Int(3);
     $nbt->write(chr(NBT::TAG_INT));
     $nbt->writeTAG_String("Time");
     $nbt->writeTAG_Int($level->getTime());
     $nbt->write(chr(NBT::TAG_END));
     @file_put_contents($path . "level.dat", Utils::writeLInt(3) . Utils::writeLInt(strlen($nbt->binary)) . $nbt->binary);
     $nbt->binary = "";
     $nbt->write(chr(NBT::TAG_COMPOUND) . "");
     $nbt->write(chr(NBT::TAG_LIST));
     $nbt->writeTAG_String("Entities");
     $nbt->writeTAG_Byte(NBT::TAG_COMPOUND);
     $nbt->writeTAG_Int(0);
     $nbt->write(chr(NBT::TAG_LIST));
     $nbt->writeTAG_String("TileEntities");
     $nbt->writeTAG_Byte(NBT::TAG_COMPOUND);
     $tiles = $level->tiles->getAll();
     $nbt->writeTAG_Int(count($tiles));
     foreach ($tiles as $tid => $data) {
         $nbt->write(chr(NBT::TAG_STRING));
         $nbt->writeTAG_String("id");
         $nbt->writeTAG_String($data["id"]);
         $nbt->write(chr(NBT::TAG_INT));
         $nbt->writeTAG_String("x");
         $nbt->writeTAG_Int($data["x"]);
         $nbt->write(chr(NBT::TAG_INT));
         $nbt->writeTAG_String("y");
         $nbt->writeTAG_Int($data["y"]);
         $nbt->write(chr(NBT::TAG_INT));
         $nbt->writeTAG_String("z");
         $nbt->writeTAG_Int($data["z"]);
         if ($data["id"] === "Sign") {
             $nbt->write(chr(NBT::TAG_STRING));
             $nbt->writeTAG_String("Text1");
             $nbt->writeTAG_String($data["Text1"]);
             $nbt->write(chr(NBT::TAG_STRING));
             $nbt->writeTAG_String("Text2");
             $nbt->writeTAG_String($data["Text2"]);
             $nbt->write(chr(NBT::TAG_STRING));
             $nbt->writeTAG_String("Text3");
             $nbt->writeTAG_String($data["Text3"]);
             $nbt->write(chr(NBT::TAG_STRING));
             $nbt->writeTAG_String("Text4");
             $nbt->writeTAG_String($data["Text4"]);
         } elseif ($data["id"] === "Furnace") {
             $nbt->write(chr(NBT::TAG_SHORT));
             $nbt->writeTAG_String("BurnTime");
             $nbt->writeTAG_Short($data["BurnTime"]);
             $nbt->write(chr(NBT::TAG_SHORT));
             $nbt->writeTAG_String("CookTime");
             $nbt->writeTAG_Short($data["CookTime"]);
         } elseif ($data["id"] === "Chest" and isset($data["pairx"]) and isset($data["pairz"])) {
             $nbt->write(chr(NBT::TAG_INT));
             $nbt->writeTAG_String("pairx");
             $nbt->writeTAG_Int($data["pairx"]);
             $nbt->write(chr(NBT::TAG_INT));
             $nbt->writeTAG_String("pairz");
             $nbt->writeTAG_Int($data["pairz"]);
         }
         if ($data["id"] === "Furnace" or $data["id"] === "Chest") {
             $nbt->write(chr(NBT::TAG_LIST));
             $nbt->writeTAG_String("Items");
             $nbt->writeTAG_Byte(NBT::TAG_COMPOUND);
             $nbt->writeTAG_Int(count($data["Items"]));
             foreach ($data["Items"] as $index => $item) {
                 $nbt->write(chr(NBT::TAG_BYTE));
                 $nbt->writeTAG_String("Slot");
                 $nbt->writeTAG_Byte($item["Slot"]);
                 $nbt->write(chr(NBT::TAG_SHORT));
                 $nbt->writeTAG_String("id");
                 $nbt->writeTAG_Short($data["id"]);
                 $nbt->write(chr(NBT::TAG_SHORT));
                 $nbt->writeTAG_String("Damage");
                 $nbt->writeTAG_Short($data["Damage"]);
                 $nbt->write(chr(NBT::TAG_BYTE));
                 $nbt->writeTAG_String("Count");
                 $nbt->writeTAG_Byte($item["Count"]);
                 $nbt->write(chr(NBT::TAG_END));
             }
         }
         $nbt->write(chr(NBT::TAG_END));
     }
     $nbt->write(chr(NBT::TAG_END));
     @file_put_contents($path . "entities.dat", "ENT" . Utils::writeLInt(1) . Utils::writeLInt(strlen($nbt->binary)) . $nbt->binary);
 }