forked from iiSaints83/Coding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaintsyFly
More file actions
107 lines (107 loc) · 4.46 KB
/
Copy pathSaintsyFly
File metadata and controls
107 lines (107 loc) · 4.46 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
declare(strict_types=1);
namespace iiFlamiinBlaze\BlazinFly;
use pocketmine\entity\Entity;
use pocketmine\plugin\PluginBase;
use pocketmine\event\Listener;
use pocketmine\Player;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\utils\TextFormat;
class BlazinFly extends PluginBase implements Listener{
private const PREFIX = TextFormat::AQUA . "BlazinFly" . TextFormat::YELLOW . " > ";
private const VERSION = "v1.8.7";
public function onEnable() : void{
$this->getServer()->getPluginManager()->registerEvents($this, $this);
@mkdir($this->getDataFolder());
$this->saveDefaultConfig();
}
private function multiWorldCheck(Entity $entity) : bool{
if(!$entity instanceof Player) return false;
if($this->getConfig()->get("multi-world") === "on"){
if(!in_array($entity->getLevel()->getName(), $this->getConfig()->get("worlds"))){
$entity->sendMessage(self::PREFIX . TextFormat::BLUE . "You are not in the right world to be able to use the fly command");
if(!$entity->isCreative()){
$entity->setFlying(false);
$entity->setAllowFlight(false);
}
return false;
}
}elseif($this->getConfig()->get("multi-world") === "off") return true;
return true;
}
public function onJoin(PlayerJoinEvent $event) : void{
$player = $event->getPlayer();
if($this->getConfig()->get("onJoin-FlyReset") === true){
if($player->isCreative()) return;
$player->setAllowFlight(false);
$player->sendMessage($this->getConfig()->get("fly-disabled"));
}
}
public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{
if($command->getName() === "fly"){
if(!$sender instanceof Player){
$sender->sendMessage(self::PREFIX . TextFormat::BLUE . "Use this command in-game");
return false;
}
if(!$sender->hasPermission("blazinfly.command")){
$sender->sendMessage(self::PREFIX . TextFormat::BLUE . "You do not have permission to use this command");
return false;
}
if(empty($args[0])){
if(!$sender->isCreative()){
if($this->multiWorldCheck($sender) === false) return false;
$sender->sendMessage($sender->getAllowFlight() === false ? $this->getConfig()->get("fly-enabled") : $this->getConfig()->get("fly-disabled"));
$sender->setAllowFlight($sender->getAllowFlight() === false ? true : false);
$sender->setFlying($sender->isFlying() === false ? true : false);
}else{
$sender->sendMessage(self::PREFIX . TextFormat::BLUE . "You can only use this command in survival mode");
return false;
}
return false;
}
if(!$sender->hasPermission("blazinfly.other")){
$sender->sendMessage(self::PREFIX . TextFormat::BLUE . "You do not have permission to enable flight for others");
return false;
}
if($this->getServer()->getPlayer($args[0])){
$player = $this->getServer()->getPlayer($args[0]);
if(!$player->isCreative()){
if($this->multiWorldCheck($player) === false) return false;
$player->sendMessage($player->getAllowFlight() === false ? $this->getConfig()->get("fly-enabled") : $this->getConfig()->get("fly-disabled"));
$sender->sendMessage($player->getAllowFlight() === false ? self::PREFIX . TextFormat::PURPLE . "You have enabled fly for " . $player->getName() : self::PREFIX . TextFormat::RED . "You have disabled fly for " . $player->getName());
$player->setAllowFlight($player->getAllowFlight() === false ? true : false);
$player->setFlying($player->isFlying() === false ? true : false);
}else{
$sender->sendMessage(self::PREFIX . TextFormat::BLUE . $player->getName() . " is in creative mode");
return false;
}
}else{
$sender->sendMessage(self::PREFIX . TextFormat::BLUE . "Player not found");
return false;
}
}
return true;
}
public function onDamage(EntityDamageEvent $event) : void{
$entity = $event->getEntity();
if($this->getConfig()->get("onDamage-FlyReset") === true){
if($event instanceof EntityDamageByEntityEvent){
if($entity instanceof Player){
$damager = $event->getDamager();
if(!$damager instanceof Player) return;
if($damager->isCreative()) return;
if($damager->getAllowFlight() === true){
$damager->sendMessage(self::PREFIX . TextFormat::LIGHT_BLUE . "Flight mode disabled due to combat");
$damager->setAllowFlight(false);
$damager->setFlying(false);
}
}
}
}
}
}