Ejemplo n.º 1
0
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (count($args) > 1) {
         return false;
     }
     if (count($args) == 0) {
         if (!MPMU::inGame($sender)) {
             return true;
         }
         $target = $sender;
         $other = false;
     } else {
         if (!MPMU::access($sender, "gb.cmd." . $cmd->getName() . ".others")) {
             return true;
         }
         $target = $this->owner->getServer()->getPlayer($args[0]);
         if ($target === null) {
             $sender->sendMessage(mc::_("%1% can not be found.", $args[0]));
             return true;
         }
         $other = true;
     }
     $n = strtolower($target->getName());
     if ($target->isOp()) {
         // Player is dropping from op...
         $this->reops[$n] = true;
         $target->setOp(false);
         if ($other) {
             $sender->sendMessage(mc::_("%1% is no longer Op", $target->getDisplayName()));
         }
         $target->sendMessage(mc::_("You are no longer Op"));
         return true;
     }
     // Player wants to resume op
     if (isset($this->reops[$n])) {
         $target->setOp(true);
         unset($this->reops[$n]);
         if ($other) {
             $sender->sendMessage(mc::_("%1% is now Op", $target->getDisplayName()));
         }
         $target->sendMessage(mc::_("You are now Op"));
         return true;
     }
     // This player can not be re-opped
     if ($other) {
         $sender->sendMessage(mc::_("That is not possible"));
         return true;
     }
     $sender->sendMessage(mc::_("You are not allowed to do this"));
     return true;
 }
Ejemplo n.º 2
0
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (count($args) == 0) {
         return false;
     }
     $i = array_pop($args);
     if (($type = ArmorItems::str2quality($i)) == ArmorItems::ERROR) {
         $sender->sendMessage(mc::_("Unknown armor quality %1%", $i));
         return false;
     }
     $slots = [0, 1, 2, 3];
     // All slots
     if (count($args)) {
         $i = ArmorItems::str2part($args[count($args) - 1]);
         if ($i != ArmorItems::ERROR) {
             $slots = [$i];
             array_pop($args);
         }
     }
     $pl = $sender;
     if (count($args)) {
         $i = $this->owner->getServer()->getPlayer($args[count($args) - 1]);
         if ($i) {
             $pl = $i;
             if (!MPMU::access($sender, "gb.cmd.setarmor.others")) {
                 return true;
             }
             array_pop($args);
         }
     }
     if (count($args)) {
         return false;
     }
     if (!MPMU::inGame($pl)) {
         return true;
     }
     foreach ($slots as $i) {
         $pl->getInventory()->setArmorItem($i, new Item(ArmorItems::getItemId($type, $i), 0, 1));
     }
     if ($type == ArmorItems::NONE) {
         $sender->sendMessage(mc::_("Amouring down %1%", $pl->getName()));
     } else {
         $sender->sendMessage(mc::_("Amouring up %1%", $pl->getName()));
     }
     // Make sure inventory is updated...
     $pl->getInventory()->sendArmorContents($pl);
     return true;
 }
Ejemplo n.º 3
0
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (count($args) > 1) {
         return false;
     }
     if (count($args) == 0) {
         if (!MPMU::inGame($sender)) {
             return true;
         }
         $target = $sender;
         $other = false;
     } else {
         if (!MPMU::access($sender, "gb.cmd." . $cmd->getName() . ".others")) {
             return true;
         }
         $target = $this->owner->getServer()->getPlayer($args[0]);
         if ($target === null) {
             $sender->sendMessage(mc::_("%1% can not be found.", $args[0]));
             return true;
         }
         $other = true;
     }
     switch ($cmd->getName()) {
         case "clearinv":
             $target->getInventory()->clearAll();
             if ($other) {
                 $target->sendMessage(mc::_("Your inventory has been cleared by %1%", $sender->getName()));
             }
             $sender->sendMessage(mc::_("%1%'s inventory cleared", $target->getName()));
             return true;
         case "clearhotbar":
             $inv = $target->getInventory();
             for ($i = 0; $i < $inv->getHotbarSize(); $i++) {
                 $inv->setHotbarSlotIndex($i, -1);
             }
             if ($other) {
                 $target->sendMessage(mc::_("Your hotbar has been cleared by %1%", $sender->getName()));
             }
             $sender->sendMessage(mc::_("%1%'s hotbar cleared", $target->getName()));
             // Make sure inventory is updated...
             $inv->sendContents($target);
             return true;
     }
     return false;
 }
