PocketMine-MP 5.17.1 git-df4ada81e5d74a14046f27cf44a37dcee69d657e
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
18
23 public const NETWORK_ID = ProtocolInfo::LESSON_PROGRESS_PACKET;
24
25 public const ACTION_START = 0;
26 public const ACTION_FINISH = 1;
27 public const ACTION_RESTART = 2;
28
29 private int $action;
30 private int $score;
31 private string $activityId;
32
36 public static function create(int $action, int $score, string $activityId) : self{
37 $result = new self;
38 $result->action = $action;
39 $result->score = $score;
40 $result->activityId = $activityId;
41 return $result;
42 }
43
44 public function getAction() : int{ return $this->action; }
45
46 public function getScore() : int{ return $this->score; }
47
48 public function getActivityId() : string{ return $this->activityId; }
49
50 protected function decodePayload(PacketSerializer $in) : void{
51 $this->action = $in->getVarInt();
52 $this->score = $in->getVarInt();
53 $this->activityId = $in->getString();
54 }
55
56 protected function encodePayload(PacketSerializer $out) : void{
57 $out->putVarInt($this->action);
58 $out->putVarInt($this->score);
59 $out->putString($this->activityId);
60 }
61
62 public function handle(PacketHandlerInterface $handler) : bool{
63 return $handler->handleLessonProgress($this);
64 }
65}
static create(int $action, int $score, string $activityId)