mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-28 06:09:57 +00:00
Fixed type of empty ListTags and removed some undefined behaviour (#974)
* Fixed fallback type of empty ListTags, close #972 * Less undefined behaviour
This commit is contained in:
parent
ad4659365a
commit
840a3883b1
@ -27,7 +27,7 @@ use pocketmine\nbt\NBT;
|
|||||||
|
|
||||||
class ListTag extends NamedTag implements \ArrayAccess, \Countable{
|
class ListTag extends NamedTag implements \ArrayAccess, \Countable{
|
||||||
|
|
||||||
private $tagType;
|
private $tagType = NBT::TAG_End;
|
||||||
|
|
||||||
public function __construct($name = "", $value = []){
|
public function __construct($name = "", $value = []){
|
||||||
$this->__name = $name;
|
$this->__name = $name;
|
||||||
@ -113,11 +113,11 @@ class ListTag extends NamedTag implements \ArrayAccess, \Countable{
|
|||||||
return NBT::TAG_List;
|
return NBT::TAG_List;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTagType($type){
|
public function setTagType(int $type){
|
||||||
$this->tagType = $type;
|
$this->tagType = $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTagType(){
|
public function getTagType() : int{
|
||||||
return $this->tagType;
|
return $this->tagType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,11 +135,11 @@ class ListTag extends NamedTag implements \ArrayAccess, \Countable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function write(NBT $nbt, bool $network = false){
|
public function write(NBT $nbt, bool $network = false){
|
||||||
if(!isset($this->tagType)){
|
if($this->tagType === NBT::TAG_End){ //previously empty list, try detecting type from tag children
|
||||||
$id = null;
|
$id = NBT::TAG_End;
|
||||||
foreach($this as $tag){
|
foreach($this as $tag){
|
||||||
if($tag instanceof Tag){
|
if($tag instanceof Tag and !($tag instanceof EndTag)){
|
||||||
if(!isset($id)){
|
if($id === NBT::TAG_End){
|
||||||
$id = $tag->getType();
|
$id = $tag->getType();
|
||||||
}elseif($id !== $tag->getType()){
|
}elseif($id !== $tag->getType()){
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user