diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index ac9e10aad..b2c37c22f 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -728,12 +728,12 @@ class Server{ } $spawn = $this->getDefaultLevel()->getSafeSpawn(); $nbt = new CompoundTag("", [ - new LongTag("firstPlayed", floor(microtime(true) * 1000)), - new LongTag("lastPlayed", floor(microtime(true) * 1000)), + new LongTag("firstPlayed", (int) (microtime(true) * 1000)), + new LongTag("lastPlayed", (int) (microtime(true) * 1000)), new ListTag("Pos", [ - new DoubleTag(0, $spawn->x), - new DoubleTag(1, $spawn->y), - new DoubleTag(2, $spawn->z) + new DoubleTag("", $spawn->x), + new DoubleTag("", $spawn->y), + new DoubleTag("", $spawn->z) ]), new StringTag("Level", $this->getDefaultLevel()->getName()), //new StringTag("SpawnLevel", $this->getDefaultLevel()->getName()), @@ -745,13 +745,13 @@ class Server{ new CompoundTag("Achievements", []), new IntTag("playerGameType", $this->getGamemode()), new ListTag("Motion", [ - new DoubleTag(0, 0.0), - new DoubleTag(1, 0.0), - new DoubleTag(2, 0.0) + new DoubleTag("", 0.0), + new DoubleTag("", 0.0), + new DoubleTag("", 0.0) ]), new ListTag("Rotation", [ - new FloatTag(0, 0.0), - new FloatTag(1, 0.0) + new FloatTag("", 0.0), + new FloatTag("", 0.0) ]), new FloatTag("FallDistance", 0.0), new ShortTag("Fire", 0), diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index c18a475b1..cc137bb51 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -738,7 +738,7 @@ abstract class Entity extends Location implements Metadatable{ $this->namedtag->id = new StringTag("id", $this->getSaveId()); if($this->getNameTag() !== ""){ $this->namedtag->CustomName = new StringTag("CustomName", $this->getNameTag()); - $this->namedtag->CustomNameVisible = new StringTag("CustomNameVisible", $this->isNameTagVisible()); + $this->namedtag->CustomNameVisible = new ByteTag("CustomNameVisible", $this->isNameTagVisible() ? 1 : 0); }else{ unset($this->namedtag->CustomName); unset($this->namedtag->CustomNameVisible); @@ -746,20 +746,20 @@ abstract class Entity extends Location implements Metadatable{ } $this->namedtag->Pos = new ListTag("Pos", [ - new DoubleTag(0, $this->x), - new DoubleTag(1, $this->y), - new DoubleTag(2, $this->z) + new DoubleTag("", $this->x), + new DoubleTag("", $this->y), + new DoubleTag("", $this->z) ]); $this->namedtag->Motion = new ListTag("Motion", [ - new DoubleTag(0, $this->motionX), - new DoubleTag(1, $this->motionY), - new DoubleTag(2, $this->motionZ) + new DoubleTag("", $this->motionX), + new DoubleTag("", $this->motionY), + new DoubleTag("", $this->motionZ) ]); $this->namedtag->Rotation = new ListTag("Rotation", [ - new FloatTag(0, $this->yaw), - new FloatTag(1, $this->pitch) + new FloatTag("", $this->yaw), + new FloatTag("", $this->pitch) ]); $this->namedtag->FallDistance = new FloatTag("FallDistance", $this->fallDistance); @@ -771,7 +771,7 @@ abstract class Entity extends Location implements Metadatable{ if(count($this->effects) > 0){ $effects = []; foreach($this->effects as $effect){ - $effects[$effect->getId()] = new CompoundTag($effect->getId(), [ + $effects[] = new CompoundTag("", [ "Id" => new ByteTag("Id", $effect->getId()), "Amplifier" => new ByteTag("Amplifier", $effect->getAmplifier()), "Duration" => new IntTag("Duration", $effect->getDuration()), diff --git a/src/pocketmine/entity/Item.php b/src/pocketmine/entity/Item.php index 8f3b99a6f..335d43feb 100644 --- a/src/pocketmine/entity/Item.php +++ b/src/pocketmine/entity/Item.php @@ -36,8 +36,11 @@ use pocketmine\Player; class Item extends Entity{ const NETWORK_ID = 64; - protected $owner = null; - protected $thrower = null; + /** @var string */ + protected $owner = ""; + /** @var string */ + protected $thrower = ""; + /** @var int */ protected $pickupDelay = 0; /** @var ItemItem */ protected $item; diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 5836c40f9..0f4ac8d39 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -32,6 +32,7 @@ use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\Timings; use pocketmine\item\Item as ItemItem; use pocketmine\math\Vector3; +use pocketmine\nbt\tag\FloatTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\network\mcpe\protocol\EntityEventPacket; use pocketmine\utils\BlockIterator; @@ -51,10 +52,12 @@ abstract class Living extends Entity implements Damageable{ parent::initEntity(); if(isset($this->namedtag->HealF)){ - $this->namedtag->Health = new ShortTag("Health", (int) $this->namedtag["HealF"]); + $this->namedtag->Health = new FloatTag("Health", (float) $this->namedtag["HealF"]); unset($this->namedtag->HealF); - }elseif(!isset($this->namedtag->Health) or !($this->namedtag->Health instanceof ShortTag)){ - $this->namedtag->Health = new ShortTag("Health", $this->getMaxHealth()); + }elseif(isset($this->namedtag->Health) and !($this->namedtag->Health instanceof FloatTag)){ + $this->namedtag->Health = new FloatTag("Health", (float) $this->namedtag->Health->getValue()); + }else{ + $this->namedtag->Health = new FloatTag("Health", (float) $this->getMaxHealth()); } $this->setHealth($this->namedtag["Health"]); diff --git a/src/pocketmine/level/format/io/BaseLevelProvider.php b/src/pocketmine/level/format/io/BaseLevelProvider.php index 300c84956..dd11bbeb0 100644 --- a/src/pocketmine/level/format/io/BaseLevelProvider.php +++ b/src/pocketmine/level/format/io/BaseLevelProvider.php @@ -59,7 +59,7 @@ abstract class BaseLevelProvider implements LevelProvider{ } if(!isset($this->levelData->generatorName)){ - $this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("DEFAULT")); + $this->levelData->generatorName = new StringTag("generatorName", (string) Generator::getGenerator("DEFAULT")); } if(!isset($this->levelData->generatorOptions)){ diff --git a/src/pocketmine/level/format/io/leveldb/LevelDB.php b/src/pocketmine/level/format/io/leveldb/LevelDB.php index b08ee7a01..79b782dbf 100644 --- a/src/pocketmine/level/format/io/leveldb/LevelDB.php +++ b/src/pocketmine/level/format/io/leveldb/LevelDB.php @@ -95,7 +95,7 @@ class LevelDB extends BaseLevelProvider{ if(isset($this->levelData->Generator)){ switch((int) $this->levelData->Generator->getValue()){ //Detect correct generator from MCPE data case self::GENERATOR_FLAT: - $this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("FLAT")); + $this->levelData->generatorName = new StringTag("generatorName", (string) Generator::getGenerator("FLAT")); if(($layers = $this->db->get(self::ENTRY_FLAT_WORLD_LAYERS)) !== false){ //Detect existing custom flat layers $layers = trim($layers, "[]"); }else{ @@ -105,7 +105,7 @@ class LevelDB extends BaseLevelProvider{ break; case self::GENERATOR_INFINITE: //TODO: add a null generator which does not generate missing chunks (to allow importing back to MCPE and generating more normal terrain without PocketMine messing things up) - $this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("DEFAULT")); + $this->levelData->generatorName = new StringTag("generatorName", (string) Generator::getGenerator("DEFAULT")); $this->levelData->generatorOptions = new StringTag("generatorOptions", ""); break; case self::GENERATOR_LIMITED: @@ -114,7 +114,7 @@ class LevelDB extends BaseLevelProvider{ throw new LevelException("Unknown LevelDB world format type, this level cannot be loaded"); } }else{ - $this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("DEFAULT")); + $this->levelData->generatorName = new StringTag("generatorName", (string) Generator::getGenerator("DEFAULT")); } } diff --git a/src/pocketmine/level/format/io/region/Anvil.php b/src/pocketmine/level/format/io/region/Anvil.php index 163712cde..7e35da205 100644 --- a/src/pocketmine/level/format/io/region/Anvil.php +++ b/src/pocketmine/level/format/io/region/Anvil.php @@ -56,7 +56,7 @@ class Anvil extends McRegion{ if($subChunk->isEmpty()){ continue; } - $nbt->Sections[++$subChunks] = new CompoundTag(null, [ + $nbt->Sections[++$subChunks] = new CompoundTag("", [ "Y" => new ByteTag("Y", $y), "Blocks" => new ByteArrayTag("Blocks", ChunkUtils::reorderByteArray($subChunk->getBlockIdArray())), //Generic in-memory chunks are currently always XZY "Data" => new ByteArrayTag("Data", ChunkUtils::reorderNibbleArray($subChunk->getBlockDataArray())), diff --git a/src/pocketmine/level/format/io/region/PMAnvil.php b/src/pocketmine/level/format/io/region/PMAnvil.php index 3a165a188..c3b8c590e 100644 --- a/src/pocketmine/level/format/io/region/PMAnvil.php +++ b/src/pocketmine/level/format/io/region/PMAnvil.php @@ -59,7 +59,7 @@ class PMAnvil extends Anvil{ if($subChunk->isEmpty()){ continue; } - $nbt->Sections[++$subChunks] = new CompoundTag(null, [ + $nbt->Sections[++$subChunks] = new CompoundTag("", [ "Y" => new ByteTag("Y", $y), "Blocks" => new ByteArrayTag("Blocks", $subChunk->getBlockIdArray()), "Data" => new ByteArrayTag("Data", $subChunk->getBlockDataArray()), diff --git a/src/pocketmine/nbt/tag/ByteArrayTag.php b/src/pocketmine/nbt/tag/ByteArrayTag.php index 00bc696c0..75eb3e71a 100644 --- a/src/pocketmine/nbt/tag/ByteArrayTag.php +++ b/src/pocketmine/nbt/tag/ByteArrayTag.php @@ -29,6 +29,16 @@ use pocketmine\nbt\NBT; class ByteArrayTag extends NamedTag{ + /** + * ByteArrayTag constructor. + * + * @param string $name + * @param string $value + */ + public function __construct(string $name = "", string $value = ""){ + parent::__construct($name, $value); + } + public function getType(){ return NBT::TAG_ByteArray; } @@ -41,4 +51,23 @@ class ByteArrayTag extends NamedTag{ $nbt->putInt(strlen($this->value), $network); $nbt->put($this->value); } + + /** + * @return string + */ + public function &getValue() : string{ + return parent::getValue(); // TODO: Change the autogenerated stub + } + + /** + * @param string $value + * + * @throws \TypeError + */ + public function setValue($value){ + if(!is_string($value)){ + throw new \TypeError("ByteArrayTag value must be of type string, " . gettype($value) . " given"); + } + parent::setValue($value); + } } \ No newline at end of file diff --git a/src/pocketmine/nbt/tag/ByteTag.php b/src/pocketmine/nbt/tag/ByteTag.php index 3aa13b512..6a5c9311f 100644 --- a/src/pocketmine/nbt/tag/ByteTag.php +++ b/src/pocketmine/nbt/tag/ByteTag.php @@ -29,6 +29,16 @@ use pocketmine\nbt\NBT; class ByteTag extends NamedTag{ + /** + * ByteTag constructor. + * + * @param string $name + * @param int $value + */ + public function __construct(string $name = "", int $value = 0){ + parent::__construct($name, $value); + } + public function getType(){ return NBT::TAG_Byte; } @@ -40,4 +50,25 @@ class ByteTag extends NamedTag{ public function write(NBT $nbt, bool $network = false){ $nbt->putByte($this->value); } + + /** + * @return int + */ + public function &getValue() : int{ + return parent::getValue(); + } + + /** + * @param int $value + * + * @throws \TypeError + */ + public function setValue($value){ + if(!is_int($value)){ + throw new \TypeError("ByteTag value must be of type int, " . gettype($value) . " given"); + }elseif($value < -(2 ** 7) or $value > ((2 ** 7) - 1)){ + throw new \InvalidArgumentException("Value $value is too large!"); + } + parent::setValue($value); + } } \ No newline at end of file diff --git a/src/pocketmine/nbt/tag/CompoundTag.php b/src/pocketmine/nbt/tag/CompoundTag.php index 623b00e0a..e7413494f 100644 --- a/src/pocketmine/nbt/tag/CompoundTag.php +++ b/src/pocketmine/nbt/tag/CompoundTag.php @@ -30,14 +30,13 @@ use pocketmine\nbt\NBT; class CompoundTag extends NamedTag implements \ArrayAccess{ /** + * CompoundTag constructor. + * * @param string $name * @param NamedTag[] $value */ - public function __construct($name = "", $value = []){ - $this->__name = $name; - foreach($value as $tag){ - $this->{$tag->getName()} = $tag; - } + public function __construct(string $name = "", array $value = []){ + parent::__construct($name, $value); } public function getCount(){ @@ -51,13 +50,22 @@ class CompoundTag extends NamedTag implements \ArrayAccess{ return $count; } + /** + * @param NamedTag[] $value + * + * @throws \TypeError + */ public function setValue($value){ if(is_array($value)){ foreach($value as $name => $tag){ if($tag instanceof NamedTag){ - $this->{$name} = $tag; + $this->{$tag->getName()} = $tag; + }else{ + throw new \TypeError("CompoundTag members must be NamedTags, got " . gettype($tag) . " in given array"); } } + }else{ + throw new \TypeError("CompoundTag value must be NamedTag[], " . gettype($value) . " given"); } } diff --git a/src/pocketmine/nbt/tag/DoubleTag.php b/src/pocketmine/nbt/tag/DoubleTag.php index f0eb71f63..e60647daf 100644 --- a/src/pocketmine/nbt/tag/DoubleTag.php +++ b/src/pocketmine/nbt/tag/DoubleTag.php @@ -29,6 +29,16 @@ use pocketmine\nbt\NBT; class DoubleTag extends NamedTag{ + /** + * DoubleTag constructor. + * + * @param string $name + * @param float $value + */ + public function __construct(string $name = "", float $value = 0.0){ + parent::__construct($name, $value); + } + public function getType(){ return NBT::TAG_Double; } @@ -40,4 +50,23 @@ class DoubleTag extends NamedTag{ public function write(NBT $nbt, bool $network = false){ $nbt->putDouble($this->value); } + + /** + * @return float + */ + public function &getValue() : float{ + return parent::getValue(); + } + + /** + * @param float $value + * + * @throws \TypeError + */ + public function setValue($value){ + if(!is_float($value) and !is_int($value)){ + throw new \TypeError("DoubleTag value must be of type double, " . gettype($value) . " given"); + } + parent::setValue((float) $value); + } } \ No newline at end of file diff --git a/src/pocketmine/nbt/tag/FloatTag.php b/src/pocketmine/nbt/tag/FloatTag.php index 2201aa427..b0cea1fb3 100644 --- a/src/pocketmine/nbt/tag/FloatTag.php +++ b/src/pocketmine/nbt/tag/FloatTag.php @@ -29,6 +29,16 @@ use pocketmine\nbt\NBT; class FloatTag extends NamedTag{ + /** + * FloatTag constructor. + * + * @param string $name + * @param float $value + */ + public function __construct(string $name = "", float $value = 0.0){ + parent::__construct($name, $value); + } + public function getType(){ return NBT::TAG_Float; } @@ -40,4 +50,18 @@ class FloatTag extends NamedTag{ public function write(NBT $nbt, bool $network = false){ $nbt->putFloat($this->value); } + + /** + * @return float + */ + public function &getValue() : float{ + return parent::getValue(); + } + + public function setValue($value){ + if(!is_float($value) and !is_int($value)){ + throw new \TypeError("FloatTag value must be of type float, " . gettype($value) . " given"); + } + parent::setValue((float) $value); + } } \ No newline at end of file diff --git a/src/pocketmine/nbt/tag/IntArrayTag.php b/src/pocketmine/nbt/tag/IntArrayTag.php index 1a507e777..f409f7fb6 100644 --- a/src/pocketmine/nbt/tag/IntArrayTag.php +++ b/src/pocketmine/nbt/tag/IntArrayTag.php @@ -29,6 +29,16 @@ use pocketmine\nbt\NBT; class IntArrayTag extends NamedTag{ + /** + * IntArrayTag constructor. + * + * @param string $name + * @param int[] $value + */ + public function __construct(string $name = "", array $value = []){ + parent::__construct($name, $value); + } + public function getType(){ return NBT::TAG_IntArray; } @@ -48,4 +58,27 @@ class IntArrayTag extends NamedTag{ $str .= implode(", ", $this->value); return $str . "}"; } + + /** + * @return int[] + */ + public function &getValue() : array{ + return parent::getValue(); + } + + /** + * @param int[] $value + * + * @throws \TypeError + */ + public function setValue($value){ + if(!is_array($value)){ + throw new \TypeError("IntArrayTag value must be of type int[], " . gettype($value) . " given"); + } + assert(count(array_filter($value, function($v){ + return !is_int($v); + })) === 0); + + parent::setValue($value); + } } diff --git a/src/pocketmine/nbt/tag/IntTag.php b/src/pocketmine/nbt/tag/IntTag.php index 77580f9c0..990433808 100644 --- a/src/pocketmine/nbt/tag/IntTag.php +++ b/src/pocketmine/nbt/tag/IntTag.php @@ -29,6 +29,14 @@ use pocketmine\nbt\NBT; class IntTag extends NamedTag{ + /** + * @param string $name + * @param int $value + */ + public function __construct(string $name = "", int $value = 0){ + parent::__construct($name, $value); + } + public function getType(){ return NBT::TAG_Int; } @@ -40,4 +48,25 @@ class IntTag extends NamedTag{ public function write(NBT $nbt, bool $network = false){ $nbt->putInt($this->value, $network); } + + /** + * @return int + */ + public function &getValue() : int{ + return parent::getValue(); + } + + /** + * @param int $value + * + * @throws \TypeError + */ + public function setValue($value){ + if(!is_int($value)){ + throw new \TypeError("IntTag value must be of type int, " . gettype($value) . " given"); + }elseif($value < -(2 ** 31) or $value > ((2 ** 31) - 1)){ + throw new \InvalidArgumentException("Value $value is too large!"); + } + parent::setValue($value); + } } \ No newline at end of file diff --git a/src/pocketmine/nbt/tag/ListTag.php b/src/pocketmine/nbt/tag/ListTag.php index 23197dbd1..ac6d709fd 100644 --- a/src/pocketmine/nbt/tag/ListTag.php +++ b/src/pocketmine/nbt/tag/ListTag.php @@ -31,14 +31,20 @@ class ListTag extends NamedTag implements \ArrayAccess, \Countable{ private $tagType = NBT::TAG_End; - public function __construct($name = "", $value = []){ - $this->__name = $name; - foreach($value as $k => $v){ - $this->{$k} = $v; - } + /** + * ListTag constructor. + * + * @param string $name + * @param NamedTag[] $value + */ + public function __construct(string $name = "", array $value = []){ + parent::__construct($name, $value); } - public function &getValue(){ + /** + * @return NamedTag[] + */ + public function &getValue() : array{ $value = []; foreach($this as $k => $v){ if($v instanceof Tag){ @@ -49,13 +55,22 @@ class ListTag extends NamedTag implements \ArrayAccess, \Countable{ return $value; } + /** + * @param NamedTag[] $value + * + * @throws \TypeError + */ public function setValue($value){ if(is_array($value)){ foreach($value as $name => $tag){ if($tag instanceof NamedTag){ $this->{$name} = $tag; + }else{ + throw new \TypeError("ListTag members must be NamedTags, got " . gettype($tag) . " in given array"); } } + }else{ + throw new \TypeError("ListTag value must be NamedTag[], " . gettype($value) . " given"); } } diff --git a/src/pocketmine/nbt/tag/LongTag.php b/src/pocketmine/nbt/tag/LongTag.php index d5b907289..867e07077 100644 --- a/src/pocketmine/nbt/tag/LongTag.php +++ b/src/pocketmine/nbt/tag/LongTag.php @@ -29,6 +29,16 @@ use pocketmine\nbt\NBT; class LongTag extends NamedTag{ + /** + * LongTag constructor. + * + * @param string $name + * @param int $value + */ + public function __construct(string $name = "", int $value = 0){ + parent::__construct($name, $value); + } + public function getType(){ return NBT::TAG_Long; } diff --git a/src/pocketmine/nbt/tag/NamedTag.php b/src/pocketmine/nbt/tag/NamedTag.php index b7d29774c..745bbe1e2 100644 --- a/src/pocketmine/nbt/tag/NamedTag.php +++ b/src/pocketmine/nbt/tag/NamedTag.php @@ -29,13 +29,13 @@ abstract class NamedTag extends Tag{ protected $__name; /** - * @param string $name - * @param bool|float|double|int|ByteTag|ShortTag|array|CompoundTag|ListTag|string $value + * @param string $name + * @param mixed $value */ - public function __construct($name = "", $value = null){ + public function __construct(string $name = "", $value = null){ $this->__name = ($name === null or $name === false) ? "" : $name; if($value !== null){ - $this->value = $value; + $this->setValue($value); } } diff --git a/src/pocketmine/nbt/tag/ShortTag.php b/src/pocketmine/nbt/tag/ShortTag.php index 707907de2..9317f0a98 100644 --- a/src/pocketmine/nbt/tag/ShortTag.php +++ b/src/pocketmine/nbt/tag/ShortTag.php @@ -29,6 +29,16 @@ use pocketmine\nbt\NBT; class ShortTag extends NamedTag{ + /** + * ShortTag constructor. + * + * @param string $name + * @param int $value + */ + public function __construct(string $name = "", int $value = 0){ + parent::__construct($name, $value); + } + public function getType(){ return NBT::TAG_Short; } @@ -40,4 +50,25 @@ class ShortTag extends NamedTag{ public function write(NBT $nbt, bool $network = false){ $nbt->putShort($this->value); } + + /** + * @return int + */ + public function &getValue() : int{ + return parent::getValue(); // TODO: Change the autogenerated stub + } + + /** + * @param int $value + * + * @throws \TypeError + */ + public function setValue($value){ + if(!is_int($value)){ + throw new \TypeError("ShortTag value must be of type int, " . gettype($value) . " given"); + }elseif($value < -(2 ** 15) or $value > ((2 ** 15) - 1)){ + throw new \InvalidArgumentException("Value $value is too large!"); + } + parent::setValue($value); + } } \ No newline at end of file diff --git a/src/pocketmine/nbt/tag/StringTag.php b/src/pocketmine/nbt/tag/StringTag.php index d44b440e8..1f3e1c41b 100644 --- a/src/pocketmine/nbt/tag/StringTag.php +++ b/src/pocketmine/nbt/tag/StringTag.php @@ -29,6 +29,16 @@ use pocketmine\nbt\NBT; class StringTag extends NamedTag{ + /** + * StringTag constructor. + * + * @param string $name + * @param string $value + */ + public function __construct(string $name = "", string $value = ""){ + parent::__construct($name, $value); + } + public function getType(){ return NBT::TAG_String; } @@ -40,4 +50,23 @@ class StringTag extends NamedTag{ public function write(NBT $nbt, bool $network = false){ $nbt->putString($this->value, $network); } + + /** + * @return string + */ + public function &getValue() : string{ + return parent::getValue(); + } + + /** + * @param string $value + * + * @throws \TypeError + */ + public function setValue($value){ + if(!is_string($value)){ + throw new \TypeError("ShortTag value must be of type int, " . gettype($value) . " given"); + } + parent::setValue($value); + } } \ No newline at end of file diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index 708c3b789..c3df50689 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -190,15 +190,24 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ } } - public function getName(){ + /** + * @return string + */ + public function getName() : string{ return isset($this->namedtag->CustomName) ? $this->namedtag->CustomName->getValue() : "Chest"; } - public function hasName(){ + /** + * @return bool + */ + public function hasName() : bool{ return isset($this->namedtag->CustomName); } - public function setName($str){ + /** + * @param string $str + */ + public function setName(string $str){ if($str === ""){ unset($this->namedtag->CustomName); return; diff --git a/src/pocketmine/tile/EnchantTable.php b/src/pocketmine/tile/EnchantTable.php index d6ff0ba32..aa16bd4a4 100644 --- a/src/pocketmine/tile/EnchantTable.php +++ b/src/pocketmine/tile/EnchantTable.php @@ -30,15 +30,15 @@ use pocketmine\nbt\tag\StringTag; class EnchantTable extends Spawnable implements Nameable{ - public function getName(){ + public function getName() : string{ return isset($this->namedtag->CustomName) ? $this->namedtag->CustomName->getValue() : "Enchanting Table"; } - public function hasName(){ + public function hasName() : bool{ return isset($this->namedtag->CustomName); } - public function setName($str){ + public function setName(string $str){ if($str === ""){ unset($this->namedtag->CustomName); return; diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index e960e73d8..574df3d27 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -72,15 +72,15 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ } } - public function getName(){ + public function getName() : string{ return isset($this->namedtag->CustomName) ? $this->namedtag->CustomName->getValue() : "Furnace"; } - public function hasName(){ + public function hasName() : bool{ return isset($this->namedtag->CustomName); } - public function setName($str){ + public function setName(string $str){ if($str === ""){ unset($this->namedtag->CustomName); return; @@ -228,11 +228,11 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ } if($this->namedtag["BurnTime"] > 0){ - $this->namedtag->BurnTime = new ShortTag("BurnTime", $this->namedtag["BurnTime"] - 1); + $this->namedtag->BurnTime = new ShortTag("BurnTime", ((int) $this->namedtag["BurnTime"]) - 1); $this->namedtag->BurnTicks = new ShortTag("BurnTicks", (int) ceil(($this->namedtag["BurnTime"] / $this->namedtag["MaxTime"] * 200))); if($smelt instanceof FurnaceRecipe and $canSmelt){ - $this->namedtag->CookTime = new ShortTag("CookTime", $this->namedtag["CookTime"] + 1); + $this->namedtag->CookTime = new ShortTag("CookTime", (int) ($this->namedtag["CookTime"]) + 1); if($this->namedtag["CookTime"] >= 200){ //10 seconds $product = Item::get($smelt->getResult()->getId(), $smelt->getResult()->getDamage(), $product->getCount() + 1); @@ -247,7 +247,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ $this->inventory->setSmelting($raw); } - $this->namedtag->CookTime = new ShortTag("CookTime", $this->namedtag["CookTime"] - 200); + $this->namedtag->CookTime = new ShortTag("CookTime", ((int) $this->namedtag["CookTime"]) - 200); } }elseif($this->namedtag["BurnTime"] <= 0){ $this->namedtag->BurnTime = new ShortTag("BurnTime", 0); @@ -297,8 +297,8 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ new IntTag("x", (int) $this->x), new IntTag("y", (int) $this->y), new IntTag("z", (int) $this->z), - new ShortTag("BurnTime", $this->namedtag["BurnTime"]), - new ShortTag("CookTime", $this->namedtag["CookTime"]) + new ShortTag("BurnTime", (int) $this->namedtag["BurnTime"]), + new ShortTag("CookTime", (int) $this->namedtag["CookTime"]) ]); if($this->hasName()){ diff --git a/src/pocketmine/tile/Nameable.php b/src/pocketmine/tile/Nameable.php index 6651c927d..43a1a9154 100644 --- a/src/pocketmine/tile/Nameable.php +++ b/src/pocketmine/tile/Nameable.php @@ -30,15 +30,15 @@ interface Nameable{ /** * @return string */ - public function getName(); + public function getName() : string; /** - * @param void $str + * @param string $str */ - public function setName($str); + public function setName(string $str); /** * @return bool */ - public function hasName(); + public function hasName() : bool; }