PocketMine-MP 5.17.1 git-df4ada81e5d74a14046f27cf44a37dcee69d657e
Tag.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\nbt\tag;
25
27
28abstract class Tag{
29
34 protected $cloning = false;
35
37 abstract public function getValue();
38
39 abstract public function getType() : int;
40
41 abstract public function write(NbtStreamWriter $writer) : void;
42
43 public function __toString(){
44 return $this->toString();
45 }
46
47 final public function toString(int $indentation = 0) : string{
48 return "TAG_" . $this->getTypeName() . "=" . $this->stringifyValue($indentation);
49 }
50
51 abstract protected function getTypeName() : string;
52
53 abstract protected function stringifyValue(int $indentation) : string;
54
61 public function safeClone() : Tag{
62 if($this->cloning){
63 throw new \RuntimeException("Recursive NBT tag dependency detected");
64 }
65 $this->cloning = true;
66
67 $retval = $this->makeCopy();
68
69 $this->cloning = false;
70 $retval->cloning = false;
71
72 return $retval;
73 }
74
78 abstract protected function makeCopy();
79
84 public function equals(Tag $that) : bool{
85 return $that instanceof $this and $this->getValue() === $that->getValue();
86 }
87
88 protected static function restrictArgCount(string $func, int $haveArgs, int $wantMaxArgs) : void{
89 if($haveArgs > $wantMaxArgs){
90 throw new \ArgumentCountError("$func() expects at most $wantMaxArgs parameters, $haveArgs given");
91 }
92 }
93}
equals(Tag $that)
Definition: Tag.php:84