mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 07:54:19 +00:00
Move translation flattening logic from Player to NetworkSession
this is network-specific stuff, so it doesn't belong in Player.
This commit is contained in:
parent
9c9929ff39
commit
b03733442b
@ -930,15 +930,22 @@ class NetworkSession{
|
||||
$this->sendDataPacket(AvailableCommandsPacket::create($commandData, [], [], []));
|
||||
}
|
||||
|
||||
public function onRawChatMessage(string $message) : void{
|
||||
$this->sendDataPacket(TextPacket::raw($message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $parameters
|
||||
*/
|
||||
public function onTranslatedChatMessage(string $key, array $parameters) : void{
|
||||
$this->sendDataPacket(TextPacket::translation($key, $parameters));
|
||||
public function onChatMessage(Translatable|string $message) : void{
|
||||
if($message instanceof Translatable){
|
||||
//we can't send nested translations to the client, so make sure they are always pre-translated by the server
|
||||
$language = $this->player->getLanguage();
|
||||
$parameters = array_map(fn(string|Translatable $p) => $p instanceof Translatable ? $language->translate($p) : $p, $message->getParameters());
|
||||
if(!$this->server->isLanguageForced()){
|
||||
foreach($parameters as $i => $p){
|
||||
$parameters[$i] = $language->translateString($p, [], "pocketmine.");
|
||||
}
|
||||
$this->sendDataPacket(TextPacket::translation($language->translateString($message->getText(), $parameters, "pocketmine."), $parameters));
|
||||
}else{
|
||||
$this->sendDataPacket(TextPacket::raw($language->translateString($message->getText(), $parameters)));
|
||||
}
|
||||
}else{
|
||||
$this->sendDataPacket(TextPacket::raw($message));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,7 +132,6 @@ use pocketmine\world\World;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
use function abs;
|
||||
use function array_filter;
|
||||
use function array_map;
|
||||
use function assert;
|
||||
use function count;
|
||||
use function explode;
|
||||
@ -1994,21 +1993,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
* Sends a direct chat message to a player
|
||||
*/
|
||||
public function sendMessage(Translatable|string $message) : void{
|
||||
if($message instanceof Translatable){
|
||||
//we can't send nested translations to the client, so make sure they are always pre-translated by the server
|
||||
$parameters = array_map(fn(string|Translatable $p) => $p instanceof Translatable ? $this->getLanguage()->translate($p) : $p, $message->getParameters());
|
||||
if(!$this->server->isLanguageForced()){
|
||||
foreach($parameters as $i => $p){
|
||||
$parameters[$i] = $this->getLanguage()->translateString($p, [], "pocketmine.");
|
||||
}
|
||||
$this->getNetworkSession()->onTranslatedChatMessage($this->getLanguage()->translateString($message->getText(), $parameters, "pocketmine."), $parameters);
|
||||
}else{
|
||||
$this->getNetworkSession()->onRawChatMessage($this->getLanguage()->translateString($message->getText(), $parameters));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$this->getNetworkSession()->onRawChatMessage($message);
|
||||
$this->getNetworkSession()->onChatMessage($message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user