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; }
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 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() != "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 ($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 (!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 (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 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() != "spawn") { return false; } if (count($args) != 0) { return false; } if (!MPMU::inGame($sender)) { return true; } $pos = $sender->getLevel()->getSafeSpawn(); $sender->sendMessage("Teleporting to spawn..."); $sender->teleport($pos); 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 onEnable() { if (!is_dir($this->getDataFolder())) { mkdir($this->getDataFolder()); } mc::plugin_init($this, $this->getFile()); $features = ["players" => ["CmdPlayers", true], "ops" => ["CmdOps", true], "gm?" => ["CmdGmx", true], "as" => ["CmdAs", true], "slay" => ["CmdSlay", true], "heal" => ["CmdHeal", true], "whois" => ["CmdWhois", true], "mute-unmute" => ["CmdMuteMgr", true], "freeze-thaw" => ["CmdFreezeMgr", true], "showtimings" => ["CmdTimings", true], "seeinv-seearmor" => ["CmdShowInv", true], "clearinv" => ["CmdClearInv", true], "get" => ["CmdGet", true], "shield" => ["CmdShieldMgr", true], "srvmode" => ["CmdSrvModeMgr", true], "opms-rpt" => ["CmdOpMsg", true], "entities" => ["CmdEntities", true], "after-at" => ["CmdAfterAt", true], "summon-dismiss" => ["CmdSummon", true], "pushtp-poptp" => ["CmdTpStack", true], "prefix" => ["CmdPrefixMgr", true], "spawn" => ["CmdSpawn", true], "burn" => ["CmdBurn", true], "blowup" => ["CmdBlowUp", true], "setarmor" => ["CmdSetArmor", true], "spectator" => ["CmdSpectator", false], "followers" => ["CmdFollowMgr", true], "rcon-client" => ["CmdRcon", true], "join-mgr" => ["JoinMgr", true], "repeater" => ["RepeatMgr", true], "broadcast-tp" => ["BcTpMgr", true], "crash" => ["CmdCrash", true], "pluginmgr" => ["CmdPluginMgr", true], "permmgr" => ["CmdPermMgr", true], "throw" => ["CmdThrow", true], "regmgr" => ["CmdRegMgr", true], "invisible" => ["CmdInvisible", true], "chat-utils" => ["CmdChatMgr", true], "query-hosts" => ["CmdQuery", true]]; if (MPMU::apiVersion("1.12.0")) { $features["fly"] = ["CmdFly", true]; $features["skinner"] = ["CmdSkinner", true]; $features["blood-particles"] = ["BloodMgr", true]; $ft = $this->getServer()->getPluginManager()->getPlugin("FastTransfer"); if ($ft) { $features["broadcast-ft"] = ["TransferMgr", true]; } } $cfg = $this->modConfig(__NAMESPACE__, $features, ["version" => $this->getDescription()->getVersion(), "rcon-client" => [], "query-hosts" => [], "join-mgr" => JoinMgr::defaults(), "broadcast-tp" => BcTpMgr::defaults(), "freeze-thaw" => CmdFreezeMgr::defaults()]); }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { if (count($args) !== 0) { return false; } if ($cmd->getName() != "invis") { return false; } if (!MPMU::inGame($sender)) { return true; } $state = $this->getState($sender, false); if ($state) { $this->deactivate($sender); } else { $this->activate($sender); } return true; }
/** * @priority MONITOR */ public function onTeleport(EntityTeleportEvent $ev) { echo __METHOD__ . "," . __LINE__ . "\n"; //##DEBUG if ($ev->isCancelled()) { return; } $pl = $ev->getEntity(); if (!$pl instanceof Player) { return; } $from = $ev->getFrom(); if (!$from->getLevel()) { $from->setLevel($pl->getLevel()); } $to = $ev->getTo(); if (!$to->getLevel()) { $to->setLevel($pl->getLevel()); } if (MPMU::apiVersion("1.12.0")) { foreach ([$to, $from] as $pos) { for ($i = 0; $i < 20; $i++) { $pos->getLevel()->addParticle(new DustParticle(self::randVector($pos), mt_rand() / mt_getrandmax() * 2, 255, 255, 255)); } $pos->getLevel()->addSound(new FizzSound($pos)); } } if ($from->getLevel()->getName() != $to->getLevel()->getName()) { if ($this->world) { $this->owner->getServer()->broadcastMessage(mc::_("%1% teleported to %2%", $pl->getName(), $to->getLevel()->getName())); } return; } if (!$this->local) { return; } $dist = $from->distance($to); if ($dist > $this->local) { $this->owner->getServer()->broadcastMessage(mc::_("%1% teleported away!", $pl->getName())); } }
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; }
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; }
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); }
private function cmdTileList(CommandSender $c, $args) { $pageNumber = $this->getPageNumber($args); if (count($args) > 1) { $c->sendMessage(mc::_("Usage: /et tiles [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")]; foreach ($level->getTiles() as $t) { $id = $t->getId(); $pos = implode(",", [floor($t->getX()), floor($t->getY()), floor($t->getZ())]); $name = basename(strtr(get_class($t), "\\", "/")); $tab[] = [$id, $name, $pos]; ++$cnt; } $tab[0][0] = "#:{$cnt}"; if ($cnt) { return $this->paginateTable($c, $pageNumber, $tab); } $c->sendMessage(mc::_("No tiles found")); return true; }
private function cmdAlias(CommandSender $sender, array $args) { if (count($args) == 0 || count($args) == 1 && is_numeric($args[0])) { return $this->lsAliaes($sender, $args); } if (count($args) == 1) { return $this->showAlias($sender, $args[0]); } if (args[0] == "-f") { $force = true; array_shift($args); if (count($args) <= 1) { return false; } } else { $force = false; } // Create an alias $alias = array_shift($args); $cmdline = implode(" ", $args); if ($this->owner->getServer()->getCommandMap()->getCommand($alias) !== null) { if ($force) { MPMU::rmCommand($this->owner->getServer(), $alias); } else { $sender->sendMessage(TextFormat::RED . mc::_("%1% already exists use -f option", $alias)); return true; } } $this->aliases[$alias] = new AliasCmd($this->owner, $alias, $cmdline); $sender->sendMessage(TextFormat::GREEN . mc::_("Created alias \"%1%\" as \"%2%\"", $alias, $cmdline)); return true; }
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; }
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; }
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; }
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; }
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; }
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; }
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 cmdPopTp(CommandSender $c, $args) { if (!MPMU::inGame($c)) { return true; } if (count($args)) { return false; } $stack = $this->getState($c, []); if (count($stack) == 0) { $c->sendMessage(mc::_("TpStack is empty")); return true; } $pos = array_pop($stack); $c->sendMessage(mc::_("Teleporting...")); $c->teleport($pos); $this->setState($c, $stack); return true; }
public function onPlayerMoveEvent(PlayerMoveEvent $ev) { $n = MPMU::iName($ev->getPlayer()); if (isset($this->followers[$n])) { $this->approach($n, $this->followers[$n]); } if (isset($this->leaders[$n])) { foreach ($this->leaders[$n] as $follower) { $this->approach($follower, $n); } } }
public function onMove(PlayerMoveEvent $ev) { //echo __METHOD__.",".__LINE__."\n";//##DEBUG if ($ev->isCancelled()) { return; } $p = $ev->getPlayer(); if (isset($this->frosties[strtolower($p->getName())])) { if ($this->hard) { $ev->setCancelled(); if (MPMU::apiVersion("1.12.0")) { $p->sendTip(mc::_("You are frozen")); } } else { // Lock position but still allow to turn around $to = clone $ev->getFrom(); $to->yaw = $ev->getTo()->yaw; $to->pitch = $ev->getTo()->pitch; $ev->setTo($to); if (MPMU::apiVersion("1.12.0")) { $p->sendTip(mc::_("You are frozen in place")); } } } }