PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
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
43 public static function create(
44 int $type,
45 string $text,
46 int $fadeInTime,
47 int $stayTime,
48 int $fadeOutTime,
49 string $xuid,
50 string $platformOnlineId,
51 ) : self{
52 $result = new self;
53 $result->type = $type;
54 $result->text = $text;
55 $result->fadeInTime = $fadeInTime;
56 $result->stayTime = $stayTime;
57 $result->fadeOutTime = $fadeOutTime;
58 $result->xuid = $xuid;
59 $result->platformOnlineId = $platformOnlineId;
60 return $result;
61 }
62
63 protected function decodePayload(PacketSerializer $in) : void{
64 $this->type = $in->getVarInt();
65 $this->text = $in->getString();
66 $this->fadeInTime = $in->getVarInt();
67 $this->stayTime = $in->getVarInt();
68 $this->fadeOutTime = $in->getVarInt();
69 $this->xuid = $in->getString();
70 $this->platformOnlineId = $in->getString();
71 }
72
73 protected function encodePayload(PacketSerializer $out) : void{
74 $out->putVarInt($this->type);
75 $out->putString($this->text);
76 $out->putVarInt($this->fadeInTime);
77 $out->putVarInt($this->stayTime);
78 $out->putVarInt($this->fadeOutTime);
79 $out->putString($this->xuid);
80 $out->putString($this->platformOnlineId);
81 }
82
83 public function handle(PacketHandlerInterface $handler) : bool{
84 return $handler->handleSetTitle($this);
85 }
86
87 private static function type(int $type) : self{
88 $result = new self;
89 $result->type = $type;
90 return $result;
91 }
92
93 private static function text(int $type, string $text) : self{
94 $result = self::type($type);
95 $result->text = $text;
96 return $result;
97 }
98
99 public static function title(string $text) : self{
100 return self::text(self::TYPE_SET_TITLE, $text);
101 }
102
103 public static function subtitle(string $text) : self{
104 return self::text(self::TYPE_SET_SUBTITLE, $text);
105 }
106
107 public static function actionBarMessage(string $text) : self{
108 return self::text(self::TYPE_SET_ACTIONBAR_MESSAGE, $text);
109 }
110
111 public static function clearTitle() : self{
112 return self::type(self::TYPE_CLEAR_TITLE);
113 }
114
115 public static function resetTitleOptions() : self{
116 return self::type(self::TYPE_RESET_TITLE);
117 }
118
119 public static function setAnimationTimes(int $fadeIn, int $stay, int $fadeOut) : self{
120 $result = self::type(self::TYPE_SET_ANIMATION_TIMES);
121 $result->fadeInTime = $fadeIn;
122 $result->stayTime = $stay;
123 $result->fadeOutTime = $fadeOut;
124 return $result;
125 }
126}
handle(PacketHandlerInterface $handler)
static create(int $type, string $text, int $fadeInTime, int $stayTime, int $fadeOutTime, string $xuid, string $platformOnlineId,)