Skip to content

Commit 571cabf

Browse files
committed
Avoid encode-level hacks for TextPacket
we don't want to break packet encode/decode symmetry testability. Putting it in the static constructor should avoid most side effects. It's not ideal, but the alternative is forcing every place that might have given empty strings to check manually, which would take a lot more work.
1 parent e6aa220 commit 571cabf

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/TextPacket.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ class TextPacket extends DataPacket implements ClientboundPacket, ServerboundPac
7575
private static function messageOnly(int $type, string $message) : self{
7676
$result = new self;
7777
$result->type = $type;
78-
$result->message = $message;
78+
//TODO: HACK! Empty message crashes or bugs out client in 1.21.130
79+
$result->message = $message === "" ? " " : $message;
7980
return $result;
8081
}
8182

@@ -86,7 +87,8 @@ private static function baseTranslation(int $type, string $key, array $parameter
8687
$result = new self;
8788
$result->type = $type;
8889
$result->needsTranslation = true;
89-
$result->message = $key;
90+
//TODO: HACK! Empty message crashes or bugs out client in 1.21.130
91+
$result->message = $key === "" ? " " : $key;
9092
$result->parameters = $parameters;
9193
return $result;
9294
}
@@ -210,20 +212,20 @@ protected function encodePayload(ByteBufferWriter $out) : void{
210212
case self::TYPE_WHISPER:
211213
/** @noinspection PhpMissingBreakStatementInspection */
212214
case self::TYPE_ANNOUNCEMENT:
213-
CommonTypes::putString($out, $this->sourceName === '' ? ' ' : $this->sourceName);
215+
CommonTypes::putString($out, $this->sourceName);
214216
case self::TYPE_RAW:
215217
case self::TYPE_TIP:
216218
case self::TYPE_SYSTEM:
217219
case self::TYPE_JSON_WHISPER:
218220
case self::TYPE_JSON:
219221
case self::TYPE_JSON_ANNOUNCEMENT:
220-
CommonTypes::putString($out, $this->message === '' ? ' ' : $this->message);
222+
CommonTypes::putString($out, $this->message);
221223
break;
222224

223225
case self::TYPE_TRANSLATION:
224226
case self::TYPE_POPUP:
225227
case self::TYPE_JUKEBOX_POPUP:
226-
CommonTypes::putString($out, $this->message === '' ? ' ' : $this->message);
228+
CommonTypes::putString($out, $this->message);
227229
VarInt::writeUnsignedInt($out, count($this->parameters));
228230
foreach($this->parameters as $p){
229231
CommonTypes::putString($out, $p);

0 commit comments

Comments
 (0)