Skip to content

Commit

Permalink
Added count(Enum)
Browse files Browse the repository at this point in the history
  • Loading branch information
PEMapModder committed Jul 21, 2014
1 parent 1772592 commit da884fe
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tag/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Enum as TagEnum;

class Enum extends NamedTag implements \ArrayAccess{
class Enum extends NamedTag implements \ArrayAccess, \Countable{

private $tagType;

Expand Down Expand Up @@ -73,6 +73,19 @@ public function offsetUnset($offset){
unset($this->{$offset});
}

public function count($mode = COUNT_NORMAL){
for($i = 0; true; $i++){
if(!isset($this->{$i})){
return $i;
}
if($mode === COUNT_RECURSIVE){
if($this->{$i} instanceof \Countable){
$i += count($this->{$i});
}
}
}
}

public function getType(){
return NBT::TAG_Enum;
}
Expand Down Expand Up @@ -178,4 +191,4 @@ public function write(NBT $nbt){
$tag->write($nbt);
}
}
}
}

0 comments on commit da884fe

Please sign in to comment.