本文整理汇总了PHP中pocketmine\command\CommandSender类的典型用法代码示例。如果您正苦于以下问题:PHP CommandSender类的具体用法?PHP CommandSender怎么用?PHP CommandSender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommandSender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
if ($sender instanceof Player) {
if (count($args) == 0) {
$sender->sendMessage(TextFormat::RED . "Not enough arguments.");
return;
}
if (count($args) == 1) {
if ($this->getServer()->getPlayer($args[0])) {
$location = $this->getServer()->getPlayer($args[0])->getLocation();
$sender->teleport($location);
$sender->sendMessage(TextFormat::BLUE . "[Server] You have teleported to {$args['0']}");
return;
} else {
$sender->sendMessage(TextFormat::RED . "[Server] That player isn't online!");
return;
}
}
if (count($args) == 2) {
if ($this->getServer()->getPlayer($args[0]) & getLocation() && $this->getServer()->getPlayer($args[1])) {
$location2 = $this->getServer()->getPlayer($args[1])->getLocation();
$player1 = $this->getServer()->getPlayer($args[0]);
$player2 = $this->getServer()->getPlayer($args[1]);
$player1->teleport($location2);
$player1->sendMessage(TextFormat::BLUE . "[Server] You have teleported to {$args['1']}");
return;
}
}
}
}
示例2: onSCommand
public function onSCommand(CommandSender $c, Command $cc, $scmd, $world, array $args)
{
if ($scmd != "gm") {
return false;
}
if (count($args) == 0) {
$gm = $this->owner->getCfg($world, "gamemode", null);
if ($gm === null) {
$c->sendMessage(mc::_("[WP] No gamemode for %1%", $world));
} else {
$c->sendMessage(mc::_("[WP] %1% Gamemode: %2%", $world, MPMU::gamemodeStr($gm)));
}
return true;
}
if (count($args) != 1) {
return false;
}
$newmode = $this->owner->getServer()->getGamemodeFromString($args[0]);
if ($newmode === -1) {
$this->owner->unsetCfg($world, "gamemode");
$this->owner->getServer()->broadcastMessage(mc::_("[WP] %1% gamemode removed", $world));
} else {
$this->owner->setCfg($world, "gamemode", $newmode);
$this->owner->getServer()->broadcastMessage(mc::_("[WP] %1% gamemode set to %2%", $world, MPMU::gamemodeStr($newmode)));
}
return true;
}
示例3: execute
public function execute(CommandSender $sender, array $args)
{
if (count($args) !== 1) {
return false;
}
$player = $sender->getServer()->getPlayer($sender->getName());
$biome = strtoupper($args[0]);
$plot = $this->getPlugin()->getPlotByPosition($player->getPosition());
if ($plot === null) {
$sender->sendMessage(TextFormat::RED . "You are not standing on an island");
return true;
}
if ($plot->owner !== $sender->getName()) {
$sender->sendMessage(TextFormat::RED . "You are not the owner of this island");
return true;
}
if (!isset($this->biomes[$biome])) {
$sender->sendMessage(TextFormat::RED . "That biome doesn't exist");
$biomes = implode(", ", array_keys($this->biomes));
$sender->sendMessage(TextFormat::RED . "The possible biomes are: {$biomes}");
return true;
}
$biome = Biome::getBiome($this->biomes[$biome]);
if ($this->getPlugin()->setPlotBiome($plot, $biome)) {
$sender->sendMessage(TextFormat::GREEN . "Changed the island biome");
} else {
$sender->sendMessage(TextFormat::RED . "Could not change the island biome");
}
return true;
}
示例4: execute
public function execute(CommandSender $sender, $commandLabel, array $args)
{
$commands = [];
$result = false;
foreach ($this->formatStrings as $formatString) {
try {
$commands[] = $this->buildCommand($formatString, $args);
} catch (\Exception $e) {
if ($e instanceof \InvalidArgumentException) {
$sender->sendMessage(TextFormat::RED . $e->getMessage());
} else {
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.exception"));
$logger = $sender->getServer()->getLogger();
if ($logger instanceof MainLogger) {
$logger->logException($e);
}
}
return false;
}
}
foreach ($commands as $command) {
$result |= Server::getInstance()->dispatchCommand($sender, $command);
}
return (bool) $result;
}
示例5: onCommand
public function onCommand(CommandSender $sender, Command $cmd, $label, array $sub)
{
$mm = "[TeleportView] ";
if ($sender->getName() == "CONSOLE") {
$sender->sendMessage($mm . ($this->isKorean() ? "게임내에서만 사용가능합니다." : "Please run this command in-game"));
return true;
}
$yaw = $sender->getYaw();
$pitch = $sender->getPitch();
$yawS = -sin($yaw / 180 * M_PI);
$yawC = cos($yaw / 180 * M_PI);
$pitchS = -sin($pitch / 180 * M_PI);
$pitchC = cos($pitch / 180 * M_PI);
$x = $sender->x;
$y = $sender->y + $sender->getEyeHeight();
$z = $sender->z;
$l = $sender->getLevel();
$ps = $this->getServer()->getOnlinePlayers();
for ($f = 0; $f < 50; ++$f) {
$x += $yawS * $pitchC;
$y += $pitchS;
$z += $yawC * $pitchC;
$b = $l->getBlock(new Position($x, $y, $z, $l));
if ($b->isSolid()) {
break;
}
if ($f >= 50) {
$sender->sendMessage($mm . ($this->isKorean() ? "타겟 블럭이 너무 멉니다." : "TargetBlock is too far"));
return true;
}
}
$sender->teleport(new Position($x, $y, $z, $sender->getLevel()));
return true;
}
示例6: onCommand
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;
}
示例7: exec
public function exec(CommandSender $sender, array $params)
{
$player = array_shift($params);
$amount = array_shift($params);
if (trim($player) === "" or trim($amount) === "" or !is_numeric($amount)) {
$sender->sendMessage("Usage: " . $this->getUsage());
return true;
}
$server = Server::getInstance();
$p = $server->getPlayer($player);
if ($p instanceof Player) {
$player = $p->getName();
}
if ($player === $sender->getName()) {
$sender->sendMessage($this->getPlugin()->getMessage("pay-failed"));
return true;
}
$result = $this->getPlugin()->reduceMoney($sender, $amount, false, "payment");
if ($result !== EconomyAPI::RET_SUCCESS) {
$sender->sendMessage($this->getPlugin()->getMessage("pay-failed", $sender));
return true;
}
$result = $this->getPlugin()->addMoney($player, $amount, false, "payment");
if ($result !== EconomyAPI::RET_SUCCESS) {
$sender->sendMessage($this->getPlugin()->getMessage("request-cancelled", $sender));
$this->getPlugin()->addMoney($sender, $amount, true, "payment-rollback");
return true;
}
$this->getPlugin()->getServer()->getPluginManager()->callEvent(new PayMoneyEvent($this->getPlugin(), $sender->getName(), $player, $amount));
$sender->sendMessage($this->getPlugin()->getMessage("pay-success", $sender, [$amount, $player, "%3", "%4"]));
if ($p instanceof Player) {
$p->sendMessage($this->getPlugin()->getMessage("money-paid", $p, [$sender->getName(), $amount, "%3", "%4"]));
}
return true;
}
示例8: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
if (strtolower($command->getName()) === "buyworld") {
if (count($args) < 1 || count($args) > 4) {
return false;
}
if (EconomyAPI::getInstance()->myMoney($sender->getName()) < 10000) {
$sender->sendMessage(TextFormat::RED . "[HyperPlot] You don't have enought money. It cost \$10000");
return true;
}
$world = array_shift($args);
if (strlen($world) < 3) {
$sender->sendMessage(TextFormat::RED . "[HyperPlot] Small World name");
return true;
}
if ($this->getServer()->isLevelGenerated($world)) {
$sender->sendMessage(TextFormat::RED . "[HyperPlot] A world named " . $world . " already exists");
return true;
}
EconomyAPI::getInstance()->reduceMoney($sender->getName(), 10000);
$this->getServer()->broadcastMessage($sender->sendMessage(TextFormat::RED . "[HyperPlot] Creating level " . $sender->getName() . "-" . $world . "..."));
$generator = Generator::getGenerator("ownworld");
$this->getServer()->generateLevel($sender->getName() . "-" . $world, null, $generator, []);
$this->getServer()->loadLevel($sender->getName() . "-" . $world);
return true;
}
return false;
}
示例9: execute
public function execute(CommandSender $sender, $alias, array $args)
{
if (!$sender instanceof Player) {
$sender->sendMessage("Please run this command in-game or through a CCS (run \"ccs\" for help).");
return true;
}
$session = $this->main->getSessionCollection()->getSession($sender);
if ($session === null or !$session->isValid()) {
$sender->sendMessage("Your account is still being loaded. Please wait...");
return true;
}
if ($alias[0] !== "/") {
return false;
// how come this could even happen!
}
if ($alias === "/") {
$this->displayHelp($sender);
return true;
} else {
$cmdName = substr($alias, 1);
var_dump($cmdName);
$cmd = $this->findCommand($cmdName);
if ($cmd === null) {
return false;
}
$ret = $cmd->run($session, $args);
if (is_string($ret)) {
$session->sendMessage($ret);
} elseif (is_int($ret)) {
// TODO
}
return true;
}
}
示例10: execute
public function execute(CommandSender $sender, array $args)
{
if (!$sender instanceof Player) {
$sender->sendMessage(TextFormat::YELLOW . "Please run this command in game!");
return true;
}
if (!isset($args[0])) {
$sender->sendMessage(TextFormat::RED . "Please specify a valid arena name!");
return true;
}
if (!isset($this->getMain()->arenas[strtolower($args[0])])) {
$sender->sendMessage(TextFormat::RED . "The arena " . $args[0] . " does not exist");
return true;
}
$inGame = false;
foreach ($this->getMain()->arenas as $arena) {
if ($arena->getPlayerManager()->isPlaying($sender)) {
$inGame = true;
break;
}
}
if ($inGame) {
$sender->sendMessage(TextFormat::RED . "Please quit/finish this game first");
return true;
}
if ($this->getMain()->arenas[strtolower($args[0])]->getPlayerManager()->isPlaying($sender)) {
$sender->sendMessage(TextFormat::RED . "You are already playing in that arena");
return true;
}
$this->getMain()->arenas[strtolower($args[0])]->getPlayerHandler()->spawnPlayer($sender);
return true;
}
示例11: onCommand
/**
* @param CommandSender $sender
* @param Command $command
* @param string $commandAlias
* @param array $args
*
* @return bool
*/
public function onCommand(CommandSender $sender, Command $command, $commandAlias, array $args)
{
if (strToLower($command) === $this->plugin->getDatabase()->get("command-name")) {
// TODO: 명령어만 친 경우
if (!isset($args[0])) {
$sender->sendMessage($this->plugin->getDatabase()->get("help-message"));
return true;
}
switch (strToLower($args[0])) {
//TODO: '/예제 어쩌구'
case $this->plugin->getDatabase()->get("hello-world"):
$sender->sendMessage($this->plugin->getDatabase()->get("hello-world-result"));
break;
// TODO: '/예제 저쩌구'
// TODO: '/예제 저쩌구'
case $this->plugin->getDatabase()->get("dlrow-olleh"):
$sender->sendMessage($this->plugin->getDatabase()->get("dlrow-olleh-result"));
break;
// TODO: 잘못된 명령어를 입력한 경우
// TODO: 잘못된 명령어를 입력한 경우
default:
$sender->sendMessage($this->plugin->getDatabase()->get("wrong-command"));
break;
}
}
return true;
}
示例12: onSCommand
public function onSCommand(CommandSender $c, Command $cc, $scmd, $data, array $args)
{
if (count($args) == 0) {
return false;
}
$wname = implode(" ", $args);
$old = $this->owner->getServer()->getConfigString("level-name");
if ($old == $wname) {
$c->sendMessage(TextFormat::RED . mc::_("No change"));
return true;
}
if (!$this->owner->autoLoad($c, $wname)) {
$c->sendMessage(TextFormat::RED . mc::_("[MW] Unable to load %1%", $wname));
$c->sendMessage(TextFormat::RED . mc::_("Change failed!"));
return true;
}
$level = $this->owner->getServer()->getLevelByName($wname);
if ($level === null) {
$c->sendMessage(TextFormat::RED . mc::_("Error GetLevelByName %1%"));
return true;
}
$this->owner->getServer()->setConfigString("level-name", $wname);
$this->owner->getServer()->setDefaultLevel($level);
$c->sendMessage(TextFormat::BLUE . mc::_("Default world changed to %1%", $wname));
return true;
}
示例13: onSCommand
public function onSCommand(CommandSender $c, Command $cc, $scmd, $world, array $args)
{
if ($scmd != "max") {
return false;
}
if (count($args) == 0) {
$count = $this->owner->getCfg($world, "max-players", null);
if ($count == null) {
$c->sendMessage(mc::_("[WP] Max players in %1% is un-limited", $world));
} else {
$c->sendMessage(mc::_("[WP] Players allowed in %1%: %2%", $world, $count));
}
return true;
}
if (count($args) != 1) {
return false;
}
$count = intval($args[0]);
if ($count <= 0) {
$this->owner->unsetCfg($world, "max-players");
$this->owner->getServer()->broadcastMessage(mc::_("[WP] Player limit in %1% removed", $world));
} else {
$this->owner->setCfg($world, "max-players", $count);
$this->owner->getServer()->broadcastMessage(mc::_("[WP] Player limit for %1% set to %2%", $world, $count));
}
return true;
}
示例14: execute
public function execute(CommandSender $sender, array $args)
{
if (!$sender instanceof Player) {
$sender->sendMessage($this->getMessage("error.in-game"));
return true;
}
if (!isset($args[0])) {
$sender->sendMessage($this->getMessage("commands.spectate.valid"));
}
if (!isset($this->getMain()->arenas[strtolower($args[0])])) {
$sender->sendMessage($this->getMessage("commands.spectate.exists", ["ARENA" => $args[0]]));
return true;
}
foreach ($this->getMain()->arenas as $arena) {
if ($arena->getPlayerManager()->isPlaying($sender)) {
$sender->sendMessage($this->getMessage("commands.spectate.in-game"));
return true;
}
}
if ($this->getMain()->arenas[strtolower($args[0])]->getPlayerManager()->isInArena($sender)) {
$sender->sendMessage($this->getMessage("commands.spectate.already"));
return true;
}
$this->getMain()->arenas[strtolower($args[0])]->getPlayerHandler()->spectatePlayer($sender);
return true;
}
示例15: exec
/**
* @param CommandSender $sender
* @param string[] $args
* @return bool
*/
public function exec(CommandSender $sender, array $args)
{
if (count($args) < 2 or !is_string($args[0]) or !is_string($args[1])) {
return false;
}
$clanName = Clannish::validateName($args[0], true);
$managerName = Clannish::validateName($sender->getName());
$memberName = Clannish::validateName($args[1]);
$clan = Clannish::getInstance()->getClan($clanName);
if ($clan === null) {
$this->sendMessage($sender, "clan-not-found", ["name" => $clanName]);
return true;
}
if (!($clan->getMember($managerName)->isManager() or $sender->hasPermission("clannish.operation"))) {
$this->sendMessage($sender, "clan-manager-only");
return true;
}
if (!$clan->isMember($memberName)) {
$this->sendMessage($sender, "clan-member-not-found", ["name" => $memberName]);
return true;
}
$clan->getManager()->setGrade(ClanMember::GRADE_STAFF);
$clan->getMember($memberName)->setGrade(ClanMember::GRADE_MANAGER);
$this->sendMessage($sender, "clan-manager-delegated", ["name" => $clanName, "member" => $memberName]);
return true;
}