PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
LessonProgressPacket.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
26 public const NETWORK_ID = ProtocolInfo::LESSON_PROGRESS_PACKET;
27
28 public const ACTION_START = 0;
29 public const ACTION_FINISH = 1;
30 public const ACTION_RESTART = 2;
31
32 private int $action;
33 private int $score;
34 private string $activityId;
35
39 public static function create(int $action, int $score, string $activityId) : self{
40 $result = new self;
41 $result->action = $action;
42 $result->score = $score;
43 $result->activityId = $activityId;
44 return $result;
45 }
46
47 public function getAction() : int{ return $this->action; }
48
49 public function getScore() : int{ return $this->score; }
50
51 public function getActivityId() : string{ return $this->activityId; }
52
53 protected function decodePayload(ByteBufferReader $in) : void{
54 $this->action = VarInt::readSignedInt($in);
55 $this->score = VarInt::readSignedInt($in);
56 $this->activityId = CommonTypes::getString($in);
57 }
58
59 protected function encodePayload(ByteBufferWriter $out) : void{
60 VarInt::writeSignedInt($out, $this->action);
61 VarInt::writeSignedInt($out, $this->score);
62 CommonTypes::putString($out, $this->activityId);
63 }
64
65 public function handle(PacketHandlerInterface $handler) : bool{
66 return $handler->handleLessonProgress($this);
67 }
68}
static create(int $action, int $score, string $activityId)