Esempio n. 1
0
 public function onSCommand(CommandSender $c, Command $cc, $scmd, $data, array $args)
 {
     if (count($args) == 0) {
         return false;
     }
     $wname = implode(" ", $args);
     $old = $this->owner->getServer()->getConfigString("level-name");
     if ($old == $wname) {
         $c->sendMessage(TextFormat::RED . mc::_("No change"));
         return true;
     }
     if (!$this->owner->autoLoad($c, $wname)) {
         $c->sendMessage(TextFormat::RED . mc::_("[MW] Unable to load %1%", $wname));
         $c->sendMessage(TextFormat::RED . mc::_("Change failed!"));
         return true;
     }
     $level = $this->owner->getServer()->getLevelByName($wname);
     if ($level === null) {
         $c->sendMessage(TextFormat::RED . mc::_("Error GetLevelByName %1%"));
         return true;
     }
     $this->owner->getServer()->setConfigString("level-name", $wname);
     $this->owner->getServer()->setDefaultLevel($level);
     $c->sendMessage(TextFormat::BLUE . mc::_("Default world changed to %1%", $wname));
     return true;
 }
Esempio n. 2
0
 public function onSCommand(CommandSender $c, Command $cc, $scmd, $data, array $args)
 {
     if (count($args) < 1 || count($args) > 4) {
         return false;
     }
     $world = array_shift($args);
     if ($this->owner->getServer()->isLevelGenerated($world)) {
         $c->sendMessage(TextFormat::RED . mc::_("[MW] A world named %1% already exists", $world));
         return true;
     }
     $seed = null;
     $generator = null;
     $opts = [];
     if (isset($args[0])) {
         $seed = intval($args[0]);
     }
     if (isset($args[1])) {
         $generator = Generator::getGenerator($args[1]);
         if (strtolower($args[1]) != Generator::getGeneratorName($generator)) {
             $c->sendMessage(TextFormat::RED . mc::_("[MW] Unknown generator %1%", $args[1]));
             return true;
         }
         $c->sendMessage(TextFormat::GREEN . mc::_("[MW] Using %1%", Generator::getGeneratorName($generator)));
     }
     if (isset($args[2])) {
         $opts = ["preset" => $args[2]];
     }
     $this->owner->getServer()->broadcastMessage(mc::_("[MW] Creating level %1%... (Expect Lag)", $world));
     $this->owner->getServer()->generateLevel($world, $seed, $generator, $opts);
     $this->owner->getServer()->loadLevel($world);
     return true;
 }
 /**
  * Dispatch commands using sub command table
  */
 public function dispatchSCmd(CommandSender $sender, Command $cmd, array $args, $data = null)
 {
     if (count($args) == 0) {
         $sender->sendMessage(mc::_("No sub-command specified"));
         return false;
     }
     $scmd = strtolower(array_shift($args));
     if (isset($this->aliases[$scmd])) {
         $scmd = $this->aliases[$scmd];
     }
     if (!isset($this->executors[$scmd])) {
         $sender->sendMessage(mc::_("Unknown sub-command %2% (try /%1% help)", $cmd->getName(), $scmd));
         return false;
     }
     if (isset($this->permission[$scmd])) {
         if (!$sender->hasPermission($this->permission[$scmd])) {
             $sender->sendMessage(mc::_("You are not allowed to do this"));
             return true;
         }
     }
     $callback = $this->executors[$scmd];
     if ($callback($sender, $cmd, $scmd, $data, $args)) {
         return true;
     }
     if (isset($this->executors["help"])) {
         $callback = $this->executors["help"];
         return $callback($sender, $cmd, $scmd, $data, ["usage"]);
     }
     return false;
 }
Esempio n. 4
0
 public function onSCommand(CommandSender $c, Command $cc, $scmd, $data, array $args)
 {
     if (count($args) != 0) {
         return false;
     }
     if (MPMU::apiVersion("1.12.0")) {
         $c->sendMessage(implode(", ", Generator::getGeneratorList()));
     } else {
         $c->sendMessage("normal, flat");
         $c->sendMessage(TextFormat::RED . mc::_("[MW] Plugin provided world generators\n are not included in\n this list."));
     }
     return true;
 }
