PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
StatusCommand.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\command\defaults;
25
31use function count;
32use function floor;
33use function microtime;
34use function number_format;
35use function round;
36
38
39 public function __construct(){
40 parent::__construct(
41 "status",
42 KnownTranslationFactory::pocketmine_command_status_description()
43 );
44 $this->setPermission(DefaultPermissionNames::COMMAND_STATUS);
45 }
46
47 public function execute(CommandSender $sender, string $commandLabel, array $args){
49
50 $server = $sender->getServer();
51 $sender->sendMessage(TextFormat::GREEN . "---- " . TextFormat::RESET . "Server status" . TextFormat::GREEN . " ----");
52
53 $time = (int) (microtime(true) - $server->getStartTime());
54
55 $seconds = $time % 60;
56 $minutes = null;
57 $hours = null;
58 $days = null;
59
60 if($time >= 60){
61 $minutes = floor(($time % 3600) / 60);
62 if($time >= 3600){
63 $hours = floor(($time % (3600 * 24)) / 3600);
64 if($time >= 3600 * 24){
65 $days = floor($time / (3600 * 24));
66 }
67 }
68 }
69
70 $uptime = ($minutes !== null ?
71 ($hours !== null ?
72 ($days !== null ?
73 "$days days "
74 : "") . "$hours hours "
75 : "") . "$minutes minutes "
76 : "") . "$seconds seconds";
77
78 $sender->sendMessage(TextFormat::GOLD . "Uptime: " . TextFormat::RED . $uptime);
79
80 $tpsColor = TextFormat::GREEN;
81 if($server->getTicksPerSecond() < 12){
82 $tpsColor = TextFormat::RED;
83 }elseif($server->getTicksPerSecond() < 17){
84 $tpsColor = TextFormat::GOLD;
85 }
86
87 $sender->sendMessage(TextFormat::GOLD . "Current TPS: {$tpsColor}{$server->getTicksPerSecond()} ({$server->getTickUsage()}%)");
88 $sender->sendMessage(TextFormat::GOLD . "Average TPS: {$tpsColor}{$server->getTicksPerSecondAverage()} ({$server->getTickUsageAverage()}%)");
89
90 $bandwidth = $server->getNetwork()->getBandwidthTracker();
91 $sender->sendMessage(TextFormat::GOLD . "Network upload: " . TextFormat::RED . round($bandwidth->getSend()->getAverageBytes() / 1024, 2) . " kB/s");
92 $sender->sendMessage(TextFormat::GOLD . "Network download: " . TextFormat::RED . round($bandwidth->getReceive()->getAverageBytes() / 1024, 2) . " kB/s");
93
94 $sender->sendMessage(TextFormat::GOLD . "Thread count: " . TextFormat::RED . Process::getThreadCount());
95
96 $sender->sendMessage(TextFormat::GOLD . "Main thread memory: " . TextFormat::RED . number_format(round(($mUsage[0] / 1024) / 1024, 2), 2) . " MB.");
97 $sender->sendMessage(TextFormat::GOLD . "Total memory: " . TextFormat::RED . number_format(round(($mUsage[1] / 1024) / 1024, 2), 2) . " MB.");
98 $sender->sendMessage(TextFormat::GOLD . "Total virtual memory: " . TextFormat::RED . number_format(round(($mUsage[2] / 1024) / 1024, 2), 2) . " MB.");
99
100 $globalLimit = $server->getMemoryManager()->getGlobalMemoryLimit();
101 if($globalLimit > 0){
102 $sender->sendMessage(TextFormat::GOLD . "Maximum memory (manager): " . TextFormat::RED . number_format(round(($globalLimit / 1024) / 1024, 2), 2) . " MB.");
103 }
104
105 foreach($server->getWorldManager()->getWorlds() as $world){
106 $worldName = $world->getFolderName() !== $world->getDisplayName() ? " (" . $world->getDisplayName() . ")" : "";
107 $timeColor = $world->getTickRateTime() > 40 ? TextFormat::RED : TextFormat::YELLOW;
108 $sender->sendMessage(TextFormat::GOLD . "World \"{$world->getFolderName()}\"$worldName: " .
109 TextFormat::RED . number_format(count($world->getLoadedChunks())) . TextFormat::GREEN . " loaded chunks, " .
110 TextFormat::RED . number_format(count($world->getTickingChunks())) . TextFormat::GREEN . " ticking chunks, " .
111 TextFormat::RED . number_format(count($world->getEntities())) . TextFormat::GREEN . " entities. " .
112 "Time $timeColor" . round($world->getTickRateTime(), 2) . "ms"
113 );
114 }
115
116 return true;
117 }
118}
execute(CommandSender $sender, string $commandLabel, array $args)
static getAdvancedMemoryUsage()
Definition: Process.php:55