From be83eaf521f09e75babe888354a40bb36ca56bae Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 3 Jun 2013 23:24:33 +0200 Subject: [PATCH] Correct call of destruct chain to release PMF file locks at unload --- src/API/LevelAPI.php | 5 +++++ src/pmf/Level.php | 6 ++++++ src/world/Level.php | 5 +++++ src/world/LevelImport.php | 4 ++-- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 40eb95acb3..301b7e6012 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -139,6 +139,7 @@ class LevelAPI{ foreach($this->server->api->tile->getAll($level) as $tile){ $tile->close(); } + $level->close(); unset($this->levels[$name]); return true; } @@ -154,6 +155,9 @@ class LevelAPI{ console("[INFO] Preparing level \"".$name."\""); $level = new PMFLevel($path."level.pmf"); $entities = new Config($path."entities.yml", CONFIG_YAML); + if(file_exists($path."tileEntities.yml")){ + @rename($path."tileEntities.yml", $path."tiles.yml"); + } $tiles = new Config($path."tiles.yml", CONFIG_YAML); $this->levels[$name] = new Level($level, $entities, $tiles, $name); foreach($entities->getAll() as $entity){ @@ -191,6 +195,7 @@ class LevelAPI{ } $t = $this->server->api->tile->add($this->levels[$name], $tile["id"], $tile["x"], $tile["y"], $tile["z"], $tile); } + return true; } public function handle($data, $event){ diff --git a/src/pmf/Level.php b/src/pmf/Level.php index 69dec65d50..03fd67f53b 100644 --- a/src/pmf/Level.php +++ b/src/pmf/Level.php @@ -51,6 +51,12 @@ class PMFLevel extends PMF{ return true; } + public function close(){ + $chunks = null; + unset($chunks, $chunkChange, $locationTable); + parent::close(); + } + public function __construct($file, $blank = false){ if(is_array($blank)){ $this->create($file, 0); diff --git a/src/world/Level.php b/src/world/Level.php index 9245116588..100902ac21 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -45,6 +45,10 @@ class Level{ $this->changedCount = array(); } + public function close(){ + $this->__destruct(); + } + public function useChunk($X, $Z, Player $player){ if(!isset($this->usedChunks[$X.".".$Z])){ $this->usedChunks[$X.".".$Z] = array(); @@ -118,6 +122,7 @@ class Level{ public function __destruct(){ $this->save(); + $this->level->close(); unset($this->level); } diff --git a/src/world/LevelImport.php b/src/world/LevelImport.php index 2ced0c5aff..438bed8b69 100644 --- a/src/world/LevelImport.php +++ b/src/world/LevelImport.php @@ -32,12 +32,12 @@ class LevelImport{ } public function import(){ - if(file_exists($this->path."tiles.dat")){ //OldPM + 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."tiles.dat"))); + $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();