Esempio n. 5
0
 public function onSCommand(CommandSender $c, Command $cc, $scmd, $data, array $args)
 {
     if (count($args) == 0) {
         return false;
     }
     $player = $c;
     if (count($args) > 1) {
         $player = $this->owner->getServer()->getPlayer($args[0]);
         if ($player !== null) {
             if (!MPMU::access($c, "mw.cmd.tp.others")) {
                 return true;
             }
             array_shift($args);
         } else {
             // Compatibility with old versions...
             $player = $this->owner->getServer()->getPlayer($args[count($args) - 1]);
             if ($player !== null) {
                 if (!MPMU::access($c, "mw.cmd.tp.others")) {
                     return true;
                 }
                 array_pop($args);
             } else {
                 $player = $c;
             }
         }
     }
     if (!MPMU::inGame($player)) {
         return true;
     }
     $wname = implode(" ", $args);
     if ($player->getLevel() == $this->owner->getServer()->getLevelByName($wname)) {
         $c->sendMessage($c == $player ? mc::_("You are already in %1%", $wname) : mc::_("%1% is already in %2%", $player->getName(), $wname));
         return true;
     }
     if (!$this->owner->autoLoad($c, $wname)) {
         $c->sendMessage(TextFormat::RED . mc::_("Teleport failed"));
         return true;
     }
     $level = $this->owner->getServer()->getLevelByName($wname);
     if ($level === null) {
         $c->sendMessage(TextFormat::RED . mc::_("Error GetLevelByName %1%"));
         return true;
     }
     if ($c != $player) {
         $player->sendMessage(TextFormat::YELLOW . mc::_("Teleporting you to %1% by %2%", $wname, $c->getName()));
     } else {
         $c->sendMessage(TextFormat::GREEN . mc::_("Teleporting to %1%", $wname));
     }
     $player->teleport($level->getSafeSpawn());
     return true;
 }
Esempio n. 6
0
 public function autoLoad(CommandSender $c, $world)
 {
     if ($this->getServer()->isLevelLoaded($world)) {
         return true;
     }
     if ($c !== null && !MPMU::access($c, "mw.cmd.world.load")) {
         return false;
     }
     if (!$this->getServer()->isLevelGenerated($world)) {
         if ($c !== null) {
             $c->sendMessage(mc::_("[MW] No world with the name %1% exists!", $world));
         }
         return false;
     }
     $this->getServer()->loadLevel($world);
     return $this->getServer()->isLevelLoaded($world);
 }
 /**
  * Entry point for sub-commands.  Will show the help or usage messages
  *
  * @param CommandSender $c - Entity issuing the command
  * @param Command $cc - actual command that was issued
  * @param str $scmd - sub-command being executed
  * @param mixed $data - Additional data passed to sub-command (global options)
  * @param str[] $args - arguments for sub-command
  */
 public function onSCommand(CommandSender $c, Command $cc, $scmd, $data, array $args)
 {
     $cm = $this->owner->getSCmdMap();
     $pageNumber = $this->getPageNumber($args);
     if (count($args)) {
         if ($args[0] == "usage") {
             if ($cm->getUsage($scmd) === null) {
                 return false;
             }
             $c->sendMessage(TextFormat::RED . mc::_("Usage: ") . sprintf($this->fmt, $cc->getName(), $scmd, $cm->getUsage($scmd)));
             return true;
         }
         $txt = ["Help for " . $cc->getName()];
         foreach ($args as $i) {
             if ($cm->getAlias($i) !== null) {
                 $i = $cm->getAlias($i);
             }
             if ($cm->getHelpMsg($i) === null && $cm->getUsage($i) === null) {
                 $txt[] = TextFormat::RED . mc::_("No help for %1%", $i);
                 continue;
             }
             $txt[] = TextFormat::YELLOW . mc::_("Help: ") . TextFormat::WHITE . "/" . $cc->getName() . " {$i}";
             if ($cm->getHelpMsg($i) !== null) {
                 $txt[] = TextFormat::YELLOW . mc::_("Description: ") . TextFormat::WHITE . $cm->getHelpMsg($i);
             }
             if ($cm->getUsage($i) !== null) {
                 $txt[] = TextFormat::YELLOW . mc::_("Usage: ") . TextFormat::WHITE . sprintf($this->fmt, $cc->getName(), $i, $cm->getUsage($i));
             }
         }
         return $this->paginateText($c, $pageNumber, $txt);
     }
     $txt = [mc::_("Available sub-commands for %1%", $cc->getName())];
     foreach ($cm->getHelp() as $cn => $desc) {
         $ln = TextFormat::GREEN . $cn;
         foreach ($cm->getAliases() as $i => $j) {
             if ($j == $cn) {
                 $ln .= "|{$i}";
             }
         }
         $ln .= ": " . TextFormat::WHITE . $desc;
         $txt[] = $ln;
     }
     return $this->paginateText($c, $pageNumber, $txt);
 }
