public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "as") {
         return false;
     }
     if (count($args) < 2) {
         $sender->sendMessage(mc::_("Must specified a player and a command"));
         return false;
     }
     $player = $this->owner->getServer()->getPlayer($n = array_shift($args));
     if (!$player) {
         $sender->sendMessage(mc::_("Player %1% not found", $n));
         return true;
     }
     if ($args[0] == 'chat' || $args[0] == 'say') {
         array_shift($args);
         $chat = implode(" ", $args);
         $this->owner->getServer()->getPluginManager()->callEvent($ev = new PlayerChatEvent($player, $chat));
         if (!$ev->isCancelled()) {
             if (MPMU::apiVersion("1.12.0")) {
                 $s = $this->owner->getServer();
                 $s->broadcastMessage($s->getLanguage()->translateString($ev->getFormat(), [$ev->getPlayer()->getDisplayName(), $ev->getMessage()]), $ev->getRecipients());
             } else {
                 $this->owner->getServer()->broadcastMessage(sprintf($ev->getFormat(), $ev->getPlayer()->getDisplayName(), $ev->getMessage()), $ev->getRecipients());
             }
         }
     } else {
         $cmdline = implode(' ', $args);
         $sender->sendMessage(mc::_("Running command as %1%", $n));
         $this->owner->getServer()->dispatchCommand($player, $cmdline);
     }
     return true;
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (!MPMU::inGame($sender)) {
         return true;
     }
     switch ($cmd->getName()) {
         case "gmc":
             $mode = 1;
             break;
         case "gms":
             $mode = 0;
             break;
         case "gma":
             $mode = 2;
             break;
         case "gmspc":
             $mode = 3;
             break;
         default:
             return false;
     }
     if ($mode !== $sender->getGamemode()) {
         $sender->setGamemode($mode);
         if ($mode !== $sender->getGamemode()) {
             $sender->sendMessage(TextFormat::RED . mc::_("Unable to change gamemode"));
         } else {
             $this->owner->getServer()->broadcastMessage(mc::_("%1% changed gamemode to %2% mode", $sender->getName(), MPMU::gamemodeStr($mode)));
         }
     } else {
         $sender->sendMessage(mc::_("You are already in %1% mode", MPMU::gamemodeStr($mode)));
     }
     return true;
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (!isset($args[0])) {
         return false;
     }
     if ($cmd->getName() != "get") {
         return false;
     }
     if ($sender->isCreative()) {
         $sender->sendMessage(mc::_("You are in creative mode"));
         return true;
     }
     $item = Item::fromString($args[0]);
     if ($item->getId() == 0) {
         $sender->sendMessage(TextFormat::RED . mc::_("There is no item called %1%", $args[0]));
         return true;
     }
     if (isset($args[1])) {
         $item->setCount((int) $args[1]);
     } else {
         if (isset(self::$stacks[$item->getId()])) {
             $item->setCount(self::$stacks[$item->getId()]);
         } else {
             $item->setCount($item->getMaxStackSize());
         }
     }
     $sender->getInventory()->addItem(clone $item);
     $this->owner->getServer()->broadcastMessage(mc::_("%1% got %2% of %3% (%4%:%5%)", $sender->getName(), $item->getCount(), MPMU::itemName($item), $item->getId(), $item->getDamage()));
     return true;
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "heal") {
         return false;
     }
     if (count($args) == 0) {
         if (!MPMU::inGame($sender)) {
             return true;
         }
         $sender->setHealth($sender->getMaxHealth());
         $sender->sendMessage(mc::_("You have been healed"));
         return true;
     }
     $patient = $this->owner->getServer()->getPlayer($args[0]);
     if ($patient == null) {
         $sender->sendMessage(mc::_("%1% not found.", $args[0]));
         return true;
     }
     if (isset($args[1]) && is_numeric($args[1])) {
         $health = $patient->getHealth() + intval($args[1]);
         if ($health > $patient->getMaxHealth()) {
             $health = $patient->getMaxHealth();
         }
     } else {
         $health = $patient->getMaxHealth();
     }
     $patient->setHealth($health);
     $sender->sendMessage(mc::_("%1% was healed.", $args[0]));
     return true;
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "players") {
         return false;
     }
     $tab = [[mc::_("Player"), mc::_("World"), mc::_("Pos"), mc::_("Health"), mc::_("Mode")]];
     $cnt = 0;
     foreach ($this->owner->getServer()->getOnlinePlayers() as $player) {
         if (!$player->isOnline() || $sender instanceof Player && !$sender->canSee($player)) {
             continue;
         }
         $pos = $player->getPosition();
         $j = count($tab);
         $mode = substr(MPMU::gamemodeStr($player->getGamemode()), 0, 4);
         $tab[] = [$player->getName(), $player->getLevel()->getName(), $pos->getFloorX() . "," . $pos->getFloorY() . "," . $pos->getFloorZ(), intval($player->getHealth()) . '/' . intval($player->getMaxHealth()), $mode];
         ++$cnt;
     }
     if (!$cnt) {
         $sender->sendMessage(TextFormat::RED . mc::_("Nobody is on-line at the moment"));
         return true;
     }
     $tab[0][0] = mc::_("Players: %1%", $cnt);
     $pageNumber = $this->getPageNumber($args);
     return $this->paginateTable($sender, $pageNumber, $tab);
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "throw") {
         return false;
     }
     if (count($args) > 2 || count($args) == 0) {
         return false;
     }
     $pl = $this->owner->getServer()->getPlayer($args[0]);
     if (!$pl) {
         $sender->sendMessage(mc::_("%1% not found", $args[0]));
         return true;
     }
     if (MPMU::apiVersion("1.12.0")) {
         $pl->teleport(new Vector3($pl->getX(), 128, $pl->getZ()));
     } else {
         $force = 64;
         if (isset($args[1])) {
             $force = intval($args[1]);
         }
         if ($force <= 4) {
             $force = 64;
         }
         $pl->setMotion(new Vector3(0, $force, 0));
     }
     return true;
 }
 public function processCmd($msg, $sender)
 {
     if (preg_match('/^\\s*!!/', $msg)) {
         $msg = trim(preg_replace('/^\\s*!!\\s*/', '', $msg));
         // Match !
         $last = $this->owner->getState("RepeatMgr", $sender, false);
         if ($last === false) {
             $sender->sendMessage(mc::_("You do not have any recorded previous command"));
             return false;
         }
         // Just the previous command...
         if ($msg == "") {
             return $last;
         }
         if (is_numeric($msg)) {
             // We need to replace the last word with $msg....
             $words = preg_split('/\\s+/', $last);
             if (count($words) == 1) {
                 // Only a single world, we append the number...
                 $newmsg = $last . " " . $msg;
             } else {
                 if (is_numeric($words[count($words) - 1])) {
                     // Exchange the last word (page count)
                     $words[count($words) - 1] = $msg;
                     $newmsg = implode(" ", $words);
                 } else {
                     // Last word wasn't a number... append one
                     $newmsg = $last . " " . $msg;
                 }
             }
         } elseif ($msg == "/" && substr($last, 0, 1) != "/") {
             // Forgotten "/"
             $newmsg = "/" . $last;
         } elseif (substr($msg, 0, 1) == "^") {
             // Do we need space?
             if (preg_match('/^\\s+/', $msg)) {
                 $newmsg = trim(substr($msg, 1)) . " " . $last;
             } else {
                 $newmsg = trim(substr($msg, 1)) . $last;
             }
         } else {
             $words = preg_split('/\\s+/', $msg, 2);
             if (count($words) > 1 && stristr($last, $words[0]) !== false) {
                 // Replace string
                 $newmsg = str_ireplace($words[0], $words[1], $last);
             } else {
                 // Add string...
                 $newmsg = $last . ' ' . $msg;
             }
         }
         if (!$sender instanceof Player) {
             $sender->sendMessage(">> {$newmsg}");
         }
         $last = $this->owner->setState("RepeatMgr", $sender, $newmsg);
         return $newmsg;
     }
     $last = $this->owner->setState("RepeatMgr", $sender, $msg);
     return false;
 }
 private function deactivate(Player $pl)
 {
     $pl->sendMessage(mc::_("You are no longer invisible"));
     $this->setState($pl, false);
     foreach ($this->owner->getServer()->getOnlinePlayers() as $online) {
         $online->showPlayer($pl);
     }
 }
 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;
 }
 public function onPlayerJoin(PlayerJoinEvent $e)
 {
     $pl = $e->getPlayer();
     if ($pl == null) {
         return;
     }
     if ($this->srvmotd) {
         $pl->sendMessage($this->owner->getServer()->getMotd());
     }
     if ($this->admjoin && $pl->isOp()) {
         $pn = $pl->getDisplayName();
         $this->owner->getServer()->broadcastMessage(mc::_("Server op {$pn} joined."));
     }
 }
 /**
  * @priority MONITOR
  */
 public function onTransfer(PlayerTransferEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     $pl = $ev->getPlayer();
     if (!$pl instanceof Player) {
         return;
     }
     for ($i = 0; $i < 20; $i++) {
         $pl->getLevel()->addParticle(new DustParticle(self::randVector($pl), mt_rand() / mt_getrandmax() * 2, 255, 255, 255));
     }
     $pl->getLevel()->addSound(new FizzSound($pl));
     $this->owner->getServer()->broadcastMessage(mc::_("%1% is transferring to %2%:%3%", $pl->getName(), $ev->getAddress(), $ev->getPort()));
 }
 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;
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (!MPMU::inGame($sender)) {
         return true;
     }
     if ($cmd->getName() != "fly") {
         return false;
     }
     if ($sender->getAllowFlight()) {
         $sender->sendMessage(mc::_("Disabling flight mode"));
         $sender->setAllowFlight(false);
     } else {
         $sender->sendMessage(mc::_("Enabling flight mode"));
         $sender->setAllowFlight(true);
     }
     return true;
 }
 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;
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "showtimings") {
         return false;
     }
     $pageNumber = $this->getPageNumber($args);
     if (count($args)) {
         // Show the specified report
         $rpt = array_shift($args);
         if ($rpt == "clear") {
             $count = 0;
             foreach (glob($this->owner->getServer()->getDataPath() . "timings/timings*.txt") as $f) {
                 unlink($f);
                 $count++;
             }
             $sender->sendMessage(mc::_("Deleted reports: %1%", $count));
             return true;
         }
         $rpt = preg_replace('/[^0-9]+/i', '', $rpt);
         $f = $this->owner->getServer()->getDataPath() . "timings/timings{$rpt}.txt";
         if (!file_exists($f)) {
             $sender->sendMessage(mc::_("Report %1% can not be found.", $rpt));
             return true;
         }
         $txt = file($f);
         array_unshift($txt, mc::_("Report: timings%1%", $rpt));
         return $this->paginateText($sender, $pageNumber, $txt);
     }
     $txt = ["HDR"];
     // Inventorise the reports
     $count = 0;
     foreach (glob($this->owner->getServer()->getDataPath() . "timings/timings*.txt") as $f) {
         ++$count;
         $txt[] = "- " . basename($f);
     }
     if ($count == 0) {
         $sender->sendMessage(TextFormat::RED . mc::_("No timmings report found"));
         $sender->sendMessage(mc::_("Enable timings by typing /timings on"));
         $sender->sendMessage(mc::_("Generate timings report by typing /timings report"));
         return true;
     }
     $txt[0] = mc::_("Reports: %1%", $count);
     return $this->paginateText($sender, $pageNumber, $txt);
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "prefix") {
         return false;
     }
     if (count($args) == 0 || count($args) == 1 && $args[0] == "-n") {
         $this->unsetState($sender);
         $sender->sendMessage(mc::_("prefix turned off"));
         return true;
     }
     $sep = " ";
     if ($args[0] == "-n") {
         $sep = "";
         array_shift($args);
     }
     $this->setState($sender, $n = implode(" ", $args) . $sep);
     $sender->sendMessage(mc::_("Prefix set to \"%1%\"", $n));
     return true;
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "ops") {
         return false;
     }
     $txt = [""];
     $pageNumber = $this->getPageNumber($args);
     $cnt = 0;
     foreach (array_keys($this->owner->getServer()->getOps()->getAll()) as $opname) {
         $p = $this->owner->getServer()->getPlayer($opname);
         if ($p && ($p->isOnline() && (!$sender instanceof Player || $sender->canSee($p)))) {
             ++$cnt;
             $txt[] = TextFormat::BLUE . mc::_("%1% (online)", $opname);
         } else {
             $txt[] = TextFormat::RED . "{$opname}";
         }
     }
     $txt[0] = mc::_("Server Ops (Online:%1%)", $cnt);
     return $this->paginateText($sender, $pageNumber, $txt);
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (count($args) !== 0) {
         return false;
     }
     if ($cmd->getName() != "shield") {
         return false;
     }
     if (!MPMU::inGame($sender)) {
         return true;
     }
     $state = $this->getState($sender, false);
     if ($state) {
         $sender->sendMessage(mc::_("Shields DOWN"));
         $this->setState($sender, false);
     } else {
         $sender->sendMessage(mc::_("Shields UP"));
         $this->setState($sender, true);
     }
     return true;
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "blowup") {
         return false;
     }
     if (count($args) == 0) {
         return false;
     }
     $pl = $this->owner->getServer()->getPlayer($args[0]);
     if (!$pl) {
         $sender->sendMessage(mc::_("%1% not found.", $args[0]));
         return true;
     }
     array_shift($args);
     $yield = 5;
     $magic = false;
     foreach ($args as $i) {
         if (is_numeric($i)) {
             $yield = intval($i);
             if ($yield < 1) {
                 $yield = 1;
             }
         } elseif (strtolower($i) == "magic") {
             $magic = true;
         } elseif (strtolower($i) == "normal") {
             $magic = false;
         }
     }
     $this->owner->getServer()->getPluginManager()->callEvent($cc = new ExplosionPrimeEvent($pl, $yield));
     if ($cc->isCancelled()) {
         return true;
     }
     $explosion = new Explosion($pl, $yield);
     if (!$magic) {
         $explosion->explodeA();
     }
     $explosion->explodeB();
     return true;
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (count($args) == 0) {
         $sender->sendMessage(mc::_("Spectators: %1%", count($this->watchers)));
         if (count($this->watchers)) {
             $sender->sendMessage(implode(", ", $this->watchers));
         }
         return true;
     }
     switch ($cmd->getName()) {
         case "spectator":
             foreach ($args as $n) {
                 $player = $this->owner->getServer()->getPlayer($n);
                 if ($player) {
                     $this->watchers[strtolower($player->getName())] = $player->getName();
                     $player->sendMessage(mc::_("You are now an spectator"));
                     $sender->sendMessage(mc::_("%1% is now an spectator", $n));
                 } else {
                     $sender->sendMessage(mc::_("%1% not found.", $n));
                 }
             }
             return true;
         case "unspectator":
             foreach ($args as $n) {
                 if (isset($this->watchers[strtolower($n)])) {
                     unset($this->watchers[strtolower($n)]);
                     $player = $this->owner->getServer()->getPlayer($n);
                     if ($player) {
                         $player->sendMessage(mc::_("You are no longer an spectator"));
                     }
                     $sender->sendMessage(mc::_("%1% is not an spectator", $n));
                 } else {
                     $sender->sendMessage(mc::_("%1% not found.", $n));
                 }
             }
             return true;
     }
     return false;
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "burn") {
         return false;
     }
     if (count($args) > 2 || count($args) == 0) {
         return false;
     }
     $pl = $this->owner->getServer()->getPlayer($args[0]);
     if (!$pl) {
         $sender->sendMessage(mc::_("%1% not found", $args[0]));
         return true;
     }
     $secs = 15;
     if (isset($args[1])) {
         $secs = intval($args[1]);
     }
     if ($secs <= 1) {
         $secs = 15;
     }
     $pl->setOnFire($secs);
     return true;
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "slay") {
         return false;
     }
     if (!isset($args[0])) {
         $sender->sendMessage(mc::_("Must specify a player to slay"));
         return false;
     }
     $victim = $this->owner->getServer()->getPlayer($n = array_shift($args));
     if ($victim == null) {
         $sender->sendMessage(mc::_("Player %1% not found", $n));
         return true;
     }
     if (count($args)) {
         $this->setState($victim, [time(), implode(" ", $args)]);
     } else {
         $this->unsetState($victim);
     }
     $victim->setHealth(0);
     $sender->sendMessage(TextFormat::RED . mc::_("%1% has been slain.", $victim->getName()));
     return true;
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     $pageNumber = $this->getPageNumber($args);
     if (count($args) != 1) {
         $sender->sendMessage(mc::_("You must specify a player's name"));
         return false;
     }
     $target = $this->owner->getServer()->getPlayer($args[0]);
     if ($target == null) {
         $sender->sendMessage(mc::_("%1% can not be found.", $args[0]));
         return true;
     }
     if ($cmd->getName() == "seeinv") {
         $tab = [[$args[0], mc::_("Count"), mc::_("Damage")]];
         $max = $target->getInventory()->getSize();
         foreach ($target->getInventory()->getContents() as $slot => &$item) {
             if ($slot >= $max) {
                 continue;
             }
             $tab[] = [MPMU::itemName($item) . " (" . $item->getId() . ")", $item->getCount(), $item->getDamage()];
         }
         if (count($tab) == 1) {
             $sender->sendMessage(mc::_("The inventory for %1% is EMPTY", $args[0]));
             return true;
         }
     } elseif ($cmd->getName() == "seearmor") {
         $tab = [[mc::_("Armor for"), TextFormat::RED . $args[0]]];
         foreach ([0 => "head", 1 => "body", 2 => "legs", 3 => "boots"] as $slot => $attr) {
             $item = $target->getInventory()->getArmorItem($slot);
             if ($item->getID() == 0) {
                 continue;
             }
             $tab[] = [$attr . TextFormat::BLUE, MPMU::itemName($item) . " (" . $item->getId() . ":" . $item->getDamage() . ")"];
         }
     }
     return $this->paginateTable($sender, $pageNumber, $tab);
 }
 public function kickuser($pn)
 {
     $player = $this->owner->getServer()->getPlayer($pn);
     if (!$player instanceof Player) {
         return;
     }
     $this->owner->getServer()->broadcastMessage(TextFormat::RED . mc::_("%1% attempted to join", $pn));
     $player->kick($this->mode);
 }
