Added Level::startTime() and Level::stopTime()

This commit is contained in:
Shoghi Cervantes 2013-12-18 09:45:00 +01:00
parent 9137a36b55
commit 5eed43ddd0
2 changed files with 22 additions and 2 deletions

View File

@ -193,8 +193,10 @@ class CustomPacketHandler{
case MC_SET_TIME: case MC_SET_TIME:
if($this->c === false){ if($this->c === false){
$this->data["time"] = Utils::readInt($this->get(4)); $this->data["time"] = Utils::readInt($this->get(4));
$this->data["started"] = ord($this->get(1)) & 0x80 > 0;
}else{ }else{
$this->raw .= Utils::writeInt($this->data["time"])."\x80"; $this->raw .= Utils::writeInt($this->data["time"])."\x80";
$this->raw .= chr((isset($this->data["started"]) and $this->data["started"] == true) ? 0x80:0x00);
} }
break; break;
case MC_START_GAME: case MC_START_GAME:

View File

@ -21,7 +21,7 @@
class Level{ class Level{
public $entities, $tiles, $blockUpdates, $nextSave, $players = array(), $level; public $entities, $tiles, $blockUpdates, $nextSave, $players = array(), $level;
private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount; private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime;
public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){ public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
@ -33,6 +33,7 @@ class Level{
$this->startTime = $this->time = (int) $this->level->getData("time"); $this->startTime = $this->time = (int) $this->level->getData("time");
$this->nextSave = $this->startCheck = microtime(true); $this->nextSave = $this->startCheck = microtime(true);
$this->nextSave += 90; $this->nextSave += 90;
$this->stopTime = false;
$this->server->schedule(15, array($this, "checkThings"), array(), true); $this->server->schedule(15, array($this, "checkThings"), array(), true);
$this->server->schedule(20 * 13, array($this, "checkTime"), array(), true); $this->server->schedule(20 * 13, array($this, "checkTime"), array(), true);
$this->name = $name; $this->name = $name;
@ -70,11 +71,16 @@ class Level{
return false; return false;
} }
$now = microtime(true); $now = microtime(true);
$time = $this->startTime + ($now - $this->startCheck) * 20; if($this->stopTime == true){
}else{
$time = $this->startTime + ($now - $this->startCheck) * 20;
}
if($this->server->api->dhandle("time.change", array("level" => $this, "time" => $time)) !== false){ if($this->server->api->dhandle("time.change", array("level" => $this, "time" => $time)) !== false){
$this->time = $time; $this->time = $time;
$this->server->api->player->broadcastPacket($this->players, MC_SET_TIME, array( $this->server->api->player->broadcastPacket($this->players, MC_SET_TIME, array(
"time" => (int) $this->time, "time" => (int) $this->time,
"started" => $this->stopTime == false,
)); ));
} }
} }
@ -470,6 +476,18 @@ class Level{
$this->checkTime(); $this->checkTime();
} }
public function stopTime(){
$this->stopTime = true;
$this->startCheck = 0;
$this->checkTime();
}
public function startTime(){
$this->stopTime = false;
$this->startCheck = microtime(true);
$this->checkTime();
}
public function getSeed(){ public function getSeed(){
if(!isset($this->level)){ if(!isset($this->level)){
return false; return false;