PocketMine-MP 5.36.1 git-eaa7c4834c8fe2f379d24e7f0ee6cc63cfb18ccc
Loading...
Searching...
No Matches
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(string $namespace, string $name){
40 parent::__construct(
41 $namespace,
42 $name,
43 KnownTranslationFactory::pocketmine_command_status_description()
44 );
45 $this->setPermission(DefaultPermissionNames::COMMAND_STATUS);
46 }
47
48 public function execute(CommandSender $sender, string $commandLabel, array $args){
50
51 $server = $sender->getServer();
52 $sender->sendMessage(TextFormat::GREEN . "---- " . TextFormat::RESET . "Server status" . TextFormat::GREEN . " ----");
53
54 $time = (int) (microtime(true) - $server->getStartTime());
55
56 $seconds = $time % 60;
57 $minutes = null;
58 $hours = null;
59 $days = null;
60
61 if($time >= 60){
62 $minutes = floor(($time % 3600) / 60);
63 if($time >= 3600){
64 $hours = floor(($time % (3600 * 24)) / 3600);
65 if($time >= 3600 * 24){
66 $days = floor($time / (3600 * 24));
67 }
68 }
69 }
70
71 $uptime = ($minutes !== null ?
72 ($hours !== null ?
73 ($days !== null ?
74 "$days days "
75 : "") . "$hours hours "
76 : "") . "$minutes minutes "
77 : "") . "$seconds seconds";
78
79 $sender->sendMessage(TextFormat::GOLD . "Uptime: " . TextFormat::RED . $uptime);
80
81 $tpsColor = TextFormat::GREEN;
82 if($server->getTicksPerSecond() < 12){
83 $tpsColor = TextFormat::RED;
84 }elseif($server->getTicksPerSecond() < 17){
85 $tpsColor = TextFormat::GOLD;
86 }
87
88 $sender->sendMessage(TextFormat::GOLD . "Current TPS: {$tpsColor}{$server->getTicksPerSecond()} ({$server->getTickUsage()}%)");
89 $sender->sendMessage(TextFormat::GOLD . "Average TPS: {$tpsColor}{$server->getTicksPerSecondAverage()} ({$server->getTickUsageAverage()}%)");
90
91 $bandwidth = $server->getNetwork()->getBandwidthTracker();
92 $sender->sendMessage(TextFormat::GOLD . "Network upload: " . TextFormat::RED . round($bandwidth->getSend()->getAverageBytes() / 1024, 2) . " kB/s");
93 $sender->sendMessage(TextFormat::GOLD . "Network download: " . TextFormat::RED . round($bandwidth->getReceive()->getAverageBytes() / 1024, 2) . " kB/s");
94
95 $sender->sendMessage(TextFormat::GOLD . "Thread count: " . TextFormat::RED . Process::getThreadCount());
96
97 $sender->sendMessage(TextFormat::GOLD . "Main thread memory: " . TextFormat::RED . number_format(round(($mUsage[0] / 1024) / 1024, 2), 2) . " MB.");
98 $sender->sendMessage(TextFormat::GOLD . "Total memory: " . TextFormat::RED . number_format(round(($mUsage[1] / 1024) / 1024, 2), 2) . " MB.");
99 $sender->sendMessage(TextFormat::GOLD . "Total virtual memory: " . TextFormat::RED . number_format(round(($mUsage[2] / 1024) / 1024, 2), 2) . " MB.");
100
101 $globalLimit = $server->getMemoryManager()->getGlobalMemoryLimit();
102 if($globalLimit > 0){
103 $sender->sendMessage(TextFormat::GOLD . "Maximum memory (manager): " . TextFormat::RED . number_format(round(($globalLimit / 1024) / 1024, 2), 2) . " MB.");
104 }
105
106 foreach($server->getWorldManager()->getWorlds() as $world){
107 $worldName = $world->getFolderName() !== $world->getDisplayName() ? " (" . $world->getDisplayName() . ")" : "";
108 $timeColor = $world->getTickRateTime() > 40 ? TextFormat::RED : TextFormat::YELLOW;
109 $sender->sendMessage(TextFormat::GOLD . "World \"{$world->getFolderName()}\"$worldName: " .
110 TextFormat::RED . number_format(count($world->getLoadedChunks())) . TextFormat::GREEN . " loaded chunks, " .
111 TextFormat::RED . number_format(count($world->getTickingChunks())) . TextFormat::GREEN . " ticking chunks, " .
112 TextFormat::RED . number_format(count($world->getEntities())) . TextFormat::GREEN . " entities. " .
113 "Time $timeColor" . round($world->getTickRateTime(), 2) . "ms"
114 );
115 }
116
117 return true;
118 }
119}
execute(CommandSender $sender, string $commandLabel, array $args)
static getAdvancedMemoryUsage()
Definition Process.php:55