PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
SetTitlePacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
21
23 public const NETWORK_ID = ProtocolInfo::SET_TITLE_PACKET;
24
25 public const TYPE_CLEAR_TITLE = 0;
26 public const TYPE_RESET_TITLE = 1;
27 public const TYPE_SET_TITLE = 2;
28 public const TYPE_SET_SUBTITLE = 3;
29 public const TYPE_SET_ACTIONBAR_MESSAGE = 4;
30 public const TYPE_SET_ANIMATION_TIMES = 5;
31 public const TYPE_SET_TITLE_JSON = 6;
32 public const TYPE_SET_SUBTITLE_JSON = 7;
33 public const TYPE_SET_ACTIONBAR_MESSAGE_JSON = 8;
34
35 public int $type;
36 public string $text = "";
37 public int $fadeInTime = 0;
38 public int $stayTime = 0;
39 public int $fadeOutTime = 0;
40 public string $xuid = "";
41 public string $platformOnlineId = "";
42 public string $filteredTitleText = "";
43
47 public static function create(
48 int $type,
49 string $text,
50 int $fadeInTime,
51 int $stayTime,
52 int $fadeOutTime,
53 string $xuid,
54 string $platformOnlineId,
55 string $filteredTitleText,
56 ) : self{
57 $result = new self;
58 $result->type = $type;
59 $result->text = $text;
60 $result->fadeInTime = $fadeInTime;
61 $result->stayTime = $stayTime;
62 $result->fadeOutTime = $fadeOutTime;
63 $result->xuid = $xuid;
64 $result->platformOnlineId = $platformOnlineId;
65 $result->filteredTitleText = $filteredTitleText;
66 return $result;
67 }
68
69 protected function decodePayload(ByteBufferReader $in) : void{
70 $this->type = VarInt::readSignedInt($in);
71 $this->text = CommonTypes::getString($in);
72 $this->fadeInTime = VarInt::readSignedInt($in);
73 $this->stayTime = VarInt::readSignedInt($in);
74 $this->fadeOutTime = VarInt::readSignedInt($in);
75 $this->xuid = CommonTypes::getString($in);
76 $this->platformOnlineId = CommonTypes::getString($in);
77 $this->filteredTitleText = CommonTypes::getString($in);
78 }
79
80 protected function encodePayload(ByteBufferWriter $out) : void{
81 VarInt::writeSignedInt($out, $this->type);
82 CommonTypes::putString($out, $this->text);
83 VarInt::writeSignedInt($out, $this->fadeInTime);
84 VarInt::writeSignedInt($out, $this->stayTime);
85 VarInt::writeSignedInt($out, $this->fadeOutTime);
86 CommonTypes::putString($out, $this->xuid);
87 CommonTypes::putString($out, $this->platformOnlineId);
88 CommonTypes::putString($out, $this->filteredTitleText);
89 }
90
91 public function handle(PacketHandlerInterface $handler) : bool{
92 return $handler->handleSetTitle($this);
93 }
94
95 private static function type(int $type) : self{
96 $result = new self;
97 $result->type = $type;
98 return $result;
99 }
100
101 private static function text(int $type, string $text) : self{
102 $result = self::type($type);
103 $result->text = $text;
104 return $result;
105 }
106
107 public static function title(string $text) : self{
108 return self::text(self::TYPE_SET_TITLE, $text);
109 }
110
111 public static function subtitle(string $text) : self{
112 return self::text(self::TYPE_SET_SUBTITLE, $text);
113 }
114
115 public static function actionBarMessage(string $text) : self{
116 return self::text(self::TYPE_SET_ACTIONBAR_MESSAGE, $text);
117 }
118
119 public static function clearTitle() : self{
120 return self::type(self::TYPE_CLEAR_TITLE);
121 }
122
123 public static function resetTitleOptions() : self{
124 return self::type(self::TYPE_RESET_TITLE);
125 }
126
127 public static function setAnimationTimes(int $fadeIn, int $stay, int $fadeOut) : self{
128 $result = self::type(self::TYPE_SET_ANIMATION_TIMES);
129 $result->fadeInTime = $fadeIn;
130 $result->stayTime = $stay;
131 $result->fadeOutTime = $fadeOut;
132 return $result;
133 }
134}
handle(PacketHandlerInterface $handler)
static create(int $type, string $text, int $fadeInTime, int $stayTime, int $fadeOutTime, string $xuid, string $platformOnlineId, string $filteredTitleText,)