mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
Deprecated CallbackTask, moved sleep checking to level
This commit is contained in:
@ -203,6 +203,8 @@ class Level implements ChunkManager, Metadatable{
|
||||
/** @var \SplFixedArray */
|
||||
private $blockStates;
|
||||
|
||||
public $sleepTicks = 0;
|
||||
|
||||
private $chunkTickRadius;
|
||||
private $chunkTickList = [];
|
||||
private $chunksPerTick;
|
||||
@ -644,9 +646,35 @@ class Level implements ChunkManager, Metadatable{
|
||||
|
||||
$this->processChunkRequest();
|
||||
|
||||
if($this->sleepTicks > 0 and --$this->sleepTicks <= 0){
|
||||
$this->checkSleep();
|
||||
}
|
||||
|
||||
$this->timings->doTick->stopTiming();
|
||||
}
|
||||
|
||||
public function checkSleep(){
|
||||
$resetTime = true;
|
||||
foreach($this->getPlayers() as $p){
|
||||
if(!$p->isSleeping()){
|
||||
$resetTime = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($resetTime){
|
||||
$time = $this->getTime() % Level::TIME_FULL;
|
||||
|
||||
if($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE){
|
||||
$this->setTime($this->getTime() + Level::TIME_FULL - $time);
|
||||
|
||||
foreach($this->getPlayers() as $p){
|
||||
$p->stopSleep();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player[] $target
|
||||
* @param Block[] $blocks
|
||||
|
Reference in New Issue
Block a user