Ejemplo n.º 4
0
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (count($args) == 0) {
         $args = ["summary"];
     }
     switch ($cmd->getName()) {
         case "query":
             switch ($n = strtolower(array_shift($args))) {
                 case "add":
                     if (!MPMU::access($sender, "gb.cmd.query.addrm")) {
                         return true;
                     }
                     return $this->cmdAdd($sender, $args);
                 case "rm":
                     if (!MPMU::access($sender, "gb.cmd.query.addrm")) {
                         return true;
                     }
                     return $this->cmdRm($sender, $args);
                 case "ls":
                     if (!MPMU::access($sender, "gb.cmd.query.details")) {
                         return true;
                     }
                     return $this->cmdList($sender, $args);
                 case "info":
                 case "plugins":
                     if (!MPMU::access($sender, "gb.cmd.query.details")) {
                         return true;
                     }
                     return $this->cmdQuery($sender, $n, $args);
                 case "players":
                     if (!MPMU::access($sender, "gb.cmd.query.players")) {
                         return true;
                     }
                     $pageNumber = $this->getPageNumber($args);
                     if (count($args) && $sender->hasPermission("gb.cmd.query.players.showip")) {
                         return $this->cmdQuery($sender, $n, $args, $pageNumber);
                     }
                     return $this->cmdPlayers($sender, $pageNumber);
                 case "list":
                     if (!MPMU::access($sender, "gb.cmd.query.list")) {
                         return true;
                     }
                     $pageNumber = $this->getPageNumber($args);
                     return $this->cmdListAll($sender, $pageNumber);
                 case "summary":
                     return $this->cmdSummary($sender);
             }
     }
     return false;
 }
