From f1e4bb0f621b8446f380601cc1d328707f9df0bb Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Wed, 15 May 2013 22:50:55 +0200 Subject: [PATCH] Scheduled saving --- src/Player.php | 2 +- src/pmf/Level.php | 3 +++ src/world/Level.php | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Player.php b/src/Player.php index 40995ecc8..3bef01c57 100644 --- a/src/Player.php +++ b/src/Player.php @@ -133,7 +133,7 @@ class Player{ return false; } $c = key($this->chunksOrder); - $d = $this->chunksOrder[$c]; + $d = @$this->chunksOrder[$c]; if($c === null or $d > $this->server->api->getProperty("view-distance")){ if($this->freedChunks === false){ foreach($this->chunksOrder as $c => $d){ diff --git a/src/pmf/Level.php b/src/pmf/Level.php index 215ead729..9d0fe54b8 100644 --- a/src/pmf/Level.php +++ b/src/pmf/Level.php @@ -224,6 +224,9 @@ class PMFLevel extends PMF{ }elseif($save !== false){ $this->saveChunk($X, $Z); } + $index = $this->getIndex($X, $Z); + $this->chunks[$index] = null; + $this->chunkChange[$index] = null; unset($this->chunks[$index], $this->chunkChange[$index]); return true; } diff --git a/src/world/Level.php b/src/world/Level.php index 331438cfc..91ec75636 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -35,7 +35,8 @@ class Level{ $this->entities = $entities; $this->tileEntities = $tileEntities; $this->startTime = $this->time = (int) $this->level->getData("time"); - $this->startCheck = microtime(true); + $this->lastSave = $this->startCheck = microtime(true); + $this->nextSave += 30; $this->server->schedule(15, array($this, "checkThings"), array(), true); $this->server->event("server.close", array($this, "save")); $this->name = $name; @@ -74,6 +75,11 @@ class Level{ $this->level->unloadChunk((int) $X, (int) $Z); } } + + if($this->lastSave < $now){ + $this->save(); + $this->lastSave = $now + 30; + } } public function __destruct(){