From de052a79de1f603b47dec80477535e6e69859796 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 11 Apr 2015 02:31:34 +0200 Subject: [PATCH] Localized kick messages --- src/pocketmine/Achievement.php | 6 ++++-- src/pocketmine/Player.php | 27 +++++++++++++++++++++------ src/pocketmine/lang/base/en.ini | 7 +++++++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/Achievement.php b/src/pocketmine/Achievement.php index eb5fc537d..a7a11f003 100644 --- a/src/pocketmine/Achievement.php +++ b/src/pocketmine/Achievement.php @@ -21,6 +21,7 @@ namespace pocketmine; +use pocketmine\event\TranslationContainer; use pocketmine\utils\TextFormat; /** @@ -106,10 +107,11 @@ abstract class Achievement{ 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($player->getDisplayName() . " has just earned the achievement " . TextFormat::GREEN . Achievement::$list[$achievementId]["name"]); + Server::getInstance()->broadcastMessage($translation); }else{ - $player->sendMessage("You have just earned the achievement " . TextFormat::GREEN . Achievement::$list[$achievementId]["name"]); + $player->sendMessage($translation); } return true; diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 5a3848bc3..6c9ae2e96 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1355,20 +1355,26 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->randomClientId = $packet->clientId; $this->loginData = ["clientId" => $packet->clientId, "loginData" => null]; - if(count($this->server->getOnlinePlayers()) > $this->server->getMaxPlayers() and $this->kick("server full")){ + if(count($this->server->getOnlinePlayers()) > $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)){ return; } + if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){ + $message = ""; if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){ + $message = "disconnectionScreen.outdatedClient"; + $pk = new PlayStatusPacket(); $pk->status = PlayStatusPacket::LOGIN_FAILED_CLIENT; $this->dataPacket($pk); }else{ + $message = "disconnectionScreen.outdatedServer"; + $pk = new PlayStatusPacket(); $pk->status = PlayStatusPacket::LOGIN_FAILED_SERVER; $this->dataPacket($pk); } - $this->close("", "Incorrect protocol #" . $packet->protocol1, false); + $this->close("", $message, false); return; } @@ -1380,7 +1386,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } if(strlen($packet->skin) < 64 * 32 * 4){ - $this->close("", "Invalid skin", false); + $this->close("", "disconnectionScreen.invalidSkin", false); return; } @@ -2381,13 +2387,22 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ * Kicks a player from the server * * @param string $reason + * @param bool $isAdmin * * @return bool */ - public function kick($reason = ""){ + public function kick($reason = "", $isAdmin = true){ $this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, $this->getLeaveMessage())); if(!$ev->isCancelled()){ - $message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : ""); + if($isAdmin){ + $message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : ""); + }else{ + if($reason === ""){ + $message = "disconnectionScreen.noReason"; + }else{ + $message = $reason; + } + } $this->close($ev->getQuitMessage(), $message); return true; @@ -2492,7 +2507,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this); $this->spawned = false; - $this->server->getLogger()->info(TextFormat::AQUA . $this->username . TextFormat::WHITE . "[/" . $this->ip . ":" . $this->port . "] logged out due to " . str_replace(["\n", "\r"], [" ", ""], $reason)); + $this->server->getLogger()->info(TextFormat::AQUA . $this->getName() . TextFormat::WHITE . "[/" . $this->ip . ":" . $this->port . "] logged out due to " . str_replace(["\n", "\r"], [" ", ""], $this->getServer()->getLanguage()->translateString($reason))); $this->windows = new \SplObjectStorage(); $this->windowIndex = []; $this->usedChunks = []; diff --git a/src/pocketmine/lang/base/en.ini b/src/pocketmine/lang/base/en.ini index 3bec0c5ac..8a51b86a6 100644 --- a/src/pocketmine/lang/base/en.ini +++ b/src/pocketmine/lang/base/en.ini @@ -14,6 +14,13 @@ chat.type.announcement=[{%0}] {%1} chat.type.admin=[{%0}: {%1}] chat.type.achievement={%0} has just earned the achievement {%1} +disconnectionScreen.outdatedClient=Outdated client! +disconnectionScreen.outdatedServer=Outdated server! +disconnectionScreen.serverFull=Server is full! +disconnectionScreen.noReason=Disconnected from server +disconnectionScreen.invalidSkin=Invalid skin! + + death.fell.accident.generic={%0} fell from a high place death.attack.inFire={%0} went up in flames