Ejemplo n.º 5
0
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     switch ($cmd->getName()) {
         case "nick":
             if (!MPMU::inGame($sender)) {
                 return true;
             }
             if (count($args) == 0) {
                 $sender->sendName(mc::_("Current nick is: %1%", $sender->getDisplayName()));
                 return true;
             }
             if (count($args) !== 1) {
                 return false;
             }
             $this->owner->getServer(mc::_("%1% is now known as %2%", $sender->getDisplayName(), $args[0]));
             $sender->setDisplayName($args[0]);
             return true;
         case "clearchat":
             if (!MPMU::inGame($sender)) {
                 return true;
             }
             if (count($args) != 0) {
                 return false;
             }
             for ($i = 0; $i < 32; ++$i) {
                 $sender->sendMessage(" ");
             }
             return true;
         case "chat-on":
         case "chat-off":
             if (count($args) > 0) {
                 switch ($n = strtolower(array_shift($args))) {
                     case "--list":
                     case "--ls":
                     case "-l":
                         if (!MPMU::access($sender, "gb.cmd.togglechat.others")) {
                             return true;
                         }
                         $pageNumber = $this->getPageNumber($args);
                         $txt = [""];
                         $cols = 8;
                         $i = 0;
                         foreach ($this->owner->getServer()->getOnlinePlayers() as $p) {
                             if (!$this->getState($p, false)) {
                                 continue;
                             }
                             $n = $p->getDisplayName();
                             if ($i++ % $cols == 0) {
                                 $txt[] = $n;
                             } else {
                                 $txt[count($txt) - 1] .= ", " . $n;
                             }
                         }
                         if ($i == 0) {
                             $sender->sendMessage(mc::_("No players with chat off"));
                             if (!$this->chat) {
                                 $sender->sendMessage(mc::_("Chat is GLOBALLY off"));
                             }
                             return true;
                         }
                         if ($this->chat) {
                             $txt[0] = mc::n(mc::_("One player with chat off"), mc::_("%1% players with chat off", $i), $i);
                         } else {
                             $txt[0] = mc::_("Chat is GLOBALLY off");
                         }
                         return $this->paginateText($sender, $pageNumber, $txt);
                     case "--server":
                     case "--global":
                     case "-g":
                         if (count($args)) {
                             return false;
                         }
                         if (!MPMU::access($sender, "gb.cmd.togglechat.global")) {
                             return true;
                         }
                         if ($cmd->getName() == "chat-off") {
                             $this->chat = false;
                             $this->owner->getServer()->broadcastMessage(mc::_("Chat disabled globally from %1%", $sender->getName()));
                         } else {
                             $this->chat = true;
                             $this->owner->getServer()->broadcastMessage(mc::_("Chat enabled globally from %1%", $sender->getName()));
                         }
                         return true;
                     default:
                         if (count($args)) {
                             return false;
                         }
                         if (!MPMU::access($sender, "gb.cmd.togglechat.others")) {
                             return true;
                         }
                         $player = $this->owner->getServer()->getPlayer($n);
                         if ($player === null) {
                             $sender->sendMessage(mc::_("Unable to find %1%", $n));
                             return true;
                         }
                         if ($cmd->getName() == "chat-off") {
                             $this->setState($player, true);
                             $player->sendMessage(mc::_("Chat disabled from %1%", $sender->getName()));
                             $sender->sendMessage(mc::_("Chat disabled for %1%", $player->getDisplayName()));
                         } else {
                             $this->unsetState($player);
                             $player->sendMessage(mc::_("Chat enabled from %1%", $sender->getName()));
                             $sender->sendMessage(mc::_("Chat enabled for %1%", $player->getDisplayName()));
                         }
                         return true;
                 }
                 return false;
             }
             if (!MPMU::inGame($sender)) {
                 return true;
             }
             if ($cmd->getName() == "chat-off") {
                 $this->setState($sender, true);
                 $sender->sendMessage(mc::_("Chat disabled"));
             } else {
                 $this->unsetState($sender);
                 $sender->sendMessage(mc::_("Chat enabled"));
             }
             return true;
     }
     return false;
 }
Ejemplo n.º 6
0
 private function cmdRm(CommandSender $c, $args)
 {
     if (!MPMU::access($c, "gb.cmd.rcon.config")) {
         return true;
     }
     if (count($args) != 1) {
         $c->sendMessage(mc::_("Usage: --rm <id>"));
         return false;
     }
     $id = array_shift($args);
     if (!isset($this->servers[$id])) {
         $c->sendMessage(mc::_("%1% does not exist", $id));
         return false;
     }
     unset($this->servers[$id]);
     $this->owner->cfgSave("rcon-client", $this->servers);
     $c->sendMessage(mc::_("Rcon id %1% deleted", $id));
     return true;
 }