Esempio n. 8
0
 private function mwWorldUnloadCmd(CommandSender $sender, $wname, $force)
 {
     if (MPMU::apiVersion("<1.12.0")) {
         // For old stuff...
         if ($wname == "--enable") {
             $this->owner->canUnload = true;
             $sender->sendMessage(TextFormat::YELLOW . mc::_("[MW] Unload sub-command enabled"));
             $sender->sendMessage(TextFormat::YELLOW . mc::_("[MW] To disable use: /mw unload --disable"));
             return true;
         }
         if ($wname == "--disable") {
             $this->owner->canUnload = false;
             $sender->sendMessage(TextFormat::GREEN . mc::_("[MW] Unload sub-command disabled"));
             $sender->sendMessage(TextFormat::GREEN . mc::_("[MW] To enable use: /mw unload --enable"));
             return true;
         }
         if (!$this->owner->canUnload) {
             $sender->sendMessage(TextFormat::RED . mc::_("[MW] Unload sub-command is disabled by default"));
             $sender->sendMessage(TextFormat::RED . mc::_("[MW] this is because that it usually causes the"));
             $sender->sendMessage(TextFormat::RED . mc::_("[MW] server to CRASH!"));
             $sender->sendMessage(TextFormat::RED . mc::_("[MW] To activate use:"));
             $sender->sendMessage(TextFormat::BLUE . mc::_("-   /mw unload --enable"));
             return true;
         }
     }
     // Actual implementation
     if (!$this->owner->getServer()->isLevelLoaded($wname)) {
         $sender->sendMessage(TextFormat::RED . mc::_("[MW] %1% is not loaded.", $wname));
         return true;
     }
     $level = $this->owner->getServer()->getLevelByName($wname);
     if ($level === null) {
         $sender->sendMessage(TextFormat::RED . mc::_("[MW] Unable to get %1%", $wname));
         return true;
     }
     if (!$this->owner->getServer()->unloadLevel($level, $force)) {
         if ($force) {
             $sender->sendMessage(TextFormat::RED . mc::_("[MW] Unable to unload %1%", $wname));
         } else {
             $sender->sendMessage(TextFormat::RED . mc::_("[MW] Unable to unload %1%.  Try -f", $wname));
         }
     } else {
         $sender->sendMessage(TextFormat::GREEN . mc::_("[MW] %1% unloaded.", $wname));
     }
     return true;
 }
Esempio n. 9
0
 /**
  * Look-up player
  * @param CommandSender $req
  * @param str $n
  */
 public static function getPlayer(CommandSender $c, $n)
 {
     $pl = $c->getServer()->getPlayer($n);
     if ($pl === null) {
         $c->sendMessage(mc::_("%1% not found", $n));
     }
     return $pl;
 }
Esempio n. 10
0
 public function onSCommand(CommandSender $c, Command $cc, $scmd, $data, array $args)
 {
     if (count($args) == 0) {
         return false;
     }
     if ($scmd == "fixname") {
         $world = implode(" ", $args);
         $c->sendMessage(TextFormat::AQUA . mc::_("Running /mw lvdat %1% name=%1%", $world));
         $args = [$world, "name={$world}"];
     }
     $world = array_shift($args);
     if (!$this->owner->autoLoad($c, $world)) {
         $c->sendMessage(TextFormat::RED . mc::_("[MW] %1% is not loaded!", $world));
         return true;
     }
     $level = $this->owner->getServer()->getLevelByName($world);
     if (!$level) {
         $c->sendMessage(TextFormat::RED . mc::_("[MW] Unexpected error"));
         return true;
     }
     //==== provider
     $provider = $level->getProvider();
     $changed = false;
     $unload = false;
     foreach ($args as $kv) {
         $kv = explode("=", $kv, 2);
         if (count($kv) != 2) {
             $c->sendMessage(mc::_("Invalid element: %1%, ignored", $kv[0]));
             continue;
         }
         list($k, $v) = $kv;
         switch (strtolower($k)) {
             case "spawn":
                 $pos = explode(",", $v);
                 if (count($pos) != 3) {
                     $c->sendMessage(mc::_("Invalid spawn location: %1%", implode(",", $pos)));
                     continue;
                 }
                 list($x, $y, $z) = $pos;
                 $cpos = $provider->getSpawn();
                 if (($x = intval($x)) == $cpos->getX() && ($y = intval($y)) == $cpos->getY() && ($z = intval($z)) == $cpos->getZ()) {
                     $c->sendMessage(mc::_("Spawn location is unchanged"));
                     continue;
                 }
                 $changed = true;
                 $provider->setSpawn(new Vector3($x, $y, $z));
                 break;
             case "seed":
                 if ($provider->getSeed() == intval($v)) {
                     $c->sendMessage(mc::_("Seed unchanged"));
                     continue;
                 }
                 $changed = true;
                 $unload = true;
                 $provider->setSeed($v);
                 break;
             case "name":
                 // LevelName String
                 if ($provider->getName() == $v) {
                     $c->sendMessage(mc::_("Name unchanged"));
                     continue;
                 }
                 $changed = true;
                 $unload = true;
                 $provider->getLevelData()->LevelName = new String("LevelName", $v);
                 break;
             case "generator":
                 // generatorName(String)
                 if ($provider->getLevelData()->generatorName == $v) {
                     $c->sendMessage(mc::_("Generator unchanged"));
                     continue;
                 }
                 $changed = true;
                 $unload = true;
                 $provider->getLevelData()->generatorName = new String("generatorName", $v);
                 break;
             case "preset":
                 // String("generatorOptions");
                 if ($provider->getLevelData()->generatorOptions == $v) {
                     $c->sendMessage(mc::_("Preset unchanged"));
                     continue;
                 }
                 $changed = true;
                 $unload = true;
                 $provider->getLevelData()->generatorOptions = new String("generatorOptions", $v);
                 break;
             default:
                 $c->sendMessage(mc::_("Unknown key %1%, ignored", $k));
                 continue;
         }
     }
     if ($changed) {
         $c->sendMessage(mc::_("Updating level.dat for %1%", $world));
         $provider->saveLevelData();
         if ($unload) {
             $c->sendMessage(TextFormat::RED . mc::_("CHANGES WILL NOT TAKE EFFECT UNTIL UNLOAD"));
         }
     } else {
         $c->sendMessage(mc::_("Nothing happens"));
     }
     return true;
 }
