PocketMine-MP 5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
Loading...
Searching...
No Matches
WrittenBook.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\item;
25
29use function sprintf;
30use function strlen;
31
33
34 public const GENERATION_ORIGINAL = 0;
35 public const GENERATION_COPY = 1;
36 public const GENERATION_COPY_OF_COPY = 2;
37 public const GENERATION_TATTERED = 3;
38
39 public const TAG_GENERATION = "generation"; //TAG_Int
40 public const TAG_AUTHOR = "author"; //TAG_String
41 public const TAG_TITLE = "title"; //TAG_String
42
43 private int $generation = self::GENERATION_ORIGINAL;
44 private string $author = "";
45 private string $title = "";
46
47 public function getMaxStackSize() : int{
48 return 16;
49 }
50
55 public function getGeneration() : int{
56 return $this->generation;
57 }
58
64 public function setGeneration(int $generation) : self{
65 if($generation < 0 || $generation > 3){
66 throw new \InvalidArgumentException("Generation \"$generation\" is out of range");
67 }
68
69 $this->generation = $generation;
70 return $this;
71 }
72
78 public function getAuthor() : string{
79 return $this->author;
80 }
81
87 public function setAuthor(string $authorName) : self{
88 if(strlen($authorName) > Limits::INT16_MAX){
89 throw new \InvalidArgumentException(sprintf("Author must be at most %d bytes, but have %d bytes", Limits::INT16_MAX, strlen($authorName)));
90 }
91 Utils::checkUTF8($authorName);
92 $this->author = $authorName;
93 return $this;
94 }
95
99 public function getTitle() : string{
100 return $this->title;
101 }
102
108 public function setTitle(string $title) : self{
109 if(strlen($title) > Limits::INT16_MAX){
110 throw new \InvalidArgumentException(sprintf("Title must be at most %d bytes, but have %d bytes", Limits::INT16_MAX, strlen($title)));
111 }
112 Utils::checkUTF8($title);
113 $this->title = $title;
114 return $this;
115 }
116
117 protected function deserializeCompoundTag(CompoundTag $tag) : void{
118 parent::deserializeCompoundTag($tag);
119 $this->generation = $tag->getInt(self::TAG_GENERATION, $this->generation);
120 $this->author = $tag->getString(self::TAG_AUTHOR, $this->author);
121 $this->title = $tag->getString(self::TAG_TITLE, $this->title);
122 }
123
124 protected function serializeCompoundTag(CompoundTag $tag) : void{
125 parent::serializeCompoundTag($tag);
126 $tag->setInt(self::TAG_GENERATION, $this->generation);
127 $tag->setString(self::TAG_AUTHOR, $this->author);
128 $tag->setString(self::TAG_TITLE, $this->title);
129 }
130}
deserializeCompoundTag(CompoundTag $tag)
setGeneration(int $generation)
setAuthor(string $authorName)
setString(string $name, string $value)
setInt(string $name, int $value)