Beispiel #1
0
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (strtolower($cmd->getName()) != "wall") {
         return false;
     }
     if (count($args) == 0) {
         return false;
     }
     if ($sender instanceof RemoteConsoleCommandSender && ($who = MPMU::startsWith($args[1], "--rpc=")) !== null) {
         array_shift($args);
         $msg = implode(" ", $args);
         if ($msg != "") {
             $this->owner->getServer()->broadcastMesage(mc::_("WALL:%1% %2%", $who, $msg));
         }
         return true;
     }
     $msg = implode(" ", $args);
     $who = $sender->getName();
     $this->owner->getServer()->broadcastMessage(mc::_("WALL:%1% %2%", $who, $msg));
     $lst = $this->owner->getModule("ServerList");
     foreach ($lst->getIds() as $id) {
         if ($lst->getServerAttr($id, "rcon-pw") === null) {
             continue;
         }
         $host = $lst->getServerAttr($id, "rcon-host");
         $port = $lst->getServerAttr($id, "rcon-port");
         $auth = $lst->getServerAttr($id, "rcon-pw");
         $this->owner->getServer()->getScheduler()->scheduleAsyncTask(new RconTask($this->owner, "rconDone", [$host, $port, $auth], "wall --rpc=" . $who . " " . $msg, [null]));
     }
     return true;
 }
Beispiel #2
0
 /**
  * Handles command prefixes before dispatching commands.
  *
  * The following prefixes are recognized:
  * - "+op:", temporarily gives the player Op (if the player is not Op yet)
  * - "+console:", runs the command as if it was run from the console.
  * - "+rcon:", runs the command as if it was run from a RemoteConsole,
  *   capturing all output which is then send to the player.
  *
  * @param CommandSender $ctx - running context
  * @param str $cmdline - command line to execute
  */
 public static function opexec(CommandSender $ctx, $cmdline)
 {
     if (($cm = MPMU::startsWith($cmdline, "+op:")) !== null) {
         if (!$ctx->isOp()) {
             $ctx->setOp(true);
             $ctx->getServer()->distpatchCommand($ctx, $cm);
             $ctx->setOp(false);
             return;
         }
         $ctx->getServer()->distpatchCommand($ctx, $cm);
         return;
     }
     if (($cm = MPMU::startsWith($cmdline, "+console:")) !== null) {
         $ctx->getServer()->distpatchCommand(new ConsoleCommandSender(), $cm);
         return;
     }
     if (($cm = MPMU::startsWith($cmdline, "+rcon:")) !== null) {
         if ($ctx instanceof Player) {
             $rcon = new RemoteConsoleCommandSender();
             $ctx->getServer()->distpatchCommand($rcon, $cm);
             if (trim($rcon->getMessage()) != "") {
                 $ctx->sendMessage($rcon->getMessage());
             }
         } else {
             $ctx->getServer()->distpatchCommand($ctx, $cm);
         }
         return;
     }
     $ctx->getServer()->dispatchCommand($ctx, $cmdline);
 }
 private function cmdRemove(CommandSender $c, Plugin $plugin, $mgr)
 {
     $file = $this->getPluginFilePath($plugin);
     // Check the different types...
     if (($fp = MPMU::startsWith($file, "phar:")) !== null) {
         // This is a phar plugin file
         $file = $fp;
         $c->sendMessage(mc::_("Uninstalled PHAR plugin from %1%", $file));
     } elseif (($fp = MPMU::startsWith($file, "myzip:")) !== null) {
         // This is a zip plugin
         $fp = explode("#", $fp);
         array_pop($fp);
         $file = implode("#", $fp);
         $c->sendMessage(mc::_("Uninstalled Zip plugin from %1%", $file));
     } elseif (is_dir($file)) {
         // A Folder plugin from devtools
         $c->sendMessage(mc::_("Uninstalled Folder plugin from %1%", $file));
     } elseif (is_file($file)) {
         // A Script plugin
         $c->sendMessage(mc::_("Uninstalled Script plugin from %1%", $file));
     } else {
         $loader = explode("\\", get_class($plugin->getPluginLoader()));
         $c->sendMessage(mc::_("Unsupported loader %1% for uninstall", array_pop($loader)));
         return true;
     }
     $mgr->disablePlugin($plugin);
     if (FileUtils::rm_r($file)) {
         $c->sendMessage(TextFormat::GREEN . mc::_("Uninstalled!"));
         $c->sendMessage(mc::_("It is recommended to re-start the server as"));
         $c->sendMessage(mc::_("there may be lingering references pointing"));
         $c->sendMessage(mc::_("to the old plugin."));
     } else {
         $c->sendMessage(TextFormat::RED . mc::_("Uninstall failed"));
     }
     return true;
 }