Esempio n. 11
0
 private function mwWorldDetails(CommandSender $sender, $world)
 {
     $txt = [];
     if ($this->owner->getServer()->isLevelLoaded($world)) {
         $unload = false;
     } else {
         if (!$this->owner->autoLoad($sender, $world)) {
             $sender->sendMessage(TextFormat::RED . mc::_("Error getting %1%", $world));
             return null;
         }
         $unload = true;
     }
     $level = $this->owner->getServer()->getLevelByName($world);
     //==== provider
     $provider = $level->getProvider();
     $txt[] = mc::_("Info for %1%", $world);
     $txt[] = TextFormat::AQUA . mc::_("Provider: ") . TextFormat::WHITE . $provider::getProviderName();
     $txt[] = TextFormat::AQUA . mc::_("Path: ") . TextFormat::WHITE . $provider->getPath();
     $txt[] = TextFormat::AQUA . mc::_("Name: ") . TextFormat::WHITE . $provider->getName();
     $txt[] = TextFormat::AQUA . mc::_("Seed: ") . TextFormat::WHITE . $provider->getSeed();
     $txt[] = TextFormat::AQUA . mc::_("Generator: ") . TextFormat::WHITE . $provider->getGenerator();
     $gopts = $provider->getGeneratorOptions();
     if ($gopts["preset"] != "") {
         $txt[] = TextFormat::AQUA . mc::_("Generator Presets: ") . TextFormat::WHITE . $gopts["preset"];
     }
     $spawn = $provider->getSpawn();
     $txt[] = TextFormat::AQUA . mc::_("Spawn: ") . TextFormat::WHITE . $spawn->getX() . "," . $spawn->getY() . "," . $spawn->getZ();
     $plst = $level->getPlayers();
     $lst = "";
     if (count($plst)) {
         foreach ($plst as $p) {
             $lst .= (strlen($lst) ? ", " : "") . $p->getName();
         }
     }
     $txt[] = TextFormat::AQUA . mc::_("Players(%1%):", count($plst)) . TextFormat::WHITE . $lst;
     // Check for warnings...
     if ($provider->getName() != $world) {
         $txt[] = TextFormat::RED . mc::_("Folder Name and Level.Dat names do NOT match");
         $txt[] = TextFormat::RED . mc::_("This can cause intermitent problems");
         if ($sender->hasPermission("mw.cmd.lvdat")) {
             $txt[] = TextFormat::RED . mc::_("Use: ");
             $txt[] = TextFormat::GREEN . mc::_("> /mw fixname %1%", $world);
             $txt[] = TextFormat::RED . mc::_("to fix this issue");
         }
     }
     if ($unload) {
         $this->owner->getServer()->unloadLevel($level);
     }
     return $txt;
 }
 /**
  * Dispatch commands using sub command table
  */
 protected function dispatchSCmd(CommandSender $sender, Command $cmd, array $args, $data = null)
 {
     if ($this->scmdMap === null) {
         $sender->sendMessage(mc::_("No sub-commands available"));
         return false;
     }
     return $this->scmdMap->dispatchSCmd($sender, $cmd, $args, $data);
 }