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 pathVisionCommand.php
More file actions
91 lines (82 loc) · 4.06 KB
/
VisionCommand.php
File metadata and controls
91 lines (82 loc) · 4.06 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace ServerCore\command;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\command\PluginIdentifiableCommand;
use pocketmine\entity\EffectInstance;
use pocketmine\entity\Effect;
use pocketmine\plugin\Plugin;
use pocketmine\utils\TextFormat;
use pocketmine\Player;
use ServerCore\ServerCore as Main;
class VisionCommand extends Command implements PluginIdentifiableCommand {
private $plugin;
public function __construct(Main $plugin) {
$this->plugin = $plugin;
parent::__construct(
"vision",
"Gives you night vision",
"/vision <player>"
);
$this->setPermission("command.vision");
}
public function getPlugin() : Plugin {
return $this->plugin;
}
public function execute(CommandSender $sender, string $label, array $args) {
if (!$this->testPermission($sender)) {
return;
}
if ($sender instanceof Player) {
if (isset($args[0])) {
if ($this->plugin->getServer()->getPlayer($args[0])) {
$player = $this->plugin->getServer()->getPlayer($args[0]);
if (isset($this->plugin->vision[$player])) {
$player->removeEffect(Effect::NIGHT_VISION);
unset($this->plugin->vision[$player]);
$player->sendMessage(TextFormat::RED . "Night Vision has been turned off");
$sender->sendMessage(TextFormat::GREEN . "You turned off Night Vision for " . $player->getName());
} else {
$player->addEffect(new EffectInstance(Effect::getEffectByName("NIGHT_VISION"), INT32_MAX, 1, false));
$this->plugin->vision[] = $player;
$player->sendMessage(TextFormat::GREEN . "Night Vision has been turned on");
$sender->sendMessage(TextFormat::GREEN . "You turned off Night Vision for " . $player->getName());
}
} else {
$sender->sendMessage(TextFormat::RED . "Player not found");
}
} else {
if (isset($this->plugin->vision[$sender])) {
$sender->removeEffect(Effect::NIGHT_VISION);
unset($this->plugin->vision[$sender]);
$sender->sendMessage(TextFormat::RED . "Night Vision has been turned off");
} else {
$sender->addEffect(new EffectInstance(Effect::getEffectByName("NIGHT_VISION"), INT32_MAX, 1, false));
$this->plugin->vision[] = $sender;
$sender->sendMessage(TextFormat::GREEN . "Night Vision has been turned on");
}
}
} else {
if (isset($args[0])) {
if ($this->plugin->getServer()->getPlayer($args[0])) {
$player = $this->plugin->getServer()->getPlayer($args[0]);
if (isset($this->plugin->vision[$player])) {
$player->removeEffect(Effect::NIGHT_VISION);
unset($this->plugin->vision[$player]);
$player->sendMessage(TextFormat::RED . "Night Vision has been turned off");
$sender->sendMessage(TextFormat::GREEN . "You turned off Night Vision for " . $player->getName());
} else {
$player->addEffect(new EffectInstance(Effect::getEffectByName("NIGHT_VISION"), INT32_MAX, 1, false));
$this->plugin->vision[] = $player;
$player->sendMessage(TextFormat::GREEN . "Night Vision has been turned on");
$sender->sendMessage(TextFormat::GREEN . "You turned on Night Vision for " . $player->getName());
}
} else {
$sender->sendMessage(TextFormat::RED . "Player not found");
}
} else {
$sender->sendMessage(TextFormat::RED . "Please enter a player name");
}
}
}
}