-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPing.php
More file actions
71 lines (61 loc) · 2.27 KB
/
Ping.php
File metadata and controls
71 lines (61 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace OpenSource; // replace your command directory here.
/*
This was coded by Lewis Brindley under the VGDevelopment Organisation.
By the MIT License, you can do whatever you want with this file with no restrictions unless implied in the License.
You cannot however remove this commented in citation of the authorship of the file. You must add this to any file using code from this file.
*/
use pocketmine\command\{
CommandSender,
ConsoleCommandSender, // used in-case you want to allow console running the command.
PluginCommand
};
use pocketmine\Player;
use pocketmine\utils\TextFormat as Chat;
// >>>
use PluginObject as OS; // replace "PluginObject" with your "Main.php" without the extension ".php"
class Ping extends PluginCommand {
private static $os = null;
/**
* Construct the command and parent.
*
* @param string $name
* @param OS $plugin
*/
public function __construct($name, OS $plugin) {
parent::__construct($name, $plugin);
self::$os = $plugin;
$this->setDescription("Check your Ping");
$this->setUsage("/p or /ping");
$this->setPermission("plugin.pingcheck"); // replace plugin with name of your plugin
$this->setAliases([
"p"
]);
}
/**
* Called when player executes the command.
*
* Custom coloring of the ping as well!
*
* @param CommandSender $sender
* @param string $commandLabel
* @param array $args
* @return void
*/
public function execute(CommandSender $sender, string $commandLabel, array $args) {
if ($sender instanceof Player) {
$ping = $sender->getPing();
if ($ping > 200) {
$ping = Chat::RED . (string)$ping;
$radar = Chat::RED . "." . Chat::BLACK . ":i";
} else if ($ping > 100 && $ping < 200) {
$ping = Chat::YELLOW . (string)$ping;
$radar = Chat::YELLOW . ".:" . Chat::BLACK . "i";
} else {
$ping = Chat::GREEN . (string)$ping;
$radar = Chat::GREEN . ".:i";
}
$sender->sendMessage(Chat::AQUA . "The server reported your ping to be:" . Chat::EOL . $ping . Chat::AQUA . "ms " . $radar);
}
}
}