Ejemplo n.º 7
0
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "skin") {
         return false;
     }
     $pageNumber = $this->getPageNumber($args);
     if (isset($args[0])) {
         $human = $this->owner->getServer()->getPlayer($args[0]);
         if ($human !== null) {
             array_shift($args);
         } else {
             $human = $sender;
         }
     }
     if (count($args) == 0) {
         $args = ["ls"];
     }
     switch (strtolower(array_shift($args))) {
         case "ls":
             $skins = glob($this->owner->getDataFolder() . "*.skin");
             if (count($skins) == 0) {
                 $sender->sendMessage(mc::_("No skins found"));
                 return true;
             }
             $txt = [mc::n(mc::_("Found one skin"), mc::_("Found %1% skins", count($skins)), count($skins))];
             $cols = 8;
             $i = 0;
             foreach ($skins as $n) {
                 $n = basename($n, ".skin");
                 if ($i++ % $cols == 0) {
                     $txt[] = $n;
                 } else {
                     $txt[count($txt) - 1] .= ", " . $n;
                 }
             }
             return $this->paginateText($sender, $pageNumber, $txt);
         case "save":
             if (count($args) != 1) {
                 return false;
             }
             if (!MPMU::inGame($human)) {
                 return true;
             }
             if ($human !== $sender && !MPMU::access($sender, "gb.cmd.skin.other")) {
                 return true;
             }
             $fn = preg_replace('/\\.skin$/', '', basename($args[0])) . ".skin";
             $bin = zlib_encode($human->getSkinData(), ZLIB_ENCODING_DEFLATE, 9);
             file_put_contents($this->owner->getDataFolder() . $fn, $bin);
             $sender->sendMessage(mc::_("Wrote %1% bytes to %2%", strlen($bin), $fn));
             return true;
         case "load":
             $slim = false;
             if (isset($args[0]) && $args[0] == "--slim") {
                 $slim = true;
                 array_shift($args);
             }
             if ($human !== $sender && !MPMU::access($sender, "gb.cmd.skin.other")) {
                 return true;
             }
             if (count($args) != 1) {
                 return false;
             }
             if (!MPMU::inGame($human)) {
                 return true;
             }
             $fn = preg_replace('/\\.skin$/', '', basename($args[0])) . ".skin";
             $bin = file_get_contents($this->owner->getDataFolder() . $fn);
             if ($bin === false) {
                 $sender->sendMessage(mc::_("Unable to read %1%", $fn));
                 return true;
             }
             $human->setSkin(zlib_decode($bin), $slim);
             $sender->sendMessage(mc::_("Updated skin for %1%", $human->getName()));
             return true;
     }
     return false;
 }
Ejemplo n.º 8
0
 private function rmInvItem(CommandSender $sender, array $args)
 {
     if (count($args) == 0) {
         return false;
     }
     if (($target = $this->owner->getServer()->getPlayer($args[0])) === null) {
         if (!MPMU::inGame($sender)) {
             return true;
         }
         $target = $sender;
         $other = false;
     } else {
         if (!MPMU::access($sender, "gb.cmd.rminv.others")) {
             return true;
         }
         array_shift($args);
         $other = true;
     }
     if (count($args) == 0) {
         return false;
     }
     if ($target->isCreative() || $target->isSpectator()) {
         $sender->sendMessage(mc::_("%1% is in %2% mode", $target->getDisplayName(), MPMU::gamemodeStr($target->getGamemode())));
         return true;
     }
     $count = null;
     if (count($args) > 1 && is_numeric($args[count($args) - 1])) {
         $count = array_pop($args);
     }
     $args = strtolower(implode("_", $args));
     if ($args == "hand") {
         $item = clone $target->getInventory()->getItemInHand();
         if ($item->getId() == 0) {
             $sender->sendMessage(mc::_("Must be holding something"));
             return true;
         }
     } else {
         $item = Item::fromString($args);
         if ($item->getId() == 0) {
             $sender->sendMessage(mc::_("There is no item called %1%", $args));
             return true;
         }
     }
     $k = 0;
     foreach ($target->getInventory()->getContents() as $slot => &$inv) {
         if ($inv->getId() != $item->getId()) {
             continue;
         }
         if ($count !== null) {
             if ($inv->getCount() > $count) {
                 $k += $count;
                 $inv->setCount($inv->getCount() - $count);
                 $target->getInventory()->setItem($slot, clone $inv);
                 break;
             }
             $count -= $inv->getCount();
         }
         $k += $inv->getCount();
         $target->getInventory()->clear($slot);
         if ($count === 0) {
             break;
         }
     }
     if ($k) {
         $sender->sendMessage(mc::n(mc::_("one item of %1% removed", ItemName::str($item)), mc::_("%2% items of %1% removed", ItemName::str($item), $k), $k));
         if ($other) {
             $target->sendMessage(mc::n(mc::_("%2% took one item of %1% from you", ItemName::str($item), $sender->getName()), mc::_("%3% took %2% items of %1% from you", ItemName::str($item), $k, $sender->getName()), $k));
         }
     } else {
         $sender->sendMessage(mc::_("No items were removed!"));
     }
     return true;
 }
