mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-19 04:15:04 +00:00
Added Logger interface, threaded MainLogger and updated PluginLogger
This commit is contained in:
@@ -161,7 +161,7 @@ class Level{
|
||||
if($this === $this->server->getDefaultLevel() and $force !== true){
|
||||
return false;
|
||||
}
|
||||
console("[INFO] Unloading level \"" . $this->getName() . "\"");
|
||||
$this->server->getLogger()->info("Unloading level \"" . $this->getName() . "\"");
|
||||
$this->nextSave = PHP_INT_MAX;
|
||||
$this->save();
|
||||
$defaultLevel = $this->server->getDefaultLevel();
|
||||
|
@@ -25,6 +25,7 @@ use pocketmine\level\format\pmf\LevelFormat;
|
||||
use pocketmine\level\format\PocketChunkParser;
|
||||
use pocketmine\nbt\NBT;
|
||||
use pocketmine\utils\Config;
|
||||
use pocketmine\utils\MainLogger;
|
||||
|
||||
class LevelImport{
|
||||
private $path;
|
||||
@@ -36,7 +37,7 @@ class LevelImport{
|
||||
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");
|
||||
MainLogger::getLogger()->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")));
|
||||
@@ -48,7 +49,7 @@ class LevelImport{
|
||||
if($level["LevelName"] == ""){
|
||||
$level["LevelName"] = "world" . time();
|
||||
}
|
||||
console("[INFO] Importing Pocket level \"" . $level->LevelName . "\" to PMF format");
|
||||
MainLogger::getLogger()->info("Importing Pocket level \"" . $level->LevelName . "\" to PMF format");
|
||||
unset($level->Player);
|
||||
$nbt->read(substr(file_get_contents($this->path . "entities.dat"), 12));
|
||||
$entities = $nbt->getData();
|
||||
@@ -111,7 +112,7 @@ class LevelImport{
|
||||
$pmf->setPopulated($X, $Z);
|
||||
$pmf->saveChunk($X, $Z);
|
||||
}
|
||||
console("[NOTICE] Importing level " . ceil(($Z + 1) / 0.16) . "%");
|
||||
MainLogger::getLogger()->notice("Importing level " . ceil(($Z + 1) / 0.16) . "%");
|
||||
}
|
||||
$chunks->map = null;
|
||||
$chunks = null;
|
||||
|
@@ -41,7 +41,6 @@ class PocketChunkParser{
|
||||
|
||||
private function loadLocationTable(){
|
||||
$this->location = [];
|
||||
console("[DEBUG] Loading Chunk Location table...", true, true, 2);
|
||||
for($offset = 0; $offset < 0x1000; $offset += 4){
|
||||
$data = Binary::readLInt(substr($this->raw, $offset, 4));
|
||||
$sectors = $data & 0xff;
|
||||
@@ -136,7 +135,6 @@ class PocketChunkParser{
|
||||
return false;
|
||||
}
|
||||
$this->loadLocationTable();
|
||||
console("[DEBUG] Loading chunks...", true, true, 2);
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$this->map[$x] = [];
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
@@ -144,13 +142,11 @@ class PocketChunkParser{
|
||||
}
|
||||
}
|
||||
$this->raw = "";
|
||||
console("[DEBUG] Chunks loaded!", true, true, 2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function saveMap($final = false){
|
||||
console("[DEBUG] Saving chunks...", true, true, 2);
|
||||
|
||||
$fp = fopen($this->file, "r+b");
|
||||
flock($fp, LOCK_EX);
|
||||
@@ -165,7 +161,6 @@ class PocketChunkParser{
|
||||
$original = filesize($this->file);
|
||||
file_put_contents($this->file . ".gz", gzdeflate(gzdeflate(file_get_contents($this->file), 9), 9)); //Double compression for flat maps
|
||||
$compressed = filesize($this->file . ".gz");
|
||||
console("[DEBUG] Saved chunks.dat.gz with " . round(($compressed / $original) * 100, 2) . "% (" . round($compressed / 1024, 2) . "KB) of the original size", true, true, 2);
|
||||
if($final === true){
|
||||
@unlink($this->file);
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@ use pocketmine\nbt\NBT;
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\Enum;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\MainLogger;
|
||||
|
||||
class LevelFormat extends PMF{
|
||||
const VERSION = 2;
|
||||
@@ -121,7 +122,7 @@ class LevelFormat extends PMF{
|
||||
$this->seek(5);
|
||||
$this->levelData["version"] = ord($this->read(1));
|
||||
if($this->levelData["version"] > self::VERSION){
|
||||
console("[ERROR] New unsupported PMF Level format version #" . $this->levelData["version"] . ", current version is #" . self::VERSION);
|
||||
MainLogger::getLogger()->error("New unsupported PMF Level format version #" . $this->levelData["version"] . ", current version is #" . self::VERSION);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -161,7 +162,7 @@ class LevelFormat extends PMF{
|
||||
}
|
||||
|
||||
private function upgrade_From0_To1(){
|
||||
console("[NOTICE] Old PMF Level format version #0 detected, upgrading to version #1");
|
||||
MainLogger::getLogger()->notice("Old PMF Level format version #0 detected, upgrading to version #1");
|
||||
for($index = 0; $index < 256; ++$index){
|
||||
$X = $index & 0x0F;
|
||||
$Z = $index >> 4;
|
||||
@@ -186,7 +187,7 @@ class LevelFormat extends PMF{
|
||||
}
|
||||
|
||||
private function upgrade_From1_To2(){
|
||||
console("[NOTICE] Old PMF Level format version #1 detected, upgrading to version #2");
|
||||
MainLogger::getLogger()->notice("Old PMF Level format version #1 detected, upgrading to version #2");
|
||||
$nbt = new Compound("", array(
|
||||
new Enum("Entities", []),
|
||||
new Enum("TileEntities", [])
|
||||
@@ -308,7 +309,7 @@ class LevelFormat extends PMF{
|
||||
if(($this->chunkInfo[$index][0] & (1 << $Y)) !== 0){
|
||||
// 4096 + 2048 + 2048, Block Data, Meta, Light
|
||||
if(strlen($this->chunks[$index][$Y] = substr($chunk, $offset, 8192)) < 8192){
|
||||
console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents", true, true, 2);
|
||||
MainLogger::getLogger()->notice("Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents");
|
||||
$this->fillMiniChunk($X, $Z, $Y);
|
||||
}
|
||||
$offset += 8192;
|
||||
|
@@ -25,6 +25,8 @@
|
||||
namespace pocketmine\level\format\pmf;
|
||||
|
||||
|
||||
use pocketmine\utils\MainLogger;
|
||||
|
||||
class PMF{
|
||||
const VERSION = 0x01;
|
||||
|
||||
@@ -78,7 +80,7 @@ class PMF{
|
||||
$this->type = ord($this->read(1));
|
||||
break;
|
||||
default:
|
||||
console("[ERROR] Tried loading non-supported PMF version " . $this->version . " on file " . $this->file);
|
||||
MainLogger::getLogger()->alert("Tried loading non-supported PMF version " . $this->version . " on file " . $this->file);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user