mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
Added Level::startTime() and Level::stopTime()
This commit is contained in:
parent
9137a36b55
commit
5eed43ddd0
@ -193,8 +193,10 @@ class CustomPacketHandler{
|
||||
case MC_SET_TIME:
|
||||
if($this->c === false){
|
||||
$this->data["time"] = Utils::readInt($this->get(4));
|
||||
$this->data["started"] = ord($this->get(1)) & 0x80 > 0;
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["time"])."\x80";
|
||||
$this->raw .= chr((isset($this->data["started"]) and $this->data["started"] == true) ? 0x80:0x00);
|
||||
}
|
||||
break;
|
||||
case MC_START_GAME:
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
class 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){
|
||||
$this->server = ServerAPI::request();
|
||||
@ -33,6 +33,7 @@ class Level{
|
||||
$this->startTime = $this->time = (int) $this->level->getData("time");
|
||||
$this->nextSave = $this->startCheck = microtime(true);
|
||||
$this->nextSave += 90;
|
||||
$this->stopTime = false;
|
||||
$this->server->schedule(15, array($this, "checkThings"), array(), true);
|
||||
$this->server->schedule(20 * 13, array($this, "checkTime"), array(), true);
|
||||
$this->name = $name;
|
||||
@ -70,11 +71,16 @@ class Level{
|
||||
return false;
|
||||
}
|
||||
$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){
|
||||
$this->time = $time;
|
||||
$this->server->api->player->broadcastPacket($this->players, MC_SET_TIME, array(
|
||||
"time" => (int) $this->time,
|
||||
"started" => $this->stopTime == false,
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -470,6 +476,18 @@ class Level{
|
||||
$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(){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user