public function execute(CommandSender $sender, $commandLabel, array $args)
 {
     $commands = [];
     $result = false;
     foreach ($this->formatStrings as $formatString) {
         try {
             $commands[] = $this->buildCommand($formatString, $args);
         } catch (\Exception $e) {
             if ($e instanceof \InvalidArgumentException) {
                 $sender->sendMessage(TextFormat::RED . $e->getMessage());
             } else {
                 $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.exception"));
                 $logger = $sender->getServer()->getLogger();
                 if ($logger instanceof MainLogger) {
                     $logger->logException($e);
                 }
             }
             return false;
         }
     }
     foreach ($commands as $command) {
         $result |= Server::getInstance()->dispatchCommand($sender, $command);
     }
     return (bool) $result;
 }
Esempio n. 2
0
 private function badPerm(CommandSender $sender, $perm)
 {
     if (!$sender->hasPermission("BukkitPE.command.whitelist.{$perm}")) {
         $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
         return true;
     }
     return false;
 }
Esempio n. 3
0
 private function describeToSender(Plugin $plugin, CommandSender $sender)
 {
     $desc = $plugin->getDescription();
     $sender->sendMessage(TextFormat::DARK_GREEN . $desc->getName() . TextFormat::WHITE . " version " . TextFormat::DARK_GREEN . $desc->getVersion());
     if ($desc->getDescription() != \null) {
         $sender->sendMessage($desc->getDescription());
     }
     if ($desc->getWebsite() != \null) {
         $sender->sendMessage("Website: " . $desc->getWebsite());
     }
     if (\count($authors = $desc->getAuthors()) > 0) {
         if (\count($authors) === 1) {
             $sender->sendMessage("Author: " . \implode(", ", $authors));
         } else {
             $sender->sendMessage("Authors: " . \implode(", ", $authors));
         }
     }
 }
Esempio n. 4
0
 private function sendPluginList(CommandSender $sender)
 {
     $list = "";
     foreach ($plugins = $sender->getServer()->getPluginManager()->getPlugins() as $plugin) {
         if (strlen($list) > 0) {
             $list .= TextFormat::WHITE . ", ";
         }
         $list .= $plugin->isEnabled() ? TextFormat::GREEN : TextFormat::RED;
         $list .= $plugin->getDescription()->getFullName();
     }
     $sender->sendMessage(new TranslationContainer("BukkitPE.command.plugins.success", [count($plugins), $list]));
 }
Esempio n. 5
0
 /**
  * @param CommandSender $source
  * @param string        $message
  * @param bool          $sendToSource
  */
 public static function broadcastCommandMessage(CommandSender $source, $message, $sendToSource = true)
 {
     if ($message instanceof TextContainer) {
         $m = clone $message;
         $result = "[" . $source->getName() . ": " . ($source->getServer()->getLanguage()->get($m->getText()) !== $m->getText() ? "%" : "") . $m->getText() . "]";
         $users = $source->getServer()->getPluginManager()->getPermissionSubscriptions(Server::BROADCAST_CHANNEL_ADMINISTRATIVE);
         $colored = TextFormat::GRAY . TextFormat::ITALIC . $result;
         $m->setText($result);
         $result = clone $m;
         $m->setText($colored);
         $colored = clone $m;
     } else {
         $users = $source->getServer()->getPluginManager()->getPermissionSubscriptions(Server::BROADCAST_CHANNEL_ADMINISTRATIVE);
         $result = new TranslationContainer("chat.type.admin", [$source->getName(), $message]);
         $colored = new TranslationContainer(TextFormat::GRAY . TextFormat::ITALIC . "%chat.type.admin", [$source->getName(), $message]);
     }
     if ($sendToSource === true and !$source instanceof ConsoleCommandSender) {
         $source->sendMessage($message);
     }
     foreach ($users as $user) {
         if ($user instanceof CommandSender) {
             if ($user instanceof ConsoleCommandSender) {
                 $user->sendMessage($result);
             } elseif ($user !== $source) {
                 $user->sendMessage($colored);
             }
         }
     }
 }
Esempio n. 6
0
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (count($args) < 1) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return false;
     }
     if ($args[0] === "start") {
         if (!$sender->hasPermission("BukkitPE.command.time.start")) {
             $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
             return true;
         }
         foreach ($sender->getServer()->getLevels() as $level) {
             $level->checkTime();
             $level->startTime();
             $level->checkTime();
         }
         Command::broadcastCommandMessage($sender, "Restarted the time");
         return true;
     } elseif ($args[0] === "stop") {
         if (!$sender->hasPermission("BukkitPE.command.time.stop")) {
             $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
             return true;
         }
         foreach ($sender->getServer()->getLevels() as $level) {
             $level->checkTime();
             $level->stopTime();
             $level->checkTime();
         }
         Command::broadcastCommandMessage($sender, "Stopped the time");
         return true;
     } elseif ($args[0] === "query") {
         if (!$sender->hasPermission("BukkitPE.command.time.query")) {
             $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
             return true;
         }
         if ($sender instanceof Player) {
             $level = $sender->getLevel();
         } else {
             $level = $sender->getServer()->getDefaultLevel();
         }
         $sender->sendMessage(new TranslationContainer("commands.time.query", [$level->getTime()]));
         return true;
     }
     if (count($args) < 2) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return false;
     }
     if ($args[0] === "set") {
         if (!$sender->hasPermission("BukkitPE.command.time.set")) {
             $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
             return true;
         }
         if ($args[1] === "day") {
             $value = 0;
         } elseif ($args[1] === "night") {
             $value = Level::TIME_NIGHT;
         } elseif ($args[1] === "sunrise") {
             $value = Level::TIME_SUNRISE;
         } elseif ($args[1] === "sunset") {
             $value = Level::TIME_SUNSET;
         } else {
             $value = $this->getInteger($sender, $args[1], 0);
         }
         foreach ($sender->getServer()->getLevels() as $level) {
             $level->checkTime();
             $level->setTime($value);
             $level->checkTime();
         }
         Command::broadcastCommandMessage($sender, new TranslationContainer("commands.time.set", [$value]));
     } elseif ($args[0] === "add") {
         if (!$sender->hasPermission("BukkitPE.command.time.add")) {
             $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
             return true;
         }
         $value = $this->getInteger($sender, $args[1], 0);
         foreach ($sender->getServer()->getLevels() as $level) {
             $level->checkTime();
             $level->setTime($level->getTime() + $value);
             $level->checkTime();
         }
         Command::broadcastCommandMessage($sender, new TranslationContainer("commands.time.added", [$value]));
     } else {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
     }
     return true;
 }