13declare(strict_types=1);
15namespace pocketmine\network\mcpe\protocol;
21 public const NETWORK_ID = ProtocolInfo::TEXT_PACKET;
23 public const TYPE_RAW = 0;
24 public const TYPE_CHAT = 1;
25 public const TYPE_TRANSLATION = 2;
26 public const TYPE_POPUP = 3;
27 public const TYPE_JUKEBOX_POPUP = 4;
28 public const TYPE_TIP = 5;
29 public const TYPE_SYSTEM = 6;
30 public const TYPE_WHISPER = 7;
31 public const TYPE_ANNOUNCEMENT = 8;
32 public const TYPE_JSON_WHISPER = 9;
33 public const TYPE_JSON = 10;
34 public const TYPE_JSON_ANNOUNCEMENT = 11;
37 public bool $needsTranslation =
false;
38 public string $sourceName;
39 public string $message;
41 public array $parameters = [];
42 public string $xboxUserId =
"";
43 public string $platformChatId =
"";
44 public string $filteredMessage =
"";
46 private static function messageOnly(
int $type,
string $message) :
self{
48 $result->type = $type;
49 $result->message = $message;
56 private static function baseTranslation(
int $type,
string $key, array $parameters) :
self{
58 $result->type = $type;
59 $result->needsTranslation =
true;
60 $result->message = $key;
61 $result->parameters = $parameters;
65 public static function raw(
string $message) :
self{
66 return self::messageOnly(self::TYPE_RAW, $message);
72 public static function translation(
string $key, array $parameters = []) : self{
73 return self::baseTranslation(self::TYPE_TRANSLATION, $key, $parameters);
76 public static function popup(
string $message) : self{
77 return self::messageOnly(self::TYPE_POPUP, $message);
83 public static function translatedPopup(
string $key, array $parameters = []) : self{
84 return self::baseTranslation(self::TYPE_POPUP, $key, $parameters);
90 public static function jukeboxPopup(
string $key, array $parameters = []) : self{
91 return self::baseTranslation(self::TYPE_JUKEBOX_POPUP, $key, $parameters);
94 public static function tip(
string $message) : self{
95 return self::messageOnly(self::TYPE_TIP, $message);
99 $this->type = $in->getByte();
100 $this->needsTranslation = $in->
getBool();
102 case self::TYPE_CHAT:
103 case self::TYPE_WHISPER:
105 case self::TYPE_ANNOUNCEMENT:
109 case self::TYPE_SYSTEM:
110 case self::TYPE_JSON_WHISPER:
111 case self::TYPE_JSON:
112 case self::TYPE_JSON_ANNOUNCEMENT:
116 case self::TYPE_TRANSLATION:
117 case self::TYPE_POPUP:
118 case self::TYPE_JUKEBOX_POPUP:
121 for($i = 0; $i < $count; ++$i){
128 $this->platformChatId = $in->
getString();
129 $this->filteredMessage = $in->
getString();
133 $out->putByte($this->type);
134 $out->putBool($this->needsTranslation);
136 case self::TYPE_CHAT:
137 case self::TYPE_WHISPER:
139 case self::TYPE_ANNOUNCEMENT:
140 $out->putString($this->sourceName);
143 case self::TYPE_SYSTEM:
144 case self::TYPE_JSON_WHISPER:
145 case self::TYPE_JSON:
146 case self::TYPE_JSON_ANNOUNCEMENT:
147 $out->putString($this->message);
150 case self::TYPE_TRANSLATION:
151 case self::TYPE_POPUP:
152 case self::TYPE_JUKEBOX_POPUP:
153 $out->putString($this->message);
155 foreach($this->parameters as $p){
161 $out->putString($this->xboxUserId);
162 $out->putString($this->platformChatId);
163 $out->putString($this->filteredMessage);
167 return $handler->handleText($this);
decodePayload(PacketSerializer $in)
static translation(string $key, array $parameters=[])
static jukeboxPopup(string $key, array $parameters=[])
handle(PacketHandlerInterface $handler)
static translatedPopup(string $key, array $parameters=[])
encodePayload(PacketSerializer $out)
putUnsignedVarInt(int $v)