Beispiel #25
0
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "reg") {
         return false;
     }
     if (count($args) == 0) {
         $args = ["count"];
     }
     $scmd = strtolower(array_shift($args));
     switch ($scmd) {
         case "count":
             if (count($args) != 0) {
                 return false;
             }
             $cnt = count(glob($this->owner->getServer()->getDataPath() . "players/*.dat"));
             $sender->sendMessage(mc::n(mc::_("One player registered"), mc::_("%1% players registered", $cnt), $cnt));
             return true;
         case "ls":
         case "list":
             $pageNumber = $this->getPageNumber($args);
             if (count($args) == 0) {
                 $pattern = "*";
             } elseif (count($args) == 1) {
                 $pattern = implode(" ", $args);
             } else {
                 return false;
             }
             $f = glob($this->owner->getServer()->getDataPath() . "players/" . $pattern . ".dat");
             $txt = [mc::n(mc::_("One player found"), mc::_("%1% players found", count($f)), count($f))];
             $cols = 8;
             $i = 0;
             foreach ($f as $n) {
                 $n = basename($n, ".dat");
                 if ($i++ % $cols == 0) {
                     $txt[] = $n;
                 } else {
                     $txt[count($txt) - 1] .= ", " . $n;
                 }
             }
             return $this->paginateText($sender, $pageNumber, $txt);
         case "rm":
             if (count($args) != 1) {
                 return false;
             }
             $victim = strtolower(array_shift($args));
             $target = $this->owner->getServer()->getPlayer($victim);
             if ($target !== null) {
                 $sender->sendMessage(TextFormat::RED . mc::_("Can not delete player re-gistration while they are on-line"));
                 return true;
             }
             $target = $this->owner->getServer()->getOfflinePlayer($victim);
             if ($target == null || !$target->hasPlayedBefore()) {
                 $sender->sendMessage(mc::_("%1% can not be found.", $victim));
                 return true;
             }
             $f = $this->owner->getServer()->getDataPath() . "players/" . $victim . ".dat";
             if (!is_file($f)) {
                 $sender->sendMessage(TextFormat::RED . mc::_("Problem deleting %1%", $victim));
                 return true;
             }
             unlink($f);
             $sender->sendMessage(TextFormat::RED . mc::_("%1% was deleted.", $victim));
             return true;
         case "since":
             $pageNumber = $this->getPageNumber($args);
             if (count($args) == 0) {
                 return false;
             }
             if (($when = strtotime(implode(" ", $args))) === false) {
                 return false;
             }
             $f = glob($this->owner->getServer()->getDataPath() . "players/*.dat");
             $tab = [[mc::_("Date/Time"), "x"]];
             foreach ($f as $n) {
                 $n = basename($n, ".dat");
                 $target = $this->owner->getServer()->getOfflinePlayer($n);
                 if ($target == null || !$target->hasPlayedBefore()) {
                     continue;
                 }
                 if (($regdate = $target->getFirstPlayed() / 1000) > $when) {
                     $tab[] = [date(mc::_("d-M-Y H:i"), $regdate), $n];
                 }
             }
             $cnt = count($tab) - 1;
             if ($cnt == 0) {
                 $sender->sendMessage(mc::_("No players found"));
                 return true;
             }
             $tab[0][1] = mc::n(mc::_("One player found"), mc::_("%1% players found", $cnt), $cnt);
             return $this->paginateTable($sender, $pageNumber, $tab);
     }
     return false;
 }
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "whois") {
         return false;
     }
     $pageNumber = $this->getPageNumber($args);
     if (count($args) != 1) {
         $sender->sendMessage(mc::_("You must specify a player's name"));
         return true;
     }
     $target = $this->owner->getServer()->getPlayer($args[0]);
     if ($target == null) {
         $target = $this->owner->getServer()->getOfflinePlayer($args[0]);
         if ($target == null || !$target->hasPlayedBefore()) {
             $sender->sendMessage(mc::_("%1% can not be found.", $args[0]));
             return true;
         }
     }
     $txt = [];
     $txt[] = TextFormat::AQUA . mc::_("About %1%", $args[0]);
     $txt[] = TextFormat::GREEN . mc::_("On-Line: ") . TextFormat::WHITE . ($target->isOnline() ? mc::_("YES") : mc::_("NO"));
     if ($target instanceof Player) {
         $txt[] = TextFormat::GREEN . mc::_("Health: ") . TextFormat::WHITE . "[" . $target->getHealth() . "/" . $target->getMaxHealth() . "]";
         $txt[] = TextFormat::GREEN . mc::_("World: ") . TextFormat::WHITE . $target->getLevel()->getName();
         $txt[] = TextFormat::GREEN . mc::_("Location: ") . TextFormat::WHITE . "X:" . floor($target->getPosition()->x) . " Y:" . floor($target->getPosition()->y) . " Z:" . floor($target->getPosition()->z);
         if ($sender->hasPermission("gb.cmd.whois.showip")) {
             $txt[] = TextFormat::GREEN . mc::_("IP Address: ") . TextFormat::WHITE . $target->getAddress();
         }
         $txt[] = TextFormat::GREEN . mc::_("Gamemode: ") . TextFormat::WHITE . MPMU::gamemodeStr($target->getGamemode());
         $txt[] = TextFormat::GREEN . mc::_("Display Name: ") . TextFormat::WHITE . $target->getDisplayName();
         $txt[] = TextFormat::GREEN . mc::_("Flying: ") . TextFormat::WHITE . ($target->isOnGround() ? mc::_("NO") : mc::_("YES"));
         //1.5
         if (MPMU::apiVersion("1.12.0")) {
             $txt[] = TextFormat::GREEN . mc::_("UUID: ") . TextFormat::WHITE . $target->getUniqueId();
             $txt[] = TextFormat::GREEN . mc::_("ClientID: ") . TextFormat::WHITE . $target->getClientId();
             $txt[] = TextFormat::GREEN . mc::_("Can Fly: ") . TextFormat::WHITE . ($target->getAllowFlight() ? mc::_("YES") : mc::_("NO"));
         }
     } else {
         $txt[] = TextFormat::GREEN . mc::_("Banned: ") . TextFormat::WHITE . ($target->isBanned() ? mc::_("YES") : mc::_("NO"));
     }
     $txt[] = TextFormat::GREEN . mc::_("Whitelisted: ") . TextFormat::WHITE . ($target->isWhitelisted() ? mc::_("YES") : mc::_("NO"));
     $txt[] = TextFormat::GREEN . mc::_("Opped: ") . TextFormat::WHITE . ($target->isOp() ? mc::_("YES") : mc::_("NO"));
     $txt[] = TextFormat::GREEN . mc::_("First Played: ") . TextFormat::WHITE . date(mc::_("d-M-Y H:i"), $target->getFirstPlayed() / 1000);
     // $target->getLastPlayed()."\n";//##DEBUG
     if ($target->getLastPlayed()) {
         $txt[] = TextFormat::GREEN . mc::_("Last Played: ") . TextFormat::WHITE . date(mc::_("d-M-Y H:i"), $target->getLastPlayed() / 1000);
     }
     $pm = $this->owner->getServer()->getPluginManager();
     if (($kr = $pm->getPlugin("KillRate")) !== null) {
         if (version_compare($kr->getDescription()->getVersion(), "1.1") >= 0) {
             if (intval($kr->getDescription()->getVersion()) == 2) {
                 echo get_class($kr->api) . "\n";
                 //##DEBUG
                 $score = $kr->api->getScore($target);
             } else {
                 $score = $kr->getScore($target);
             }
             if ($score) {
                 $txt[] = TextFormat::GREEN . mc::_("KillRate Score: ") . TextFormat::WHITE . $score;
             }
         } else {
             $txt[] = TextFormat::RED . mc::_("KillRate version is too old (%1%)", $kr->getDescription()->getVersion());
         }
     }
     if (($pp = $pm->getPlugin("PurePerms")) !== null) {
         $txt[] = TextFormat::GREEN . mc::_("PurePerms Group: ") . TextFormat::WHITE . $pp->getUser($target)->getGroup()->getName();
     }
     if (($sa = $pm->getPlugin("SimpleAuth")) !== null) {
         if ($target instanceof Player) {
             $txt[] = TextFormat::GREEN . mc::_("Authenticated: ") . TextFormat::WHITE . ($sa->isPlayerAuthenticated($target) ? mc::_("YES") : mc::_("NO"));
         }
         $txt[] = TextFormat::GREEN . mc::_("Registered: ") . TextFormat::WHITE . ($sa->isPlayerRegistered($target) ? mc::_("YES") : mc::_("NO"));
     }
     $money = MoneyAPI::moneyPlugin($this->owner);
     if ($money !== null) {
         $txt[] = TextFormat::GREEN . mc::_("Money: ") . TextFormat::WHITE . MoneyAPI::getMoney($money, $target->getName()) . TextFormat::AQUA . mc::_(" (from %1%)", $money->getFullName());
     }
     return $this->paginateText($sender, $pageNumber, $txt);
 }
 private function cmdDismiss(CommandSender $c, $args)
 {
     if (count($args) == 0) {
         return false;
     }
     if (!MPMU::inGame($c)) {
         return true;
     }
     $state = $this->getState($c, []);
     if (count($state) == 0) {
         $c->sendMessage(mc::_("There is nobody to dismiss"));
         $c->sendMessage(mc::_("You need to summon people first"));
         return true;
     }
     if ($args[0] == "--all") {
         $args = array_keys($state);
     }
     foreach ($args as $i) {
         $pl = $this->owner->getServer()->getPlayer($i);
         if (!$pl) {
             $c->sendMessage(mc::_("%1% can not be found.", $i));
             $i = strtolower($i);
             if (isset($state[$i])) {
                 unset($state[$i]);
             }
             continue;
         }
         $pn = strtolower($pl->getName());
         if (!isset($state[$pn])) {
             $c->sendMessage(mc::_("%1% was never summoned", $i));
             continue;
         }
         $pl->sendMessage(mc::_("You have been dismissed by %1%", $c->getName()));
         $c->sendMessage(mc::_("Dismissing %1%", $i));
         $pl->teleport($state[$pn]);
         unset($state[$pn]);
     }
     $this->setState($c, $state);
     return true;
 }
