This repository was archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWarnCommand.php
More file actions
73 lines (64 loc) · 3.04 KB
/
WarnCommand.php
File metadata and controls
73 lines (64 loc) · 3.04 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
72
73
<?php
namespace ServerCore\command;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\PluginIdentifiableCommand;
use pocketmine\plugin\Plugin;
use pocketmine\utils\TextFormat;
use pocketmine\Player;
use ServerCore\ServerCore as Main;
class WarnCommand extends Command implements PluginIdentifiableCommand {
private $plugin;
public function __construct(Main $plugin) {
$this->plugin = $plugin;
parent::__construct(
"warn",
"Warns a player",
"/warn <player> <string:message>"
);
$this->setPermission("command.warn");
}
public function getPlugin() : Plugin {
return $this->plugin;
}
public function execute(CommandSender $sender, string $label, array $args) {
if (!$this->testPermission($sender)) {
return;
}
if (!isset($args[0]) || !isset($args[1])) {
$sender->sendMessage(TextFormat::RED . "Please enter the player name and the message correctly");
return;
} elseif ($this->plugin->getServer()->getPlayer($args[0]) instanceof Player) {
if ($args[1] !== null) {
$name = strtolower(array_shift($args));
$player = $this->plugin->getServer()->getPlayer($name);
$message = implode(" ", $args);
if ($this->plugin->warnedPlayers->exists($name)) {
$action = strtolower($this->plugin->warnedPlayers->get("Action"));
switch ($action) {
case "kick":
$player->kick($message, false);
$sender->sendMessage(TextFormat::DARK_GREEN . $this->plugin->prefix . " " . $player->getName() . " was kicked");
break;
case "ban":
$player->setBanned(true);
$sender->sendMessage(TextFormat::DARK_GREEN . $this->plugin->prefix . " " . $player->getName() . " was banned");
break;
case "deop":
$player->setOp(false);
$player->sendMessage(TextFormat::DARK_RED . $this->plugin->prefix . " Admin Warning: " . $message);
$sender->sendMessage(TextFormat::DARK_GREEN . $this->plugin->prefix . " " . $player->getName() . " was deoped");
break;
}
} elseif ($this->plugin->getServer()->getPlayer($name)->isOnline()) {
$this->plugin->warnedPlayers->set($name);
$this->plugin->warnedPlayers->save();
$player->sendMessage(TextFormat::DARK_RED . $this->plugin->prefix . " Admin Warning: " . $message);
$sender->sendMessage(TextFormat::DARK_GREEN . $this->plugin->prefix . " " . $player->getName() . " was warned.");
}
}
} else {
$sender->sendMessage(TextFormat::RED . "Player not found");
}
}
}