Fixed wrong paths

This commit is contained in:
Shoghi Cervantes
2014-04-01 05:06:12 +02:00
parent 05a42712bf
commit dd17652aca
437 changed files with 41109 additions and 0 deletions

255
src/pocketmine/nbt/NBT.php Normal file
View File

@ -0,0 +1,255 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/**
* Named Binary Tag handling classes
*/
namespace pocketmine\nbt;
use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\Byte_Array;
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\Int_Array;
use pocketmine\nbt\tag\Long;
use pocketmine\nbt\tag\NamedTAG;
use pocketmine\nbt\tag\Short;
use pocketmine\nbt\tag\String;
use pocketmine\nbt\tag\Tag;
use pocketmine\utils\Utils;
/**
* Named Binary Tag encoder/decoder
*/
class NBT{
const LITTLE_ENDIAN = 0;
const BIG_ENDIAN = 1;
const TAG_End = 0;
const TAG_Byte = 1;
const TAG_Short = 2;
const TAG_Int = 3;
const TAG_Long = 4;
const TAG_Float = 5;
const TAG_Double = 6;
const TAG_Byte_Array = 7;
const TAG_String = 8;
const TAG_Enum = 9;
const TAG_Compound = 10;
const TAG_Int_Array = 11;
private $buffer;
private $offset;
private $endianness;
private $data;
public function get($len){
if($len < 0){
$this->offset = strlen($this->buffer) - 1;
return "";
}elseif($len === true){
return substr($this->buffer, $this->offset);
}
$buffer = "";
for(; $len > 0; --$len, ++$this->offset){
$buffer .= @$this->buffer{$this->offset};
}
return $buffer;
}
public function put($v){
$this->buffer .= $v;
}
public function feof(){
return !isset($this->buffer{$this->offset});
}
public function __construct($endianness = self::LITTLE_ENDIAN){
$this->offset = 0;
$this->endianness = $endianness & 0x01;
}
public function read($buffer){
$this->offset = 0;
$this->buffer = $buffer;
$this->data = $this->readTag();
$this->buffer = "";
}
public function readCompressed($buffer){
$this->read(\gzdecode($buffer));
}
public function write(){
$this->offset = 0;
if($this->data instanceof Compound){
$this->writeTag($this->data);
return $this->buffer;
}else{
return false;
}
}
public function writeCompressed(){
if(($write = $this->write()) !== false){
return \gzencode($write, 9);
}
return false;
}
public function readTag(){
switch($this->getByte()){
case NBT::TAG_Byte:
$tag = new Byte($this->getString());
$tag->read($this);
break;
case NBT::TAG_Short:
$tag = new Short($this->getString());
$tag->read($this);
break;
case NBT::TAG_Int:
$tag = new Int($this->getString());
$tag->read($this);
break;
case NBT::TAG_Long:
$tag = new Long($this->getString());
$tag->read($this);
break;
case NBT::TAG_Float:
$tag = new Float($this->getString());
$tag->read($this);
break;
case NBT::TAG_Double:
$tag = new Double($this->getString());
$tag->read($this);
break;
case NBT::TAG_Byte_Array:
$tag = new Byte_Array($this->getString());
$tag->read($this);
break;
case NBT::TAG_String:
$tag = new String($this->getString());
$tag->read($this);
break;
case NBT::TAG_Enum:
$tag = new Enum($this->getString());
$tag->read($this);
break;
case NBT::TAG_Compound:
$tag = new Compound($this->getString());
$tag->read($this);
break;
case NBT::TAG_Int_Array:
$tag = new Int_Array($this->getString());
$tag->read($this);
break;
case NBT::TAG_End: //No named tag
default:
$tag = new End;
break;
}
return $tag;
}
public function writeTag(Tag $tag){
$this->putByte($tag->getType());
if($tag instanceof NamedTAG){
$this->putString($tag->getName());
}
$tag->write($this);
}
public function getByte($signed = false){
return Utils::readByte($this->get(1), $signed);
}
public function putByte($v){
$this->buffer .= Utils::writeByte($v);
}
public function getShort(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readShort($this->get(2)) : Utils::readLShort($this->get(2));
}
public function putShort($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeShort($v) : Utils::writeLShort($v);
}
public function getInt(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readInt($this->get(4)) : Utils::readLInt($this->get(4));
}
public function putInt($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeInt($v) : Utils::writeLInt($v);
}
public function getLong(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readLong($this->get(8)) : Utils::readLLong($this->get(8));
}
public function putLong($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeLong($v) : Utils::writeLLong($v);
}
public function getFloat(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readFloat($this->get(4)) : Utils::readLFloat($this->get(4));
}
public function putFloat($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeFloat($v) : Utils::writeLFloat($v);
}
public function getDouble(){
return $this->endianness === self::BIG_ENDIAN ? Utils::readDouble($this->get(8)) : Utils::readLDouble($this->get(8));
}
public function putDouble($v){
$this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeDouble($v) : Utils::writeLDouble($v);
}
public function getString(){
return $this->get($this->getShort());
}
public function putString($v){
$this->putShort(strlen($v));
$this->buffer .= $v;
}
public function getData(){
return $this->data;
}
public function setData(Compound $data){
$this->data = $data;
}
}

