mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-22 19:06:35 +00:00
Player: break cycle between sendMessage() and sendTranslation()
This commit is contained in:
parent
566a8a261f
commit
9c9929ff39
@ -1995,7 +1995,16 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
*/
|
*/
|
||||||
public function sendMessage(Translatable|string $message) : void{
|
public function sendMessage(Translatable|string $message) : void{
|
||||||
if($message instanceof Translatable){
|
if($message instanceof Translatable){
|
||||||
$this->sendTranslation($message->getText(), $message->getParameters());
|
//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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2007,16 +2016,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
* @param string[]|Translatable[] $parameters
|
* @param string[]|Translatable[] $parameters
|
||||||
*/
|
*/
|
||||||
public function sendTranslation(string $message, array $parameters = []) : void{
|
public function sendTranslation(string $message, array $parameters = []) : void{
|
||||||
//we can't send nested translations to the client, so make sure they are always pre-translated by the server
|
$this->sendMessage(new Translatable($message, $parameters));
|
||||||
$parameters = array_map(fn(string|Translatable $p) => $p instanceof Translatable ? $this->getLanguage()->translate($p) : $p, $parameters);
|
|
||||||
if(!$this->server->isLanguageForced()){
|
|
||||||
foreach($parameters as $i => $p){
|
|
||||||
$parameters[$i] = $this->getLanguage()->translateString($p, [], "pocketmine.");
|
|
||||||
}
|
|
||||||
$this->getNetworkSession()->onTranslatedChatMessage($this->getLanguage()->translateString($message, $parameters, "pocketmine."), $parameters);
|
|
||||||
}else{
|
|
||||||
$this->sendMessage($this->getLanguage()->translateString($message, $parameters));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user