本文整理汇总了PHP中pocketmine\utils\TextFormat::clean方法的典型用法代码示例。如果您正苦于以下问题:PHP TextFormat::clean方法的具体用法?PHP TextFormat::clean怎么用?PHP TextFormat::clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\utils\TextFormat
的用法示例。
在下文中一共展示了TextFormat::clean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: spawnTo
public function spawnTo(Player $player)
{
if ($player instanceof DesktopPlayer) {
if ($this !== $player and $this->spawned === true and $player->getLevel() === $this->getLevel() and $player->canSee($this)) {
$this->hasSpawned[$player->getID()] = $player;
$pk = new SpawnPlayerPacket();
if ($player->getRemoveFormat()) {
$pk->name = TextFormat::clean($this->nameTag);
} else {
$pk->name = $this->nameTag;
}
$pk->eid = $this->getID();
$pk->uuid = $this->bigBrother_formatedUUID;
$pk->x = $this->x;
$pk->z = $this->y;
$pk->y = $this->z;
$pk->yaw = $this->yaw;
$pk->pitch = $this->pitch;
$pk->item = $this->inventory->getItemInHand()->getID();
$pk->metadata = $this->getData();
$pk->data = $this->bigBrother_properties;
$player->putRawPacket($pk);
$pk = new EntityTeleportPacket();
$pk->eid = $this->getID();
$pk->x = $this->x;
$pk->z = $this->y;
$pk->y = $this->z;
$pk->yaw = $this->yaw;
$pk->pitch = $this->pitch;
$player->putRawPacket($pk);
$pk = new SetEntityMotionPacket();
$pk->eid = $this->getID();
$pk->speedX = $this->motionX;
$pk->speedY = $this->motionY;
$pk->speedZ = $this->motionZ;
$player->dataPacket($pk);
$this->inventory->sendHeldItem($player);
$this->inventory->sendArmorContents($player);
}
} else {
parent::spawnTo($player);
}
}
示例2: onPlayerTouch
public function onPlayerTouch(PlayerInteractEvent $event)
{
$player = $event->getPlayer();
$b = $event->getBlock();
$name = $event->getPlayer()->getName();
$name = strtolower($name);
if ($b->getID() === 63 || $b->getID() === 68) {
$sign = $player->getLevel()->getTile($b);
if (!$sign instanceof Sign) {
return;
}
$sign = $sign->getText();
if (TextFormat::clean($sign[0]) === '[Checkpoint]') {
$this->data->set($name, array($player->x, $player->y, $player->z, $player->getLevel()->getName()));
$this->data->save();
$player->sendMessage($this->getConfig()->get("CheckpointSaved"));
}
if (TextFormat::clean($sign[0]) === '[Earn Reward]') {
$this->data->remove($name, array($player->x, $player->y, $player->z, $player->getLevel()->getName()));
$this->data->save();
$player->sendMessage($this->getConfig()->get("EarnReward"));
if ($this->getConfig()->get("reward-command")) {
$player->getServer()->dispatchCommand(new ConsoleCommandSender(), str_ireplace("{PLAYER}", $player->getName(), $this->getConfig()->get("reward-command")));
$player->teleport($player->getLevel()->getSafeSpawn());
}
}
}
if ($b->getID() === $this->getConfig()->get("CheckPointBlock")) {
$this->data->set($name, array($player->x, $player->y, $player->z, $player->getLevel()->getName()));
$this->data->save();
$player->sendMessage($this->getConfig()->get("CheckpointSaved"));
}
}
示例3: check
public function check()
{
for ($n = 0; $n < $this->threads; ++$n) {
if ($this->workers[$n]->isTerminated() === true) {
$this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
} elseif ($this->workers[$n]->isWaiting()) {
if ($this->workers[$n]->response !== "") {
$this->server->getLogger()->info($this->workers[$n]->response);
$this->workers[$n]->synchronized(function (RCONInstance $thread) {
$thread->notify();
}, $this->workers[$n]);
} else {
$response = new RemoteConsoleCommandSender();
$command = $this->workers[$n]->cmd;
$this->server->getPluginManager()->callEvent($ev = new RemoteServerCommandEvent($response, $command));
if (!$ev->isCancelled()) {
$this->server->dispatchCommand($ev->getSender(), $ev->getCommand());
}
$this->workers[$n]->response = TextFormat::clean($response->getMessage());
$this->workers[$n]->synchronized(function (RCONInstance $thread) {
$thread->notify();
}, $this->workers[$n]);
}
}
}
}
示例4: onTelegramMessage
public function onTelegramMessage(TelegramMessageEvent $event)
{
if (!PocketTelegram::$broadcastTelegramMessages) {
return;
}
$message = $event->getMessage();
switch (true) {
case $message instanceof TextMessage:
if (PocketTelegram::$enableTelegramCommands and $message->isCommand()) {
$this->handleTelegramCommands($message);
return;
}
$text = $message->getText();
break;
case $message instanceof PhotoMessage:
$text = "(Photo)";
break;
default:
return;
}
if ($message->getChat()->getId() !== PocketTelegram::getDefaultChannel()) {
return;
}
if (is_null($from = $message->getFrom()) or is_null($username = $from->getUsername())) {
return;
}
$this->broadcastMessage(PocketTelegram::getInstance()->getConfig()->get("telegramUserPrefix", "@") . $username, TextFormat::clean($text));
}
示例5: onSignChange
public function onSignChange(SignChangeEvent $event)
{
if (strtolower(TextFormat::clean($event->getLine(0))) === "[advancedkits]" and !$event->getPlayer()->hasPermission("advancedkits.admin")) {
$event->getPlayer()->sendMessage($this->ak->langManager->getTranslation("no-perm-sign"));
$event->setCancelled();
}
}
示例6: onPostRelease
public function onPostRelease($rowId)
{
if ($this->src === "{BOT}CapsDetector" or $this->src === "{BOT}SwearDetector") {
return;
}
$message = implode("\n", ["{$this->src} @ `{$this->ip}:{$this->port}` executed /console. Message `#{$rowId}``:", MUtils::toMd($this->msg)]);
$isBot = substr($this->src, 0, 5) === "{BOT}";
$this->main->getServer()->getScheduler()->scheduleAsyncTask(new PostUrlTask(Credentials::SLACK_WEBHOOK, json_encode(["text" => TextFormat::clean($message), "icon_url" => Credentials::LEGIONPE_ICON_URL, "username" => $isBot ? substr($this->src, 5) : $this->src, "channel" => $isBot ? "#spam" : "#support"])));
}
示例7: replaceSymbols
/**
* Replaces all formatted color codes in the specified message, if revert is true, it will remove all text effects
* @param string $message
* @param bool $revert
* @return string
*/
public static function replaceSymbols($message, $revert = false)
{
$defaultFormat = [TextFormat::BLACK, TextFormat::DARK_BLUE, TextFormat::DARK_GREEN, TextFormat::DARK_AQUA, TextFormat::DARK_RED, TextFormat::DARK_PURPLE, TextFormat::GOLD, TextFormat::GRAY, TextFormat::DARK_GRAY, TextFormat::BLUE, TextFormat::GREEN, TextFormat::AQUA, TextFormat::RED, TextFormat::LIGHT_PURPLE, TextFormat::YELLOW, TextFormat::WHITE, TextFormat::OBFUSCATED, TextFormat::BOLD, TextFormat::STRIKETHROUGH, TextFormat::UNDERLINE, TextFormat::ITALIC, TextFormat::RESET];
$newFormat = ["&0", "&1", "&2", "&3", "&4", "&5", "&6", "&7", "&8", "&9", "&a", "&b", "&c", "&d", "&e", "&f", "&k", "&l", "&m", "&n", "&o", "&r"];
if ($revert) {
return TextFormat::clean($message);
} else {
return str_replace($newFormat, $defaultFormat, $message);
}
}
示例8: onQueryRegen
public function onQueryRegen(QueryRegenerateEvent $event)
{
$event->setWorld($this->main->query_world());
$this->main->getPlayersCount($total, $max, $classTotal, $classMax);
$event->setPlayerCount($classTotal);
$event->setMaxPlayerCount($classMax);
$event->setPlayerList([]);
$event->setServerName(TextFormat::clean($this->main->getServer()->getNetwork()->getName()));
$extra = $event->getExtraData();
$extra["class_numplayers"] = $classMax;
$extra["class_maxplayers"] = $classMax;
$this->addExtras($extra);
$event->setExtraData($extra);
}
示例9: onQueryRegen
public function onQueryRegen(QueryRegenerateEvent $event)
{
$event->setWorld($this->main->query_world());
$this->main->getPlayersCount($total, $max, $classTotal, $classMax);
$event->setPlayerCount($classTotal);
$event->setMaxPlayerCount($classMax);
$event->setPlayerList([]);
$event->setServerName(TextFormat::clean($this->main->getServer()->getNetwork()->getName()));
$extra = $event->getExtraData();
$name = strtolower(Settings::$CLASSES_NAMES[Settings::$LOCALIZE_CLASS]);
$extra[$name . "_numplayers"] = $classTotal;
$extra[$name . "_maxplayers"] = $classMax;
$this->addExtras($extra);
$event->setExtraData($extra);
}
示例10: onRun
public function onRun($currentTick)
{
foreach ($this->plugin->getServer()->getLevels() as $levels) {
foreach ($levels->getTiles() as $tiles) {
if ($tiles instanceof Sign) {
$text = $tiles->getText();
if (TextFormat::clean(strtolower(trim($text[0]))) === strtolower(trim($this->plugin->sign->get("sign_final_change")))) {
$world = $text[1];
$level = $this->plugin->getServer()->getLevelByName($world);
$players = count($level->getPlayers());
$tiles->setText($text[0] = TextFormat::GREEN . $this->plugin->sign->get("sign_final_change"), $text[2] = TextFormat::YELLOW . $players . " players");
}
}
}
}
}
示例11: onPlayerTouch
public function onPlayerTouch(PlayerInteractEvent $event)
{
$player = $event->getPlayer();
$b = $event->getBlock();
$name = $event->getPlayer()->getName();
$name = strtolower($name);
if ($b->getID() == 63 || $b->getID() == 68) {
$sign = $player->getLevel()->getTile($b);
if (!$sign instanceof Sign) {
return;
}
$sign = $sign->getText();
if (TextFormat::clean($sign[0]) === '[Checkpoint]') {
$this->config->set($name, array($player->x, $player->y, $player->z, $player->getLevel()->getName()));
$this->config->save();
$player->sendMessage("Saved");
} elseif (TextFormat::clean($sign[0]) === '[To Checkpoint]') {
$pos = $this->config->get($name);
if (is_array($pos)) {
if (count($pos) === 4) {
$player->sendMessage("Teleporting to Checkpoint...");
$level = $this->getServer()->getLevelByName($pos[3]);
if ($level) {
$player->teleport(new Position($pos[0], $pos[1], $pos[2], $level));
} else {
$player->sendMessage("Level is not loaded");
}
} else {
$player->sendMessage("Save Corrupted");
}
} else {
$player->sendMessage("No Save Found");
}
}
}
}
示例12: onSignChange
/**
* @param SignChangeEvent $event
*/
public function onSignChange(SignChangeEvent $event)
{
// Special Signs
// Free sign
if (strtolower(TextFormat::clean($event->getLine(0), true)) === "[free]" && $event->getPlayer()->hasPermission("essentials.sign.create.free")) {
if (trim($event->getLine(1)) !== "" || $event->getLine(1) !== null) {
$item_name = $event->getLine(1);
if (trim($event->getLine(2)) !== "" || $event->getLine(2) !== null) {
$damage = $event->getLine(2);
} else {
$damage = 0;
}
$item = $this->getAPI()->getItem($item_name . ":" . $damage);
if ($item->getID() === 0 || $item->getName() === "Air") {
$event->getPlayer()->sendMessage(TextFormat::RED . "[Error] Invalid item name/ID");
$event->setCancelled(true);
} else {
$event->getPlayer()->sendMessage(TextFormat::GREEN . "Free sign successfully created!");
$event->setLine(0, TextFormat::AQUA . "[Free]");
$event->setLine(1, $item->getName() === "Unknown" ? $item->getID() : $item->getName());
$event->setLine(2, $damage);
}
} else {
$event->getPlayer()->sendMessage(TextFormat::RED . "[Error] You should provide an item name/ID");
$event->setCancelled(true);
}
} elseif (strtolower(TextFormat::clean($event->getLine(0), true)) === "[gamemode]" && $event->getPlayer()->hasPermission("essentials.sign.create.gamemode")) {
switch (strtolower($event->getLine(1))) {
case "survival":
case "0":
$event->setLine(1, "Survival");
break;
case "creative":
case "1":
$event->setLine(1, "Creative");
break;
case "adventure":
case "2":
$event->setLine(1, "Adventure");
break;
case "spectator":
case "view":
case "3":
$event->setLine(1, "Spectator");
break;
default:
$event->getPlayer()->sendMessage(TextFormat::RED . "[Error] Unknown Gamemode, you should use \"Survival\", \"Creative\", \"Adventure\" or \"Spectator\"");
$event->setCancelled(true);
return;
break;
}
$event->getPlayer()->sendMessage(TextFormat::GREEN . "Gamemode sign successfully created!");
$event->setLine(0, TextFormat::AQUA . "[Gamemode]");
} elseif (strtolower(TextFormat::clean($event->getLine(0), true)) === "[heal]" && $event->getPlayer()->hasPermission("essentials.sign.create.heal")) {
$event->getPlayer()->sendMessage(TextFormat::GREEN . "Heal sign successfully created!");
$event->setLine(0, TextFormat::AQUA . "[Heal]");
} elseif (strtolower(TextFormat::clean($event->getLine(0), true)) === "[kit]" && $event->getPlayer()->hasPermission("essentials.sign.create.kit")) {
if (!$this->getAPI()->kitExists($event->getLine(1))) {
$event->getPlayer()->sendMessage(TextFormat::RED . "[Error] Kit doesn't exist");
return;
}
$event->getPlayer()->sendMessage(TextFormat::GREEN . "Kit sign successfully created!");
$event->setLine(0, TextFormat::AQUA . "[Kit]");
} elseif (strtolower(TextFormat::clean($event->getLine(0), true)) === "[repair]" && $event->getPlayer()->hasPermission("essentials.sign.create.repair")) {
switch (strtolower($event->getLine(1))) {
case "hand":
$event->setLine(1, "Hand");
break;
case "all":
$event->setLine(1, "All");
break;
default:
$event->getPlayer()->sendMessage(TextFormat::RED . "[Error] Invalid argument, you should use \"Hand\" or \"All\"");
$event->setCancelled(true);
return;
break;
}
$event->getPlayer()->sendMessage(TextFormat::GREEN . "Repair sign successfully created!");
$event->setLine(0, TextFormat::AQUA . "[Repair]");
} elseif (strtolower(TextFormat::clean($event->getLine(0), true)) === "[time]" && $event->getPlayer()->hasPermission("essentials.sign.create.time")) {
switch (strtolower($event->getLine(1))) {
case "day":
$event->setLine(1, "Day");
break;
case "night":
$event->setLine(1, "Night");
break;
default:
$event->getPlayer()->sendMessage(TextFormat::RED . "[Error] Invalid time, you should use \"Day\" or \"Night\"");
$event->setCancelled(true);
return;
break;
}
$event->getPlayer()->sendMessage(TextFormat::GREEN . "Time sign successfully created!");
$event->setLine(0, TextFormat::AQUA . "[Time]");
} elseif (strtolower(TextFormat::clean($event->getLine(0), true)) === "[teleport]" && $event->getPlayer()->hasPermission("essentials.sign.create.teleport")) {
if (!is_numeric($event->getLine(1))) {
//.........这里部分代码省略.........
示例13: getPlayer
public function getPlayer($player)
{
if (!$this->validateName($player, false)) {
return false;
}
$player = strtolower($player);
$found = false;
foreach ($this->getServer()->getOnlinePlayers() as $p) {
if (strtolower(TextFormat::clean($p->getDisplayName(), true)) === $player || strtolower($p->getName()) === $player) {
$found = $p;
break;
}
}
// If cannot get the exact player name/nick, try with portions of it
if (!$found) {
$found = ($f = $this->getServer()->getPlayer($player)) === null ? false : $f;
// PocketMine function to get from portions of name
}
/*
* Copy from PocketMine's function (use above xD) but modified to work with Nicknames :P
*
* ALL THE RIGHTS FROM THE FOLLOWING CODE BELONGS TO POCKETMINE-MP
*/
if (!$found) {
$delta = \PHP_INT_MAX;
foreach ($this->getServer()->getOnlinePlayers() as $p) {
// Clean the Display Name due to colored nicks :S
if (\stripos($n = TextFormat::clean($p->getDisplayName(), true), $player) === 0) {
$curDelta = \strlen($n) - \strlen($player);
if ($curDelta < $delta) {
$found = $p;
$delta = $curDelta;
}
if ($curDelta === 0) {
break;
}
}
}
}
return $found;
}
示例14: onInteract
public function onInteract(PlayerInteractEvent $event)
{
$player = $event->getPlayer();
$sign = $event->getPlayer()->getLevel()->getTile($event->getBlock());
if ($event->getBlock()->getId() == 63 or $event->getBlock()->getId() == 68) {
if ($sign instanceof Sign) {
$signtext = $sign->getText();
if (TextFormat::clean($signtext[0]) === "[DeadEnd]") {
$player->teleport(126.3, 5, 128.3, DeadEnd - lobby);
$player->sendMessage(TextFormat::GOLD . "You entered DeadEnd!");
}
}
}
}
示例15: handleDataPacket
/**
* Handles a Minecraft packet
* TODO: Separate all of this in handlers
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param DataPacket $packet
*/
public function handleDataPacket(DataPacket $packet)
{
if ($this->connected === false) {
return;
}
if ($packet->pid() === ProtocolInfo::BATCH_PACKET) {
/** @var BatchPacket $packet */
$this->server->getNetwork()->processBatch($packet, $this);
return;
}
$this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet));
if ($ev->isCancelled()) {
return;
}
switch ($packet->pid()) {
case ProtocolInfo::LOGIN_PACKET:
/*
* A/N: Not going to implement any session code until it actually does stuff.
* Single line functions are obnoxious to follow.
*/
if ($this->loggedIn === true) {
break;
}
$this->username = TextFormat::clean($packet->username);
$this->displayName = $this->username;
$this->setNameTag($this->username);
$this->iusername = strtolower($this->username);
$this->randomClientId = $packet->clientId;
$this->loginData = ["clientId" => $packet->clientId, "loginData" => null];
$this->uuid = $packet->clientUUID;
$this->rawUUID = $this->uuid->toBinary();
$this->clientSecret = $packet->clientSecret;
$this->protocol = $packet->protocol1;
if (count($this->server->getOnlinePlayers()) > $this->server->getMaxPlayers() and $this->kick("Server is full")) {
break;
}
if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) {
$message = "";
if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) {
$message = "Please update Minecraft PE to join.";
$pk = new PlayStatusPacket();
$pk->status = PlayStatusPacket::LOGIN_FAILED_CLIENT;
$this->dataPacket($pk);
} else {
$message = "Please use an older version of Minecraft PE.";
$pk = new PlayStatusPacket();
$pk->status = PlayStatusPacket::LOGIN_FAILED_SERVER;
$this->dataPacket($pk);
}
$this->close("", $message, false);
return;
}
if (strpos($packet->username, "") !== false or preg_match('#^[a-zA-Z0-9_]{3,16}$#', $packet->username) == 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console" or strlen($packet->username) > 16 or strlen($packet->username) < 3) {
$this->close("", "Please choose a valid username.");
return;
}
if (strlen($packet->skin) < 64 * 32 * 4) {
$this->close("", "Invalid skin.", false);
return;
}
$this->setSkin($packet->skin, $packet->slim);
$this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason"));
if ($ev->isCancelled()) {
$this->close("", $ev->getKickMessage());
return;
}
if (!$this->server->isWhitelisted(strtolower($this->getName()))) {
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "Server is private.");
return;
} elseif ($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress())) {
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "You have been banned.");
return;
}
if ($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)) {
$this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this);
}
if ($this->hasPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE)) {
$this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
}
foreach ($this->server->getOnlinePlayers() as $p) {
if ($p !== $this and strtolower($p->getName()) === strtolower($this->getName())) {
if ($p->kick("You connected from somewhere else.") === false) {
$this->close(TextFormat::YELLOW . $this->getName() . " has left the game", "You connected from somewhere else.");
return;
} else {
return;
}
}
}
$nbt = $this->server->getOfflinePlayerData($this->username);
if (!isset($nbt->NameTag)) {
//.........这里部分代码省略.........