View File

@ -0,0 +1,39 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
class Byte extends NamedTag{
public function getType(){
return NBT::TAG_Byte;
}
public function read(NBT $nbt){
$this->value = $nbt->getByte(true);
}
public function write(NBT $nbt){
$nbt->putByte($this->value);
}
}

View File

@ -0,0 +1,40 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
class Byte_Array extends NamedTag{
public function getType(){
return NBT::TAG_Byte_Array;
}
public function read(NBT $nbt){
$this->value = $nbt->get($nbt->getInt());
}
public function write(NBT $nbt){
$nbt->putInt(strlen($this->value));
$nbt->put($this->value);
}
}

View File

@ -0,0 +1,85 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
class Compound extends NamedTag implements \ArrayAccess{
public function __construct($name = "", $value = array()){
$this->name = $name;
foreach($value as $tag){
$this->{$tag->getName()} = $tag;
}
}
public function offsetExists($offset){
return isset($this->{$offset});
}
public function offsetGet($offset){
if($this->{$offset} instanceof Tag){
if($this->{$offset} instanceof \ArrayAccess){
return $this->{$offset};
}else{
return $this->{$offset}->getValue();
}
}
return null;
}
public function offsetSet($offset, $value){
if($value instanceof Tag){
$this->{$offset} = $value;
}elseif(isset($this->{$offset}) and $this->{$offset} instanceof Tag){
$this->{$offset}->setValue($value);
}
}
public function offsetUnset($offset){
unset($this->{$offset});
}
public function getType(){
return NBT::TAG_Compound;
}
public function read(NBT $nbt){
$this->value = array();
do{
$tag = $nbt->readTag();
if($tag instanceof NamedTag and $tag->getName() !== ""){
$this->{$tag->getName()} = $tag;
}
}while(!($tag instanceof End) and !$nbt->feof());
}
public function write(NBT $nbt){
foreach($this as $tag){
if($tag instanceof Tag and !($tag instanceof End)){
$nbt->writeTag($tag);
}
}
$nbt->writeTag(new End);
}
}

View File

@ -0,0 +1,39 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
class Double extends NamedTag{
public function getType(){
return NBT::TAG_Double;
}
public function read(NBT $nbt){
$this->value = $nbt->getDouble();
}
public function write(NBT $nbt){
$nbt->putDouble($this->value);
}
}

View File

@ -0,0 +1,39 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
class End extends Tag{
public function getType(){
return NBT::TAG_End;
}
public function read(NBT $nbt){
}
public function write(NBT $nbt){
}
}

View File

