Renamed NBT tags to have Tag in the name

This commit is contained in:
Shoghi Cervantes
2015-08-12 21:30:15 +02:00
parent 34dc6ea0d6
commit 7f8b39a63c
58 changed files with 791 additions and 791 deletions

View File

@ -25,19 +25,19 @@
namespace pocketmine\nbt;
use pocketmine\item\Item;
use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\ByteArray;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Double;
use pocketmine\nbt\tag\End;
use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Float;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\IntArray;
use pocketmine\nbt\tag\Long;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\ByteArrayTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\DoubleTag;
use pocketmine\nbt\tag\EndTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\IntArrayTag;
use pocketmine\nbt\tag\LongTag;
use pocketmine\nbt\tag\NamedTAG;
use pocketmine\nbt\tag\Short;
use pocketmine\nbt\tag\String;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\nbt\tag\Tag;
use pocketmine\utils\Utils;
@ -65,7 +65,7 @@ class NBT{
const TAG_Double = 6;
const TAG_ByteArray = 7;
const TAG_String = 8;
const TAG_Enum = 9;
const TAG_List = 9;
const TAG_Compound = 10;
const TAG_IntArray = 11;
@ -78,17 +78,17 @@ class NBT{
/**
* @param Item $item
* @param int $slot
* @return Compound
* @return CompoundTag
*/
public static function putItemHelper(Item $item, $slot = null){
$tag = new Compound(null, [
"id" => new Short("id", $item->getId()),
"Count" => new Byte("Count", $item->getCount()),
"Damage" => new Short("Damage", $item->getDamage())
$tag = new CompoundTag(null, [
"id" => new ShortTag("id", $item->getId()),
"Count" => new ByteTag("Count", $item->getCount()),
"Damage" => new ShortTag("Damage", $item->getDamage())
]);
if($slot !== null){
$tag->Slot = new Byte("Slot", (int) $slot);
$tag->Slot = new ByteTag("Slot", (int) $slot);
}
if($item->hasCompoundTag()){
@ -100,24 +100,24 @@ class NBT{
}
/**
* @param Compound $tag
* @param CompoundTag $tag
* @return Item
*/
public static function getItemHelper(Compound $tag){
public static function getItemHelper(CompoundTag $tag){
if(!isset($tag->id) or !isset($tag->Count)){
return Item::get(0);
}
$item = Item::get($tag->id->getValue(), !isset($tag->Damage) ? 0 : $tag->Damage->getValue(), $tag->Count->getValue());
if(isset($tag->tag) and $tag->tag instanceof Compound){
if(isset($tag->tag) and $tag->tag instanceof CompoundTag){
$item->setNamedTag($tag->tag);
}
return $item;
}
public static function matchList(Enum $tag1, Enum $tag2){
public static function matchList(ListTag $tag1, ListTag $tag2){
if($tag1->getName() !== $tag2->getName() or $tag1->getCount() !== $tag2->getCount()){
return false;
}
@ -131,11 +131,11 @@ class NBT{
return false;
}
if($v instanceof Compound){
if($v instanceof CompoundTag){
if(!self::matchTree($v, $tag2->{$k})){
return false;
}
}elseif($v instanceof Enum){
}elseif($v instanceof ListTag){
if(!self::matchList($v, $tag2->{$k})){
return false;
}
@ -149,7 +149,7 @@ class NBT{
return true;
}
public static function matchTree(Compound $tag1, Compound $tag2){
public static function matchTree(CompoundTag $tag1, CompoundTag $tag2){
if($tag1->getName() !== $tag2->getName() or $tag1->getCount() !== $tag2->getCount()){
return false;
}
@ -163,11 +163,11 @@ class NBT{
return false;
}
if($v instanceof Compound){
if($v instanceof CompoundTag){
if(!self::matchTree($v, $tag2->{$k})){
return false;
}
}elseif($v instanceof Enum){
}elseif($v instanceof ListTag){
if(!self::matchList($v, $tag2->{$k})){
return false;
}
@ -188,7 +188,7 @@ class NBT{
if($c === "{"){
++$offset;
$data = self::parseCompound($data, $offset);
return new Compound("", $data);
return new CompoundTag("", $data);
}elseif($c !== " " and $c !== "\r" and $c !== "\n" and $c !== "\t"){
throw new \Exception("Syntax error: unexpected '$c' at offset $offset");
}
@ -218,37 +218,37 @@ class NBT{
switch($type){
case NBT::TAG_Byte:
$data[$key] = new Byte($key, $value);
$data[$key] = new ByteTag($key, $value);
break;
case NBT::TAG_Short:
$data[$key] = new Short($key, $value);
$data[$key] = new ShortTag($key, $value);
break;
case NBT::TAG_Int:
$data[$key] = new Int($key, $value);
$data[$key] = new IntTag($key, $value);
break;
case NBT::TAG_Long:
$data[$key] = new Long($key, $value);
$data[$key] = new LongTag($key, $value);
break;
case NBT::TAG_Float:
$data[$key] = new Float($key, $value);
$data[$key] = new FloatTag($key, $value);
break;
case NBT::TAG_Double:
$data[$key] = new Double($key, $value);
$data[$key] = new DoubleTag($key, $value);
break;
case NBT::TAG_ByteArray:
$data[$key] = new ByteArray($key, $value);
$data[$key] = new ByteArrayTag($key, $value);
break;
case NBT::TAG_String:
$data[$key] = new Byte($key, $value);
$data[$key] = new ByteTag($key, $value);
break;
case NBT::TAG_Enum:
$data[$key] = new Enum($key, $value);
case NBT::TAG_List:
$data[$key] = new ListTag($key, $value);
break;
case NBT::TAG_Compound:
$data[$key] = new Compound($key, $value);
$data[$key] = new CompoundTag($key, $value);
break;
case NBT::TAG_IntArray:
$data[$key] = new IntArray($key, $value);
$data[$key] = new IntArrayTag($key, $value);
break;
}
@ -276,37 +276,37 @@ class NBT{
switch($type){
case NBT::TAG_Byte:
$data[$key] = new Byte($key, $value);
$data[$key] = new ByteTag($key, $value);
break;
case NBT::TAG_Short:
$data[$key] = new Short($key, $value);
$data[$key] = new ShortTag($key, $value);
break;
case NBT::TAG_Int:
$data[$key] = new Int($key, $value);
$data[$key] = new IntTag($key, $value);
break;
case NBT::TAG_Long:
$data[$key] = new Long($key, $value);
$data[$key] = new LongTag($key, $value);
break;
case NBT::TAG_Float:
$data[$key] = new Float($key, $value);
$data[$key] = new FloatTag($key, $value);
break;
case NBT::TAG_Double:
$data[$key] = new Double($key, $value);
$data[$key] = new DoubleTag($key, $value);
break;
case NBT::TAG_ByteArray:
$data[$key] = new ByteArray($key, $value);
$data[$key] = new ByteArrayTag($key, $value);
break;
case NBT::TAG_String:
$data[$key] = new String($key, $value);
$data[$key] = new StringTag($key, $value);
break;
case NBT::TAG_Enum:
$data[$key] = new Enum($key, $value);
case NBT::TAG_List:
$data[$key] = new ListTag($key, $value);
break;
case NBT::TAG_Compound:
$data[$key] = new Compound($key, $value);
$data[$key] = new CompoundTag($key, $value);
break;
case NBT::TAG_IntArray:
$data[$key] = new IntArray($key, $value);
$data[$key] = new IntArrayTag($key, $value);
break;
}
}
@ -351,7 +351,7 @@ class NBT{
}
++$offset;
$value = self::parseList($data, $offset);
$type = self::TAG_Enum;
$type = self::TAG_List;
break;
}else{
$value .= $c;
@ -480,7 +480,7 @@ class NBT{
$this->offset = 0;
$this->buffer = "";
if($this->data instanceof Compound){
if($this->data instanceof CompoundTag){
$this->writeTag($this->data);
return $this->buffer;
@ -505,53 +505,53 @@ class NBT{
public function readTag(){
switch($this->getByte()){
case NBT::TAG_Byte:
$tag = new Byte($this->getString());
$tag = new ByteTag($this->getString());
$tag->read($this);
break;
case NBT::TAG_Short:
$tag = new Short($this->getString());
$tag = new ShortTag($this->getString());
$tag->read($this);
break;
case NBT::TAG_Int:
$tag = new Int($this->getString());
$tag = new IntTag($this->getString());
$tag->read($this);
break;
case NBT::TAG_Long:
$tag = new Long($this->getString());
$tag = new LongTag($this->getString());
$tag->read($this);
break;
case NBT::TAG_Float:
$tag = new Float($this->getString());
$tag = new FloatTag($this->getString());
$tag->read($this);
break;
case NBT::TAG_Double:
$tag = new Double($this->getString());
$tag = new DoubleTag($this->getString());
$tag->read($this);
break;
case NBT::TAG_ByteArray:
$tag = new ByteArray($this->getString());
$tag = new ByteArrayTag($this->getString());
$tag->read($this);
break;
case NBT::TAG_String:
$tag = new String($this->getString());
$tag = new StringTag($this->getString());
$tag->read($this);
break;
case NBT::TAG_Enum:
$tag = new Enum($this->getString());
case NBT::TAG_List:
$tag = new ListTag($this->getString());
$tag->read($this);
break;
case NBT::TAG_Compound:
$tag = new Compound($this->getString());
$tag = new CompoundTag($this->getString());
$tag->read($this);
break;
case NBT::TAG_IntArray:
$tag = new IntArray($this->getString());
$tag = new IntArrayTag($this->getString());
$tag->read($this);
break;
case NBT::TAG_End: //No named tag
default:
$tag = new End;
$tag = new EndTag;
break;
}
return $tag;
@ -628,9 +628,9 @@ class NBT{
}
private static function toArray(array &$data, Tag $tag){
/** @var Compound[]|Enum[]|IntArray[] $tag */
/** @var CompoundTag[]|ListTag[]|IntArrayTag[] $tag */
foreach($tag as $key => $value){
if($value instanceof Compound or $value instanceof Enum or $value instanceof IntArray){
if($value instanceof CompoundTag or $value instanceof ListTag or $value instanceof IntArrayTag){
$data[$key] = [];
self::toArray($data[$key], $value);
}else{
@ -641,13 +641,13 @@ class NBT{
public static function fromArrayGuesser($key, $value){
if(is_int($value)){
return new Int($key, $value);
return new IntTag($key, $value);
}elseif(is_float($value)){
return new Float($key, $value);
return new FloatTag($key, $value);
}elseif(is_string($value)){
return new String($key, $value);
return new StringTag($key, $value);
}elseif(is_bool($value)){
return new Byte($key, $value ? 1 : 0);
return new ByteTag($key, $value ? 1 : 0);
}
return null;
@ -666,7 +666,7 @@ class NBT{
$isIntArray = false;
}
}
$tag{$key} = $isNumeric ? ($isIntArray ? new IntArray($key, []) : new Enum($key, [])) : new Compound($key, []);
$tag{$key} = $isNumeric ? ($isIntArray ? new IntArrayTag($key, []) : new ListTag($key, [])) : new CompoundTag($key, []);
self::fromArray($tag->{$key}, $value, $guesser);
}else{
$v = call_user_func($guesser, $key, $value);
@ -678,19 +678,19 @@ class NBT{
}
public function setArray(array $data, callable $guesser = null){
$this->data = new Compound("", []);
$this->data = new CompoundTag("", []);
self::fromArray($this->data, $data, $guesser === null ? [self::class, "fromArrayGuesser"] : $guesser);
}
/**
* @return Compound|array
* @return CompoundTag|array
*/
public function getData(){
return $this->data;
}
/**
* @param Compound|array $data
* @param CompoundTag|array $data
*/
public function setData($data){
$this->data = $data;

View File

@ -25,7 +25,7 @@ use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class ByteArray extends NamedTag{
class ByteArrayTag extends NamedTag{
public function getType(){
return NBT::TAG_ByteArray;

View File

@ -25,7 +25,7 @@ use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class Byte extends NamedTag{
class ByteTag extends NamedTag{
public function getType(){
return NBT::TAG_Byte;

View File

@ -25,7 +25,7 @@ use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class Compound extends NamedTag implements \ArrayAccess{
class CompoundTag extends NamedTag implements \ArrayAccess{
/**
* @param string $name
@ -88,16 +88,16 @@ class Compound extends NamedTag implements \ArrayAccess{
if($tag instanceof NamedTag and $tag->getName() !== ""){
$this->{$tag->getName()} = $tag;
}
}while(!($tag instanceof End) and !$nbt->feof());
}while(!($tag instanceof EndTag) and !$nbt->feof());
}
public function write(NBT $nbt){
foreach($this as $tag){
if($tag instanceof Tag and !($tag instanceof End)){
if($tag instanceof Tag and !($tag instanceof EndTag)){
$nbt->writeTag($tag);
}
}
$nbt->writeTag(new End);
$nbt->writeTag(new EndTag);
}
public function __toString(){

View File

@ -25,7 +25,7 @@ use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class Double extends NamedTag{
class DoubleTag extends NamedTag{
public function getType(){
return NBT::TAG_Double;

View File

@ -23,7 +23,7 @@ namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
class End extends Tag{
class EndTag extends Tag{
public function getType(){
return NBT::TAG_End;

View File

@ -25,7 +25,7 @@ use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class Float extends NamedTag{
class FloatTag extends NamedTag{
public function getType(){
return NBT::TAG_Float;

View File

@ -25,7 +25,7 @@ use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class IntArray extends NamedTag{
class IntArrayTag extends NamedTag{
public function getType(){
return NBT::TAG_IntArray;

View File

@ -25,7 +25,7 @@ use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class Int extends NamedTag{
class IntTag extends NamedTag{
public function getType(){
return NBT::TAG_Int;

View File

@ -22,11 +22,11 @@
namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Enum as TagEnum;
use pocketmine\nbt\tag\ListTag as TagEnum;
#include <rules/NBT.h>
class Enum extends NamedTag implements \ArrayAccess, \Countable{
class ListTag extends NamedTag implements \ArrayAccess, \Countable{
private $tagType;
@ -103,7 +103,7 @@ class Enum extends NamedTag implements \ArrayAccess, \Countable{
}
public function getType(){
return NBT::TAG_Enum;
return NBT::TAG_List;
}
public function setTagType($type){
@ -121,57 +121,57 @@ class Enum extends NamedTag implements \ArrayAccess, \Countable{
for($i = 0; $i < $size and !$nbt->feof(); ++$i){
switch($this->tagType){
case NBT::TAG_Byte:
$tag = new Byte("");
$tag = new ByteTag("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Short:
$tag = new Short("");
$tag = new ShortTag("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Int:
$tag = new Int("");
$tag = new IntTag("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Long:
$tag = new Long("");
$tag = new LongTag("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Float:
$tag = new Float("");
$tag = new FloatTag("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Double:
$tag = new Double("");
$tag = new DoubleTag("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_ByteArray:
$tag = new ByteArray("");
$tag = new ByteArrayTag("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_String:
$tag = new String("");
$tag = new StringTag("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Enum:
case NBT::TAG_List:
$tag = new TagEnum("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Compound:
$tag = new Compound("");
$tag = new CompoundTag("");
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_IntArray:
$tag = new IntArray("");
$tag = new IntArrayTag("");
$tag->read($nbt);
$this->{$i} = $tag;
break;

View File

@ -25,7 +25,7 @@ use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class Long extends NamedTag{
class LongTag extends NamedTag{
public function getType(){
return NBT::TAG_Long;

View File

@ -28,7 +28,7 @@ abstract class NamedTag extends Tag{
/**
* @param string $name
* @param bool|float|double|int|byte|short|array|Compound|Enum|string $value
* @param bool|float|double|int|ByteTag|ShortTag|array|CompoundTag|ListTag|string $value
*/
public function __construct($name = "", $value = null){
$this->__name = ($name === null or $name === false) ? "" : $name;

View File

@ -25,7 +25,7 @@ use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class Short extends NamedTag{
class ShortTag extends NamedTag{
public function getType(){
return NBT::TAG_Short;

View File

@ -25,7 +25,7 @@ use pocketmine\nbt\NBT;
#include <rules/NBT.h>
class String extends NamedTag{
class StringTag extends NamedTag{
public function getType(){
return NBT::TAG_String;