PocketMine-MP 5.23.3 git-976fc63567edab7a6fb6aeae739f43cf9fe57de4
Loading...
Searching...
No Matches
IntArrayTag.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
29use function array_values;
30use function assert;
31use function func_num_args;
32use function implode;
33use function is_int;
34
35final class IntArrayTag extends ImmutableTag{
40 private $value;
41
46 public function __construct(array $value){
47 self::restrictArgCount(__METHOD__, func_num_args(), 1);
48 assert((function() use(&$value) : bool{
49 foreach($value as $v){
50 if(!is_int($v)){
51 return false;
52 }
53 }
54
55 return true;
56 })());
57
58 $this->value = array_values($value);
59 }
60
61 protected function getTypeName() : string{
62 return "IntArray";
63 }
64
65 public function getType() : int{
66 return NBT::TAG_IntArray;
67 }
68
69 public static function read(NbtStreamReader $reader) : self{
70 return new self($reader->readIntArray());
71 }
72
73 public function write(NbtStreamWriter $writer) : void{
74 $writer->writeIntArray($this->value);
75 }
76
77 protected function stringifyValue(int $indentation) : string{
78 return "[" . implode(",", $this->value) . "]";
79 }
80
85 public function getValue() : array{
86 return $this->value;
87 }
88}