@ -0,0 +1,170 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Enum as TagEnum;
class Enum extends NamedTag implements \ArrayAccess{
private $tagType;
public function __construct($name = "", $value = array()){
$this->name = $name;
foreach($value as $k => $v){
$this->{$k} = $v;
}
}
public function offsetExists($offset){
return isset($this->{$offset});
}
public function offsetGet($offset){
if($this->{$offset} instanceof Tag){
if($this->{$offset} instanceof \ArrayAccess){
return $this->{$offset};
}else{
return $this->{$offset}->getValue();
}
}
return null;
}
public function offsetSet($offset, $value){
if($value instanceof Tag){
$this->{$offset} = $value;
}elseif($this->{$offset} instanceof Tag){
$this->{$offset}->setValue($value);
}
}
public function offsetUnset($offset){
unset($this->{$offset});
}
public function getType(){
return NBT::TAG_Enum;
}
public function setTagType($type){
$this->tagType = $type;
}
public function getTagType(){
return $this->tagType;
}
public function read(NBT $nbt){
$this->value = array();
$this->tagType = $nbt->getByte();
$size = $nbt->getInt();
for($i = 0; $i < $size and !$nbt->feof(); ++$i){
switch($this->tagType){
case NBT::TAG_Byte:
$tag = new Byte(false);
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Short:
$tag = new Short(false);
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Int:
$tag = new Int(false);
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Long:
$tag = new Long(false);
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Float:
$tag = new Float(false);
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Double:
$tag = new Double(false);
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Byte_Array:
$tag = new Byte_Array(false);
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_String:
$tag = new String(false);
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Enum:
$tag = new TagEnum(false);
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Compound:
$tag = new Compound(false);
$tag->read($nbt);
$this->{$i} = $tag;
break;
case NBT::TAG_Int_Array:
$tag = new Int_Array(false);
$tag->read($nbt);
$this->{$i} = $tag;
break;
}
}
}
public function write(NBT $nbt){
if(!isset($this->tagType)){
foreach($this as $tag){
if($tag instanceof Tag){
if(!isset($id)){
$id = $tag->getType();
}elseif($id !== $tag->getType()){
return false;
}
}
}
$this->tagType = @$id;
}
$nbt->putByte($this->tagType);
$tags = array();
foreach($this as $tag){
if($tag instanceof Tag){
$tags[] = $tag;
}
}
$nbt->putInt(count($tags));
foreach($tags as $tag){
$tag->write($nbt);
}
}
}

View File

@ -0,0 +1,39 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
class Float extends NamedTag{
public function getType(){
return NBT::TAG_Float;
}
public function read(NBT $nbt){
$this->value = $nbt->getFloat();
}
public function write(NBT $nbt){
$nbt->putFloat($this->value);
}
}

View File

@ -0,0 +1,39 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
class Int extends NamedTag{
public function getType(){
return NBT::TAG_Int;
}
public function read(NBT $nbt){
$this->value = $nbt->getInt();
}
public function write(NBT $nbt){
$nbt->putInt($this->value);
}
}

View File

@ -0,0 +1,46 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
class Int_Array extends NamedTag{
public function getType(){
return NBT::TAG_Int_Array;
}
public function read(NBT $nbt){
$this->value = array();
$size = $nbt->getInt();
for($i = 0; $i < $size and !$nbt->feof(); ++$i){
$this->value[] = $nbt->getInt();
}
}
public function write(NBT $nbt){
$nbt->putInt(count($this->value));
foreach($this->value as $v){
$nbt->putInt($v);
}
}
}

View File

@ -0,0 +1,39 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
class Long extends NamedTag{
public function getType(){
return NBT::TAG_Long;
}
public function read(NBT $nbt){
$this->value = $nbt->getLong();
}
public function write(NBT $nbt){
$nbt->putLong($this->value);
}
}

View File

@ -0,0 +1,47 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\nbt\tag;
abstract class NamedTag extends Tag{
protected $name;
/**
* @param string $name
* @param bool|float|double|int|byte|short|array|Compound|Enum|string $value
*/
public function __construct($name = "", $value = false){
$this->name = $name;
if($value !== false){
$this->value = $value;
}
}
public function getName(){
return $this->name === false ? "" : $this->name;
}
public function setName($name){
$this->name = $name;
}
}

View File

@ -0,0 +1,39 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
class Short extends NamedTag{
public function getType(){
return NBT::TAG_Short;
}
public function read(NBT $nbt){
$this->value = $nbt->getShort();
}
public function write(NBT $nbt){
$nbt->putShort($this->value);
}
}

View File

@ -0,0 +1,40 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
class String extends NamedTag{
public function getType(){
return NBT::TAG_String;
}
public function read(NBT $nbt){
$this->value = $nbt->get($nbt->getShort());
}
public function write(NBT $nbt){
$nbt->putShort(strlen($this->value));
$nbt->put($this->value);
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/**
* All the NBT Tags
*/
namespace pocketmine\nbt\tag;
use pocketmine\nbt\NBT;
abstract class Tag extends \stdClass{
protected $value;
public function &getValue(){
return $this->value;
}
public abstract function getType();
public function setValue($value){
$this->value = $value;
}
abstract public function write(NBT $nbt);
abstract public function read(NBT $nbt);
public final function __toString(){
return $this->value;
}
}