remove \pocketmine\START_TIME, add Server->getStartTime()

This commit is contained in:
Dylan K. Taylor 2019-08-25 16:25:27 +01:00
parent 647f86a5b8
commit ad0f100f8e
3 changed files with 13 additions and 5 deletions

View File

@ -263,8 +263,6 @@ namespace pocketmine {
} }
} }
//TODO: move this to a Server field
define('pocketmine\START_TIME', microtime(true));
ThreadManager::init(); ThreadManager::init();
new Server($autoloader, $logger, \pocketmine\DATA, \pocketmine\PLUGIN_PATH); new Server($autoloader, $logger, \pocketmine\DATA, \pocketmine\PLUGIN_PATH);

View File

@ -209,6 +209,8 @@ class Server{
private $currentTPS = 20; private $currentTPS = 20;
/** @var float */ /** @var float */
private $currentUse = 0; private $currentUse = 0;
/** @var float */
private $startTime;
/** @var bool */ /** @var bool */
private $doTitleTick = true; private $doTitleTick = true;
@ -547,6 +549,13 @@ class Server{
return round((array_sum($this->useAverage) / count($this->useAverage)) * 100, 2); return round((array_sum($this->useAverage) / count($this->useAverage)) * 100, 2);
} }
/**
* @return float
*/
public function getStartTime() : float{
return $this->startTime;
}
/** /**
* @return SimpleCommandMap * @return SimpleCommandMap
*/ */
@ -970,6 +979,7 @@ class Server{
throw new \InvalidStateException("Only one server instance can exist at once"); throw new \InvalidStateException("Only one server instance can exist at once");
} }
self::$instance = $this; self::$instance = $this;
$this->startTime = microtime(true);
$this->tickSleeper = new SleeperHandler(); $this->tickSleeper = new SleeperHandler();
$this->autoloader = $autoloader; $this->autoloader = $autoloader;
@ -1285,7 +1295,7 @@ class Server{
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.defaultGameMode", [$this->getGamemode()->getTranslationKey()])); $this->logger->info($this->getLanguage()->translateString("pocketmine.server.defaultGameMode", [$this->getGamemode()->getTranslationKey()]));
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.startFinished", [round(microtime(true) - \pocketmine\START_TIME, 3)])); $this->logger->info($this->getLanguage()->translateString("pocketmine.server.startFinished", [round(microtime(true) - $this->startTime, 3)]));
//TODO: move console parts to a separate component //TODO: move console parts to a separate component
$consoleSender = new ConsoleCommandSender(); $consoleSender = new ConsoleCommandSender();
@ -1736,7 +1746,7 @@ class Server{
$this->isRunning = false; $this->isRunning = false;
//Force minimum uptime to be >= 120 seconds, to reduce the impact of spammy crash loops //Force minimum uptime to be >= 120 seconds, to reduce the impact of spammy crash loops
$spacing = ((int) \pocketmine\START_TIME) - time() + 120; $spacing = ((int) $this->startTime) - time() + 120;
if($spacing > 0){ if($spacing > 0){
echo "--- Waiting $spacing seconds to throttle automatic restart (you can kill the process safely now) ---" . PHP_EOL; echo "--- Waiting $spacing seconds to throttle automatic restart (you can kill the process safely now) ---" . PHP_EOL;
sleep($spacing); sleep($spacing);

View File

@ -54,7 +54,7 @@ class StatusCommand extends VanillaCommand{
$server = $sender->getServer(); $server = $sender->getServer();
$sender->sendMessage(TextFormat::GREEN . "---- " . TextFormat::WHITE . "Server status" . TextFormat::GREEN . " ----"); $sender->sendMessage(TextFormat::GREEN . "---- " . TextFormat::WHITE . "Server status" . TextFormat::GREEN . " ----");
$time = microtime(true) - \pocketmine\START_TIME; $time = microtime(true) - $server->getStartTime();
$seconds = floor($time % 60); $seconds = floor($time % 60);
$minutes = null; $minutes = null;