Ejemplo n.º 9
0
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     switch ($cmd->getName()) {
         case "opms":
             if (count($args) == 0) {
                 return false;
             }
             $ms = TextFormat::BLUE . mc::_("OpMsg [%1%] ", $sender->getName()) . TextFormat::YELLOW . implode(" ", $args);
             $this->owner->getLogger()->info($ms);
             $count = 0;
             foreach ($this->owner->getServer()->getOnlinePlayers() as $pl) {
                 if (!$pl->isOp()) {
                     continue;
                 }
                 $pl->sendMessage($ms);
                 ++$count;
             }
             if ($sender instanceof Player && !$sender->isOp()) {
                 if ($count) {
                     $sender->sendMessage(mc::_("(ops:%1%) ", $count) . implode(" ", $args));
                 } else {
                     $sender->sendMessage(mc::_("Message sent to console only"));
                     if ($sender->hasPermission("gb.cmd.rpt")) {
                         $sender->sendMessage(mc::_("Try /rpt instead"));
                     }
                 }
             }
             return true;
         case "rpt":
             if (count($args) == 0) {
                 return false;
             }
             list($id, $rpt) = $this->rpt->getAll();
             if ($args[0] == "read" && (count($args) == 1 || count($args) == 2 && is_numeric($args[1]))) {
                 if (!MPMU::access($sender, "gb.cmd.rpt.read")) {
                     return false;
                 }
                 if (count($rpt) == 0) {
                     $sender->sendMessage(TextFormat::RED . mc::_("No reports on file!"));
                     return true;
                 }
                 $pageNumber = $this->getPageNumber($args);
                 $tab = [[mc::_("ID"), mc::_("Date"), mc::_("Name"), mc::_("Reports: %1%", count($rpt))]];
                 foreach ($rpt as $i => $ln) {
                     list($tm, $name, $ms) = $ln;
                     $tm = date(mc::_("d-M H:i"), $tm);
                     $tab[] = [$i, $tm, $name, $ms];
                 }
                 $this->paginateTable($sender, $pageNumber, $tab);
                 return true;
             }
             if ($args[0] == "clear" && count($args) == 2) {
                 if (!MPMU::access($sender, "gb.cmd.rpt.read")) {
                     return false;
                 }
                 if ($args[1] == "all") {
                     $rpt = [];
                     $sender->sendMessage(TextFormat::RED . mc::_("All reports deleted"));
                 } else {
                     $i = intval($args[1]);
                     if (!isset($rpt[$i])) {
                         $sender->sendMessage(mc::_("Unknown report #%1%", $i));
                         return true;
                     }
                     unset($rpt[$i]);
                     $sender->sendMessage(mc::_("Deleting report #%1%", $i));
                 }
             } else {
                 $rpt[++$id] = [time(), $sender->getName(), implode(" ", $args)];
                 $sender->sendMessage(mc::_("Report filed as #%1%", $id));
                 $ms = TextFormat::BLUE . mc::_("Rpt[#%1% from %2%] ", $id, $sender->getName()) . TextFormat::YELLOW . implode(" ", $args);
                 $this->owner->getLogger()->info($ms);
                 foreach ($this->owner->getServer()->getOnlinePlayers() as $pl) {
                     if (!$pl->isOp()) {
                         continue;
                     }
                     $pl->sendMessage($ms);
                 }
             }
             $this->rpt->setAll([$id, $rpt]);
             $this->rpt->save();
             return true;
     }
     return false;
 }