public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { echo __METHOD__ . "," . __LINE__ . "\n"; //##DEBUG if (strtolower($cmd->getName()) != "afk") { return false; } if (!MPMU::inGame($sender)) { return true; } $api = $this->owner->api; if ($api->isShielded($sender) && $api->isFrozen($sender) && $api->getMute($sender)) { // Current AFK'ed $msg = count($args) == 0 ? mc::_("%1% is back at keyboard", $sender->getName()) : implode(" ", $args); $api->freeze($sender, false); $api->setMute($sender, false); $api->setShield($sender, false); } else { $msg = count($args) == 0 ? mc::_("%1% is away from keyboard", $sender->getName()) : implode(" ", $args); $api->freeze($sender, true); $api->setMute($sender, true); $api->setShield($sender, true); } $this->owner->getServer()->broadcastMessage($msg); 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; }
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->blowPlayer($pl, $yield, $magic); return true; }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { if ($cmd->getName() != "near") { return false; } if (!MPMU::inGame($sender)) { return true; } switch (count($args)) { case 0: $radius = 64 * 64; break; case 1: $radius = (int) $args[0] * (int) $args[0]; break; default: return false; } $players = []; foreach ($sender->getLevel()->getPlayers() as $pl) { $dist = $pl->distanceSquared($players); if ($dist < $radius) { $players[] = $pl->getDisplayName(); } } if (count($players) == 0) { $sender->sendMessage(mc::_("No near by players found!")); } else { $sender->sendMessage(mc::_("Neighbors(%1%): %2%", count($players), implode(", ", $players))); } return true; }
public function onEnable() { if (\pocketmine\DEBUG <= 1) { return; } echo __METHOD__ . "," . __LINE__ . "\n"; //##DEBUG // Create example folders if (!is_dir($this->getDataFolder())) { mkdir($this->getDataFolder()); } $mft = explode("\n", trim($this->getResourceContents("manifest.txt"))); foreach ($mft as $f) { if (file_exists($this->getDataFolder() . $f)) { continue; } $txt = $this->getResourceContents("examples/" . $f); file_put_contents($this->getDataFolder() . $f, $txt); } echo __METHOD__ . "," . __LINE__ . "\n"; //##DEBUG mc::plugin_init($this, $this->getFile()); MPMU::addCommand($this, $this, "libcommon", ["description" => "LibCommon Command Line interface", "usage" => "/libcommon <subcommand> [options]", "aliases" => ["lc"], "permission" => "libcommon.debug.command"]); $this->modules = []; foreach (["Version", "DumpMsgs"] as $mod) { echo __METHOD__ . "," . __LINE__ . " - {$mod}\n"; //##DEBUG $mod = __NAMESPACE__ . "\\" . $mod; $this->modules[] = new $mod($this); } $this->modules[] = new BasicHelp($this); }
public function onSCommand(CommandSender $c, Command $cc, $scmd, $data, array $args) { if (count($args) != 1) { return false; } $pname = $args[0]; $mgr = $this->owner->getServer()->getPluginManager(); $plugin = $mgr->getPlugin($pname); if ($plugin === null) { $c->sendMessage(mc::_("%1%: plugin not found", $pname)); return true; } $getini = [$plugin, "getMessagesIni"]; if (!is_callable($getini)) { $c->sendMessage(mc::_("%1%: does not support dumping messages.ini", $pname)); return true; } if (!is_dir($plugin->getDataFolder())) { mkdir($plugin->getDataFolder()); } if (file_put_contents($plugin->getDataFolder() . "messages.ini", $getini())) { $c->sendMessage(mc::_("%1%: messages.ini created", $pname)); } else { $c->sendMessage(mc::_("%1%: error dumping messages.ini", $pname)); } return true; }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { if ($cmd->getName() != "top") { return false; } switch (count($args)) { case 0: if (!MPMU::inGame($sender)) { return true; } $pl = $sender; break; case 1: if (!MPMU::access($sender, "gb.cmd.top.others")) { return true; } $pl = $this->owner->getServer()->getPlayer($args[0]); if (!$pl) { $sender->sendMessage(mc::_("%1% not found", $args[0])); return true; } break; default: return false; } $y = $pl->getLevel()->getHighestBlockAt($pl->getX(), $pl->getZ()) + 1; $pl->teleport(new Vector3($pl->getX(), $y, $pl->getZ())); return true; }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { switch (count($args)) { case 0: if (!MPMU::inGame($sender)) { return true; } $target = $sender; break; case 1: if (($target = $this->owner->getServer()->getPlayer($args[0])) == null) { $sender->sendMessage(mc::_("%1% not found", $args[0])); return true; } break; default: return false; } $item = clone $target->getInventory()->getItemInHand(); $sender->sendMesage(TextFormat::BLUE . mc::_("Item: ") . TextFormat::WHITE . ItemName::str($item)); $sender->sendMesage(TextFormat::BLUE . mc::_("ItemId: ") . TextFormat::WHITE . $item->getId()); $sender->sendMesage(TextFormat::BLUE . mc::_("Count: ") . TextFormat::WHITE . $item->getCount()); $sender->sendMesage(TextFormat::BLUE . mc::_("Damage: ") . TextFormat::WHITE . $item->getDamage()); return true; }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { if (count($args) !== 0) { return false; } if ($cmd->getName() != "back") { return false; } if (!MPMU::inGame($sender)) { return true; } $pos = $this->getState($sender, null); if ($pos == null) { $sender->sendMessage(mc::_("No recorded death position to return to")); return true; } list($x, $y, $z, $world) = $pos; $level = TPUtils::getLevelByName($this->owner->getServer(), $world); if ($level === null) { $sender->sendMessage(mc::_("Can not return to your death location")); $this->unsetState($sender); return true; } $sender->sendMessage(mc::_("Teleporting to the place of your demise")); TPUtils::tpNearBy($sender, new Position($x, $y, $z, $level)); $this->unsetState($sender); return true; }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { if (strtolower($cmd->getName()) != "wall") { return false; } if (count($args) == 0) { return false; } if ($sender instanceof RemoteConsoleCommandSender && ($who = MPMU::startsWith($args[1], "--rpc=")) !== null) { array_shift($args); $msg = implode(" ", $args); if ($msg != "") { $this->owner->getServer()->broadcastMesage(mc::_("WALL:%1% %2%", $who, $msg)); } return true; } $msg = implode(" ", $args); $who = $sender->getName(); $this->owner->getServer()->broadcastMessage(mc::_("WALL:%1% %2%", $who, $msg)); $lst = $this->owner->getModule("ServerList"); foreach ($lst->getIds() as $id) { if ($lst->getServerAttr($id, "rcon-pw") === null) { continue; } $host = $lst->getServerAttr($id, "rcon-host"); $port = $lst->getServerAttr($id, "rcon-port"); $auth = $lst->getServerAttr($id, "rcon-pw"); $this->owner->getServer()->getScheduler()->scheduleAsyncTask(new RconTask($this->owner, "rconDone", [$host, $port, $auth], "wall --rpc=" . $who . " " . $msg, [null])); } 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) { $pageNumber = $this->getPageNumber($args); if (count($args) != 1) { $sender->sendMessage(mc::_("You must specify a player's name")); return false; } if (($target = MPMU::getPlayer($sender, $args[0])) === null) { 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); }
public function __construct($owner) { parent::__construct($owner); PermUtils::add($this->owner, "gb.cmd.top", "top commnad", "op"); PermUtils::add($this->owner, "gb.cmd.top.others", "top others commnad", "op"); $this->enableCmd("top", ["description" => mc::_("Teleport player to top most block"), "usage" => mc::_("/top [player]"), "permission" => "gb.cmd.top"]); }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { switch (count($args)) { case 0: if (!MPMU::inGame($sender)) { return true; } $target = $sender; $other = false; break; case 1: if (($target = MPMU::getPlayer($sender, $args[0])) === null) { return true; } $other = true; break; default: return false; } $item = clone $target->getInventory()->getItemInHand(); if ($item->getId() == Item::AIR) { if ($other) { $sender->sendMessage(mc::_("%1% is holding nothing!", $target->getDisplayName())); } else { $sender->sendMessage(mc::_("You are holding nothing!")); } return true; } $sender->sendMessage(TextFormat::BLUE . mc::_("Item: ") . TextFormat::WHITE . ItemName::str($item)); $sender->sendMessage(TextFormat::BLUE . mc::_("ItemId: ") . TextFormat::WHITE . $item->getId()); $sender->sendMessage(TextFormat::BLUE . mc::_("Count: ") . TextFormat::WHITE . $item->getCount()); $sender->sendMessage(TextFormat::BLUE . mc::_("Damage: ") . TextFormat::WHITE . $item->getDamage()); return true; }
/** * This will transfer a player and also add the workaround for players * lingering connections... * @param Player $player * @param str $address * @param int $port * @param str $message * @return bool */ public static function transferPlayer(Player $player, $address, $port, $message = null) { $ft = $player->getServer()->getPluginManager()->getPlugin("FastTransfer"); if ($ft === null) { return false; } if ($message === null) { $message = mc::_("You are being transferred"); } $res = $ft->transferPlayer($player, $address, $port, $message); // find out the RakLib interface, which is the network interface that MCPE players connect with foreach ($player->getServer()->getNetwork()->getInterfaces() as $interface) { if ($interface instanceof RakLibInterface) { $raklib = $interface; break; } } if (!isset($rakLib)) { return $res; } // calculate the identifier for the player used by RakLib $identifier = $player->getAddress() . ":" . $player->getPort(); // this method call is the most important one - // it sends some signal to RakLib that makes it think that the client // has clicked the "Quit to Title" button (or timed out). Some RakLib // internal stuff will then tell PocketMine that the player has quitted. $rakLib->closeSession($identifier, "transfer"); }
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; } if (($patient = MPMU::getPlayer($sender, $args[0])) === null) { 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() != "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 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; }
public function __construct($owner) { parent::__construct($owner); PermUtils::add($this->owner, "gb.cmd.echo", "echo command", "true"); PermUtils::add($this->owner, "gb.cmd.rem", "remark command", "true"); $this->enableCmd("echo", ["description" => mc::_("display text"), "usage" => mc::_("/echo [text]"), "permission" => "gb.cmd.echo"]); $this->enableCmd("rem", ["description" => mc::_("don't display text"), "usage" => mc::_("/rem [text]"), "permission" => "gb.cmd.rem"]); }
public function onSCommand(CommandSender $c, Command $cc, $scmd, $data, array $args) { if (count($args) != 0) { return false; } $c->sendMessage(mc::_("Version: %1%", MPMU::version())); return true; }
/** * Show a notice when the money API is found * * @param PluginBase $plugin - current plugin * @param PluginBase $api - found plugin * @param LogLevel $level - optional log level */ public static function foundMoney(PluginBase $plugin, $api, $level = LogLevel::INFO) { if (class_exists(__NAMESPACE__ . "\\mc", false)) { $plugin->getLogger()->log($level, TextFormat::BLUE . mc::_("Using money API from %1%", $api->getFullName())); } else { $plugin->getLogger()->log($level, TextFormat::BLUE . "Using money API from " . $api->getFullName()); } }
public 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); } }
/** * Expand command selectors. * Returns an array with string substitutions or `false` if no expansions * occurred. * * @param Server $server - Server context * @param CommandSender $sender - context executing this command * @param str $cmdline - command line to expand * @param int $max - max number of expansions * @return str[]|false */ public static function expandSelectors(Server $server, CommandSender $sender, $cmdline, $max = 100) { $tokens = preg_split('/\\s+/', $cmdline); $res = [$tokens]; $ret = false; foreach ($tokens as $argc => $argv) { if (!$argc) { continue; } // Trivial case... if (substr($argv, 0, 1) !== "@") { continue; } $selector = substr($argv, 1); $sargs = []; if (($i = strpos($selector, "[")) !== false) { foreach (explode(",", substr($selector, $i + 1, -1)) as $kv) { $kvp = explode("=", $kv, 2); if (count($kvp) != 2) { $sender->sendMessage(mc::_("Selector: invalid argument %1%", $kv)); continue; } $sargs[$kvp[0]] = strtolower($kvp[1]); } $selector = substr($selector, 0, $i); } $results = self::dispatchSelector($server, $sender, $selector, $sargs); if (!is_array($results) || count($results) == 0) { continue; } $ret = true; $new = []; foreach ($res as $i) { foreach ($results as $j) { $tmpLine = $i; $tmpLine[$argc] = $j; $new[] = $tmpLine; if (count($new) > $max) { break; } } if (count($new) > $max) { break; } } $res = $new; } if (!$ret) { return false; } $new = []; foreach ($res as $i) { $new[] = implode(" ", $i); } return $new; }
public function __construct($owner) { $this->owner = $owner; if ($this->owner->getModule("motd-task") == null && $this->owner->getModule("query-task") == null) { $this->owner->getLogger()->warning(mc::_("Please enable either")); $this->owner->getLogger()->warning(mc::_("motd-task or query-task")); $this->owner->getLogger()->warning(mc::_("for merge-slots to work")); return; } $this->owner->getServer()->getPluginManager()->registerEvents($this, $this->owner); }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { if (strtolower($cmd->getName()) != "xyz") { return false; } if (!MPMU::inGame($sender)) { return false; } $sender->sendMessage(mc::_("You are at %1%,%2%,%3% in world %4%, heading %5%", (int) $sender->getX(), (int) $sender->getY(), (int) $sender->getZ(), $sender->getLevel()->getName(), ExpandVars::bearing($sender->getYaw()))); 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.")); } }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { if ($cmd->getName() != "spawn") { return false; } if (count($args) != 0) { return false; } if (!MPMU::inGame($sender)) { return true; } $sender->sendMessage(mc::_("Teleporting to spawn...")); $this->tpSpawn($sender); return true; }
/** * @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 ($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; } $this->throwPlayer($pl); return true; }