Exemplo n.º 1
0
 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[] = [ItemName::str($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, ItemName::str($item) . " (" . $item->getId() . ":" . $item->getDamage() . ")"];
         }
     }
     return $this->paginateTable($sender, $pageNumber, $tab);
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 private function cmdEtList(CommandSender $c, $args)
 {
     $pageNumber = $this->getPageNumber($args);
     if (count($args) > 1) {
         $c->sendMessage(mc::_("Usage: /et ls [world]"));
         return false;
     }
     if (count($args)) {
         $level = $this->owner->getServer()->getLevelByName($args[0]);
         if (!$level) {
             $c->sendMessage(mc::_("%1%: World not found", $args[0]));
             return true;
         }
     } else {
         if (MPMU::inGame($c, false)) {
             $level = $c->getLevel();
         } else {
             $level = $this->owner->getServer()->getDefaultLevel();
         }
     }
     $cnt = 0;
     $tab = [];
     $tab[] = ["-", mc::_("Name"), mc::_("Position"), mc::_("Health")];
     foreach ($level->getEntities() as $e) {
         if ($e instanceof Player) {
             continue;
         }
         $id = $e->getId();
         $pos = implode(",", [floor($e->getX()), floor($e->getY()), floor($e->getZ())]);
         if ($e instanceof Living) {
             $name = $e->getName();
         } elseif ($e instanceof \pocketmine\entity\Item) {
             $name = mc::_("Item:%1%", ItemName::str($e->getItem()));
         } else {
             $name = basename(strtr(get_class($e), "\\", "/"));
         }
         ++$cnt;
         $tab[] = [$id, $name, $pos, $e->getHealth()];
     }
     $tab[0][0] = "#:{$cnt}";
     if ($cnt) {
         return $this->paginateTable($c, $pageNumber, $tab);
     }
     $c->sendMessage(mc::_("No entities found"));
     return true;
 }
Exemplo n.º 4
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;
 }