Пример #1
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);
 }