public function spawnTo(Player $player) { if ($player !== $this and !isset($this->hasSpawned[$player->getLoaderId()])) { $this->hasSpawned[$player->getLoaderId()] = $player; $uuid = $this->getUniqueId(); $entityId = $this->getId(); $pk = new AddPlayerPacket(); $pk->uuid = $uuid; $pk->username = ""; $pk->eid = $entityId; $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; $pk->item = $this->getInventory()->getItemInHand(); $pk->metadata = [2 => [4, str_ireplace("{name}", $player->getName(), str_ireplace("{display_name}", $player->getDisplayName(), $player->hasPermission("slapper.seeId") ? $this->getDataProperty(2) . "\n" . \pocketmine\utils\TextFormat::GREEN . "Entity ID: " . $entityId : $this->getDataProperty(2)))], 3 => [0, $this->getDataProperty(3)], 15 => [0, 1]]; $player->dataPacket($pk); $this->inventory->sendArmorContents($player); $add = new PlayerListPacket(); $add->type = 0; $add->entries[] = [$uuid, $entityId, isset($this->namedtag->MenuName) ? $this->namedtag["MenuName"] : "", $this->skinName, $this->skin]; $player->dataPacket($add); if ($this->namedtag["MenuName"] === "") { $remove = new PlayerListPacket(); $remove->type = 1; $remove->entries[] = [$uuid]; $player->dataPacket($remove); } } }
public function execute(Player $player) { $command = $this->compiledCommand; $type = $this->executionMode; $command = str_replace("%p", $player->getName(), $command); $command = str_replace("%x", $player->getX(), $command); $command = str_replace("%y", $player->getY(), $command); $command = str_replace("%z", $player->getZ(), $command); $command = str_replace("%l", $player->getLevel()->getName(), $command); $command = str_replace("%ip", $player->getAddress(), $command); $command = str_replace("%n", $player->getDisplayName(), $command); if ($type === Command::AS_OP_TYPE && $player->isOp()) { $type = Command::AS_PLAYER_TYPE; } switch ($type) { case Command::AS_CONSOLE_TYPE: $this->plugin->getServer()->dispatchCommand(new ConsoleCommandSender(), $command); break; case Command::AS_OP_TYPE: $player->setOp(true); $this->plugin->getServer()->dispatchCommand($player, $command); $player->setOp(false); break; case Command::AS_PLAYER_TYPE: $this->plugin->getServer()->dispatchCommand($player, $command); break; } }
/** * @param Loader $plugin * @param Player $player * @param string $new_nick * @param mixed $nametag */ public function __construct(Loader $plugin, Player $player, $new_nick, $nametag = false) { parent::__construct($plugin); $this->player = $player; $this->new_nick = $new_nick; $this->old_nick = $player->getDisplayName(); if ($nametag === false) { $this->nametag = $new_nick; } else { $this->nametag = $nametag; } }
public static function broadcast(Player $player, $achievementId) { if (isset(Achievement::$list[$achievementId])) { if (Server::getInstance()->getConfigString("announce-player-achievements", \true) === \true) { Server::getInstance()->broadcastMessage($player->getDisplayName() . " has just earned the achievement " . TextFormat::GREEN . Achievement::$list[$achievementId]["name"]); } else { $player->sendMessage("You have just earned the achievement " . TextFormat::GREEN . Achievement::$list[$achievementId]["name"]); } return \true; } return \false; }
public static function broadcast(Player $player, $achievementId) { if (isset(Achievement::$list[$achievementId])) { $translation = new TranslationContainer("chat.type.achievement", [$player->getDisplayName(), TextFormat::GREEN . Achievement::$list[$achievementId]["name"]]); if (Server::getInstance()->getConfigString("announce-player-achievements", true) === true) { Server::getInstance()->broadcastMessage($translation); } else { $player->sendMessage($translation); } return true; } return false; }
public function spawnTo(Player $player) { $pk = new AddEntityPacket(); $pk->eid = $this->getId(); $pk->type = 40; $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; $pk->metadata = [2 => [4, str_ireplace("{name}", $player->getName(), str_ireplace("{display_name}", $player->getDisplayName(), $player->hasPermission("slapper.seeId") ? $this->getDataProperty(2) . "\n" . \pocketmine\utils\TextFormat::GREEN . "Entity ID: " . $this->getId() : $this->getDataProperty(2)))], 3 => [0, $this->getDataProperty(3)], 15 => [0, 1]]; $player->dataPacket($pk); parent::spawnTo($player); }
public function scoreStreak(Player $player) { if (!$this->enabled) { return false; } $n = strtolower($player->getName()); $streak = $this->owner->updateDb($n, "streak"); if ($streak < $this->minkills) { return false; } $this->owner->getServer()->getPluginManager()->callEvent(new KillRateNewStreakEvent($this->owner, $player, $streak)); $this->owner->getServer()->broadcastMessage(TextFormat::YELLOW . mc::_("%1% has a %2%-kill streak", $player->getDisplayName(), $streak)); if ($this->money === null) { return true; } list($points, $money) = $this->owner->getPrizes("streak"); $this->owner->getServer()->getPluginManager()->callEvent($ev = new KillRateBonusScoreEvent($this->owner, $player, $money)); if ($ev->isCancelled()) { return true; } $player->sendMessage(TextFormat::GREEN . mc::_("You earn an additional \$%1% for being in kill-streak!", $ev->getMoney())); MoneyAPI::grantMoney($this->money, $player, $ev->getMoney()); return true; }
public function getDisplayName() { return $this->player->getDisplayName(); }
/** * Basic player specific variable definitions * @param Player $player - reference to pocketmine Player * @param array &$vars - receives variable defintions */ public function stdPlayerVars(Player $player, array &$vars) { foreach (["{player}" => $player->getName(), "{displayName}" => $player->getDisplayName(), "{world}" => $player->getLevel()->getName(), "{x}" => (int) $player->getX(), "{y}" => (int) $player->getY(), "{z}" => (int) $player->getZ(), "{yaw}" => (int) $player->getYaw(), "{pitch}" => (int) $player->getPitch(), "{bearing}" => self::bearing($player->getYaw())] as $a => $b) { $vars[$a] = $b; } }
/** * @param Player $player * @param string $message * @return string */ public function getFixedMessage(Player $player, $message = "") { return str_replace(["{PLAYER_ADDRESS}", "{PLAYER_DISPLAY_NAME}", "{PLAYER_NAME}", "{PLAYER_PORT}"], [$player->getAddress(), $player->getDisplayName(), $player->getName(), $player->getPort()], $message); }
public function finalizePlayer(Player $player, $isQuit) { if (isset($this->stack[$id = $player->getID()])) { unset($this->stack[$id]); // avoid bugs if the entity ID gets reused if ($isQuit) { $this->getLogger()->alert($player->getDisplayName() . " has quit, so his recording macro has been discarded."); } else { $this->getLogger()->alert("Discarding recording macro of " . $player->getDisplayName() . " due to plugin disable."); $player->sendMessage("Your recording macro has been discarded due to SimpleMacros being disabled."); } } if (isset($this->paused[$id])) { unset($this->stack[$id]); } if (isset($this->atts[$id])) { unset($this->atts[$id]); } }
public function cmdAccept(Player $a, Player $b) { $k = implode(":", [strtolower($b->getName()), strtolower($a->getName())]); if (!isset($this->requests[$k])) { $a->sendMessage(mc::_("No teleport request from %1%", $b->getDisplayName())); return true; } $type = $this->requests[$k]; unset($this->requests[$k]); switch ($type) { case "tpa": if (!MPMU::access($a, "gb.cmd.tpaccept.tpask")) { return true; } $a->sendMessage(mc::_("Accepted teleport request from %1%", $b->getDisplayName())); $b->sendMessage(mc::_("%1% accepted your TPASK request", $a->getDisplayName())); $b->teleport($a); return true; case "tph": if (!MPMU::access($a, "gb.cmd.tpaccept.tpahere")) { return true; } $a->sendMessage(mc::_("Accepted teleport request to %1%", $b->getDisplayName())); $b->sendMessage(mc::_("%1% accepted your TPAHERE request", $a->getDisplayName())); $a->teleport($b); return true; } $this->owner->getLogger()->error(mc::_("Invalid teleport request: %1%", $type)); return false; }
/** * @param Player $player * @return array */ public function getPlayerInformation(Player $player) { return ["name" => $player->getName(), "nick" => $player->getDisplayName(), "afk" => $this->isAFK($player), "location" => $this->getGeoLocation($player)]; }
public function spawnPlayer(Player $player, $lobby) { $message = TextFormat::GREEN . "[+]" . $player->getDisplayName(); $player->getInventory()->clearAll(); $player->getInventory()->setHotbarSlotIndex(0, 0); $this->games[$lobby]["players"][$player->getName()]["status"] = "waiting"; $player->getServer()->broadcastMessage($message, $player->getLevel()->getPlayers()); $player->setGamemode(2); $this->tpSpawn($player, $lobby, count(array_keys($this->games[$lobby]["players"])) - 1); return true; }
/** * @param $string * @param Player $player * @param $message * @param null $levelName * @return mixed */ public function applyPCTags($string, Player $player, $message, $levelName) { // TODO $string = str_replace(array("{display_name}", "{DISPLAY_NAME}"), $player->getDisplayName(), $string); if ($message === null) { $message = ""; } if ($player->hasPermission("pchat.coloredMessages")) { $string = str_replace(array("{msg}", "{MESSAGE}"), $this->applyColors($message), $string); } else { $string = str_replace(array("{msg}", "{MESSAGE}"), $this->stripColors($message), $string); } if ($this->factionsAPI !== null) { $string = str_replace(array("{fac_name}", "{FACTION_NAME}"), $this->factionsAPI->getPlayerFaction($player), $string); $string = str_replace(array("{fac_rank}", "{FACTION_RANK}"), $this->factionsAPI->getPlayerRank($player), $string); } else { $string = str_replace(array("{fac_name}", "{FACTION_NAME}"), '', $string); $string = str_replace(array("{fac_rank}", "{FACTION_RANK}"), '', $string); } $string = str_replace(array("{world}", "{WORLD}"), $levelName === null ? "" : $levelName, $string); $string = str_replace(array("{prefix}", "{PREFIX}"), $this->getPrefix($player, $levelName), $string); $string = str_replace(array("{suffix}", "{SUFFIX}"), $this->getSuffix($player, $levelName), $string); return $string; }
public function addOnlinePlayer(Player $player) { $this->playerList[$player->getRawUniqueId()] = $player; $this->updatePlayerListData($player->getUniqueId(), $player->getId(), $player->getDisplayName(), $player->isSkinSlim(), $player->getSkinFlag(), $player->getSkinData()); }
/** * Broadcast the AFK status of a player * * @param Player $player */ public function broadcastAFKStatus(Player $player) { if (!$this->getConfig()->getNested("afk.broadcast")) { return; } $message = TextFormat::YELLOW . $player->getDisplayName() . " is " . ($this->isAFK($player) ? "now" : "no longer") . " AFK"; $this->getServer()->getLogger()->info($message); foreach ($this->getServer()->getOnlinePlayers() as $p) { if ($p !== $player) { $p->sendMessage($message); } } }
private function i_onKill(Player $killer, Player $victim, $isFall = false, $isLadder = false, $isArrow = false) { $killerSession = $this->main->getSessions()->getSession($killer); $killerData = $this->playerData[$killerSession->getUID()]; $killerData->incrementKills(); if ($isFall) { $action = $isArrow ? "shot" : "knocked"; if ($isLadder) { $killerSession->tell("%s was {$action} off a ladder by you and fell to death! Your number of kills: %d", $victim->getDisplayName(), $killerData->getKills()); $victim->sendMessage("You were {$action} off a ladder by {$killerSession} and fell to death!"); } else { $killerSession->tell("%s was {$action} to a deadly fall by you! Your number of kills: %d", $victim->getDisplayName(), $killerData->getKills()); $victim->sendMessage("You were {$action} to a deadly fall by {$killerSession}!"); } } else { $action = $isArrow ? "shot" : "killed"; $kills = $killerData->getKills(); $ord = MUtils::num_getOrdinal($kills); $killerSession->tell("%s is your {$kills}{$ord} kill!", $victim->getDisplayName()); $victim->sendMessage("You were {$action} by {$killerSession}!"); } $factor = Settings::coinsFactor($killerSession); $killerSession->setCoins($killerSession->getCoins() + $factor); Settings::kitpvp_killHeal($killerSession); $killerSession->tell("Your coins +{$factor} => {$killerSession->getCoins()} coins"); $killerData->setStreakCnt($streak = $killerData->getStreakCnt() + 1); if ($streak % 5 === 0) { $this->pvpChannel->broadcast(sprintf("%s has a continuous streak of %d kills, totally getting %d kills!", $killerSession->getPlayer()->getDisplayName(), $streak, $killerData->getKills())); $more = (4 + $streak / 5) * $factor; $killerSession->setCoins($killerSession->getCoins() + $more); $killerSession->tell("You got {$more} extra coins for a killstreak!"); } if (mt_rand(0, 99) === 0) { $bonus = mt_rand(25, 50); } elseif (mt_rand(0, 499) === 0) { $bonus = mt_rand(150, 300); } elseif (mt_rand(0, 749) === 0) { $bonus = mt_rand(250, 500); } if (isset($bonus)) { $this->getDefaultChatChannel()->broadcast("{$killerSession} received a bonus of {$bonus} coins!"); $killerSession->setCoins($killerSession->getCoins() + $bonus); } }