Beispiel #28
0
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if (!isset($args[0])) {
         return false;
     }
     if ($cmd->getName() == "gift") {
         if (($receiver = $this->owner->getServer()->getPlayer($args[0])) == null) {
             if (!MPMU::inGame($sender)) {
                 return true;
             }
             $receiver = $sender;
         } else {
             array_shift($args);
         }
     } else {
         if (!MPMU::inGame($sender)) {
             return true;
         }
         $receiver = $sender;
     }
     if ($receiver->isCreative()) {
         if ($receiver === $sender) {
             $receiver->sendMessage(mc::_("You are in creative mode"));
         } else {
             $sender->sendMessage(mc::_("%1% is in creative mode", $receiver->getDisplayName()));
         }
         return true;
     }
     if (count($args) > 1 && is_numeric($args[count($args) - 1])) {
         $amt = (int) array_pop($args);
     } else {
         $amt = -1;
     }
     $args = strtolower(implode("_", $args));
     if ($args == "more") {
         $item = clone $receiver->getInventory()->getItemInHand();
         if ($item->getId() == 0) {
             $sender->sendMessage(TextFormat::RED . mc::_("Must be holding something"));
             return true;
         }
     } else {
         $item = Item::fromString($args);
         if ($item->getId() == 0) {
             $sender->sendMessage(TextFormat::RED . mc::_("There is no item called %1%", $args));
             return true;
         }
     }
     if ($amt != -1) {
         $item->setCount($amt);
     } else {
         if (isset(self::$stacks[$item->getId()])) {
             $item->setCount(self::$stacks[$item->getId()]);
         } else {
             $item->setCount($item->getMaxStackSize());
         }
     }
     $receiver->getInventory()->addItem(clone $item);
     $this->owner->getServer()->broadcastMessage(mc::_("%1% got %2% of %3% (%4%:%5%)", $receiver->getDisplayName(), $item->getCount(), ItemName::str($item), $item->getId(), $item->getDamage()));
     return true;
 }
 private function cmdEtSign(CommandSender $c, $opt, $args)
 {
     if (count($args) < 1) {
         $c->sendMessage(mc::_("Usage: /et sign[1-4] <id> <text>\n"));
         return false;
     }
     $i = array_shift($args);
     $tile = $this->getTile($i);
     if ($tile == null) {
         $c->sendMessage(mc::_("Tile %1% not found", $i));
         return true;
     }
     if (strtolower(substr($i, 0, 1)) != "t") {
         $c->sendMessage(mc::_("Only applies to tile ids"));
         return false;
     }
     if (!$tile instanceof Sign) {
         $c->sendMessage(mc::_("Tile %1% is not a sign", $i));
         return false;
     }
     $sign = $tile->getText();
     $txt = implode(" ", $args);
     $sub = intval(substr($opt, -1)) - 1;
     if ($sign[$sub] == $txt) {
         $c->sendMessage(mc::_("Text unchanged"));
         return true;
     }
     $sign[$sub] = $txt;
     $tile->setText($sign[0], $sign[1], $sign[2], $sign[3]);
     $c->sendMessage(mc::_("Changed to \"%1%\"", $txt));
     return true;
 }
 public function onChat(PlayerChatEvent $ev)
 {
     //echo __METHOD__.",".__LINE__."\n";//##DEBUG
     if ($ev->isCancelled()) {
         return;
     }
     $p = $ev->getPlayer();
     if (isset($this->mutes[strtolower($p->getName())])) {
         $p->sendMessage(mc::_("You have been muted!"));
         $ev->setCancelled();
     }
 }