Esempio n. 1
0
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (strtolower($cmd->getName()) === "fly") {
         if (empty($args)) {
             if (!$sender->hasPermission("flycommand.me")) {
                 $sender->sendMessage(TextFormat::RED . "You do not have permission to use this command");
                 return true;
             } else {
                 if (!$sender instanceof Player) {
                     $sender->sendMessage(TextFormat::RED . "Command only allowed in-game");
                     return true;
                 }
                 if ($sender->getAllowFlight()) {
                     $sender->setAllowFlight(false);
                     $sender->sendMessage(TextFormat::GREEN . "Flight mode disabled");
                     return true;
                 } else {
                     $sender->setAllowFlight(true);
                     $sender->sendMessage(TextFormat::GREEN . "Flight mode enabled");
                     return true;
                 }
             }
         } else {
             if (count($args === 1)) {
                 $player = $this->getServer()->getPlayer($args[0]);
                 if (!$sender->hasPermission("flycommand.others")) {
                     $sender->sendMessage(TextFormat::RED . "You do not have permission to use this command");
                     return true;
                 } else {
                     if ($player === null) {
                         $sender->sendMessage(TextFormat::RED . "Player not online");
                         return true;
                     }
                     if ($player->getAllowFlight()) {
                         $player->setAllowFlight(false);
                         $player->sendMessage(TextFormat::GREEN . "Flight mode disabled");
                         $sender->sendMessage(TextFormat::GREEN . "Flight mode disabled for player: " . TextFormat::WHITE . $player->getName());
                         return true;
                     } else {
                         $player->setAllowFlight(true);
                         $player->sendMessage(TextFormat::GREEN . "Flight mode enabled");
                         $sender->sendMessage(TextFormat::GREEN . "Flight mode enabled for player: " . TextFormat::WHITE . $player->getName());
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }