PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
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
18
20 public const NETWORK_ID = ProtocolInfo::SET_TITLE_PACKET;
21
22 public const TYPE_CLEAR_TITLE = 0;
23 public const TYPE_RESET_TITLE = 1;
24 public const TYPE_SET_TITLE = 2;
25 public const TYPE_SET_SUBTITLE = 3;
26 public const TYPE_SET_ACTIONBAR_MESSAGE = 4;
27 public const TYPE_SET_ANIMATION_TIMES = 5;
28 public const TYPE_SET_TITLE_JSON = 6;
29 public const TYPE_SET_SUBTITLE_JSON = 7;
30 public const TYPE_SET_ACTIONBAR_MESSAGE_JSON = 8;
31
32 public int $type;
33 public string $text = "";
34 public int $fadeInTime = 0;
35 public int $stayTime = 0;
36 public int $fadeOutTime = 0;
37 public string $xuid = "";
38 public string $platformOnlineId = "";
39 public string $filteredTitleText = "";
40
44 public static function create(
45 int $type,
46 string $text,
47 int $fadeInTime,
48 int $stayTime,
49 int $fadeOutTime,
50 string $xuid,
51 string $platformOnlineId,
52 string $filteredTitleText,
53 ) : self{
54 $result = new self;
55 $result->type = $type;
56 $result->text = $text;
57 $result->fadeInTime = $fadeInTime;
58 $result->stayTime = $stayTime;
59 $result->fadeOutTime = $fadeOutTime;
60 $result->xuid = $xuid;
61 $result->platformOnlineId = $platformOnlineId;
62 $result->filteredTitleText = $filteredTitleText;
63 return $result;
64 }
65
66 protected function decodePayload(PacketSerializer $in) : void{
67 $this->type = $in->getVarInt();
68 $this->text = $in->getString();
69 $this->fadeInTime = $in->getVarInt();
70 $this->stayTime = $in->getVarInt();
71 $this->fadeOutTime = $in->getVarInt();
72 $this->xuid = $in->getString();
73 $this->platformOnlineId = $in->getString();
74 $this->filteredTitleText = $in->getString();
75 }
76
77 protected function encodePayload(PacketSerializer $out) : void{
78 $out->putVarInt($this->type);
79 $out->putString($this->text);
80 $out->putVarInt($this->fadeInTime);
81 $out->putVarInt($this->stayTime);
82 $out->putVarInt($this->fadeOutTime);
83 $out->putString($this->xuid);
84 $out->putString($this->platformOnlineId);
85 $out->putString($this->filteredTitleText);
86 }
87
88 public function handle(PacketHandlerInterface $handler) : bool{
89 return $handler->handleSetTitle($this);
90 }
91
92 private static function type(int $type) : self{
93 $result = new self;
94 $result->type = $type;
95 return $result;
96 }
97
98 private static function text(int $type, string $text) : self{
99 $result = self::type($type);
100 $result->text = $text;
101 return $result;
102 }
103
104 public static function title(string $text) : self{
105 return self::text(self::TYPE_SET_TITLE, $text);
106 }
107
108 public static function subtitle(string $text) : self{
109 return self::text(self::TYPE_SET_SUBTITLE, $text);
110 }
111
112 public static function actionBarMessage(string $text) : self{
113 return self::text(self::TYPE_SET_ACTIONBAR_MESSAGE, $text);
114 }
115
116 public static function clearTitle() : self{
117 return self::type(self::TYPE_CLEAR_TITLE);
118 }
119
120 public static function resetTitleOptions() : self{
121 return self::type(self::TYPE_RESET_TITLE);
122 }
123
124 public static function setAnimationTimes(int $fadeIn, int $stay, int $fadeOut) : self{
125 $result = self::type(self::TYPE_SET_ANIMATION_TIMES);
126 $result->fadeInTime = $fadeIn;
127 $result->stayTime = $stay;
128 $result->fadeOutTime = $fadeOut;
129 return $result;
130 }
131}
handle(PacketHandlerInterface $handler)
static create(int $type, string $text, int $fadeInTime, int $stayTime, int $fadeOutTime, string $xuid, string $platformOnlineId, string $filteredTitleText,)