public function translate(TextContainer $c) { if ($c instanceof TranslationContainer) { $baseText = $this->internalGet($c->getText()); $baseText = $this->parseTranslation($baseText !== null ? $baseText : $c->getText()); foreach ($c->getParameters() as $i => $p) { $baseText = str_replace("{%{$i}}", $this->parseTranslation($p), $baseText); } } else { $baseText = $this->parseTranslation($c->getText()); } return $baseText; }
/** * Sends a direct chat message to a player * * @param string|TextContainer $message */ public function sendMessage($message) { if ($message instanceof TextContainer) { if ($message instanceof TranslationContainer) { $this->sendTranslation($message->getText(), $message->getParameters()); return; } $message = $message->getText(); } $mes = explode("\n", $this->server->getLanguage()->translateString($message)); foreach ($mes as $m) { if ($m !== "") { $pk = new TextPacket(); $pk->type = TextPacket::TYPE_RAW; $pk->message = $m; $this->dataPacket($pk); } } }
/** * Sends a direct chat message to a player * * @param string|TextContainer $message * @return bool */ public function sendMessage($message) { if ($message instanceof TextContainer) { if ($message instanceof TranslationContainer) { $this->sendTranslation($message->getText(), $message->getParameters()); return false; } $message = $message->getText(); } $mes = explode("\n", $this->server->getLanguage()->translateString($message)); foreach ($mes as $m) { if ($m !== "") { $this->server->getPluginManager()->callEvent($ev = new PlayerTextPreSendEvent($this, $m, PlayerTextPreSendEvent::MESSAGE)); if (!$ev->isCancelled()) { $pk = new TextPacket(); $pk->type = TextPacket::TYPE_RAW; $pk->message = $ev->getMessage(); $this->dataPacket($pk); } } } return true; }