mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-26 13:19:55 +00:00
Remove all usages of CompoundTag->hasTag()
in pretty much every case, these usages really wanted to read the tag's contents anyway, which can be combined with a getTag() and instanceof call for more concise and static analysis friendly code. In the few cases where the tag contents wasn't needed, it still wanted to check the type, which, again, can be done in a more static analysis friendly way by just using getTag() and instanceof.
This commit is contained in:
parent
91b028c208
commit
279abb871d
@ -61,8 +61,8 @@ class Banner extends Spawnable{
|
|||||||
|
|
||||||
public function readSaveData(CompoundTag $nbt) : void{
|
public function readSaveData(CompoundTag $nbt) : void{
|
||||||
$colorIdMap = DyeColorIdMap::getInstance();
|
$colorIdMap = DyeColorIdMap::getInstance();
|
||||||
if($nbt->hasTag(self::TAG_BASE, IntTag::class)){
|
if(($baseColorTag = $nbt->getTag(self::TAG_BASE)) instanceof IntTag){
|
||||||
$this->baseColor = $colorIdMap->fromInvertedId($nbt->getInt(self::TAG_BASE));
|
$this->baseColor = $colorIdMap->fromInvertedId($baseColorTag->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
$patterns = $nbt->getListTag(self::TAG_PATTERNS);
|
$patterns = $nbt->getListTag(self::TAG_PATTERNS);
|
||||||
|
@ -49,8 +49,8 @@ class Bed extends Spawnable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function readSaveData(CompoundTag $nbt) : void{
|
public function readSaveData(CompoundTag $nbt) : void{
|
||||||
if($nbt->hasTag(self::TAG_COLOR, ByteTag::class)){
|
if(($colorTag = $nbt->getTag(self::TAG_COLOR)) instanceof ByteTag){
|
||||||
$this->color = DyeColorIdMap::getInstance()->fromId($nbt->getByte(self::TAG_COLOR));
|
$this->color = DyeColorIdMap::getInstance()->fromId($colorTag->getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,9 +59,9 @@ class Chest extends Spawnable implements Container, Nameable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function readSaveData(CompoundTag $nbt) : void{
|
public function readSaveData(CompoundTag $nbt) : void{
|
||||||
if($nbt->hasTag(self::TAG_PAIRX, IntTag::class) and $nbt->hasTag(self::TAG_PAIRZ, IntTag::class)){
|
if(($pairXTag = $nbt->getTag(self::TAG_PAIRX)) instanceof IntTag and ($pairZTag = $nbt->getTag(self::TAG_PAIRZ)) instanceof IntTag){
|
||||||
$pairX = $nbt->getInt(self::TAG_PAIRX);
|
$pairX = $pairXTag->getValue();
|
||||||
$pairZ = $nbt->getInt(self::TAG_PAIRZ);
|
$pairZ = $pairZTag->getValue();
|
||||||
if(
|
if(
|
||||||
($this->pos->x === $pairX and abs($this->pos->z - $pairZ) === 1) or
|
($this->pos->x === $pairX and abs($this->pos->z - $pairZ) === 1) or
|
||||||
($this->pos->z === $pairZ and abs($this->pos->x - $pairX) === 1)
|
($this->pos->z === $pairZ and abs($this->pos->x - $pairX) === 1)
|
||||||
|
@ -56,8 +56,8 @@ trait ContainerTrait{
|
|||||||
$inventory->getListeners()->add(...$listeners);
|
$inventory->getListeners()->add(...$listeners);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($tag->hasTag(Container::TAG_LOCK, StringTag::class)){
|
if(($lockTag = $tag->getTag(Container::TAG_LOCK)) instanceof StringTag){
|
||||||
$this->lock = $tag->getString(Container::TAG_LOCK);
|
$this->lock = $lockTag->getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,9 +42,9 @@ class FlowerPot extends Spawnable{
|
|||||||
private $plant = null;
|
private $plant = null;
|
||||||
|
|
||||||
public function readSaveData(CompoundTag $nbt) : void{
|
public function readSaveData(CompoundTag $nbt) : void{
|
||||||
if($nbt->hasTag(self::TAG_ITEM, ShortTag::class) and $nbt->hasTag(self::TAG_ITEM_DATA, IntTag::class)){
|
if(($itemIdTag = $nbt->getTag(self::TAG_ITEM)) instanceof ShortTag and ($itemMetaTag = $nbt->getTag(self::TAG_ITEM_DATA)) instanceof IntTag){
|
||||||
try{
|
try{
|
||||||
$this->setPlant(BlockFactory::getInstance()->get($nbt->getShort(self::TAG_ITEM), $nbt->getInt(self::TAG_ITEM_DATA)));
|
$this->setPlant(BlockFactory::getInstance()->get($itemIdTag->getValue(), $itemMetaTag->getValue()));
|
||||||
}catch(\InvalidArgumentException $e){
|
}catch(\InvalidArgumentException $e){
|
||||||
//noop
|
//noop
|
||||||
}
|
}
|
||||||
|
@ -95,11 +95,11 @@ class MonsterSpawner extends Spawnable{
|
|||||||
private $requiredPlayerRange = self::DEFAULT_REQUIRED_PLAYER_RANGE;
|
private $requiredPlayerRange = self::DEFAULT_REQUIRED_PLAYER_RANGE;
|
||||||
|
|
||||||
public function readSaveData(CompoundTag $nbt) : void{
|
public function readSaveData(CompoundTag $nbt) : void{
|
||||||
if($nbt->hasTag(self::TAG_LEGACY_ENTITY_TYPE_ID, IntTag::class)){
|
if(($legacyIdTag = $nbt->getTag(self::TAG_LEGACY_ENTITY_TYPE_ID)) instanceof IntTag){
|
||||||
//TODO: this will cause unexpected results when there's no mapping for the entity
|
//TODO: this will cause unexpected results when there's no mapping for the entity
|
||||||
$this->entityTypeId = LegacyEntityIdToStringIdMap::getInstance()->legacyToString($nbt->getInt(self::TAG_LEGACY_ENTITY_TYPE_ID)) ?? ":";
|
$this->entityTypeId = LegacyEntityIdToStringIdMap::getInstance()->legacyToString($legacyIdTag->getValue()) ?? ":";
|
||||||
}elseif($nbt->hasTag(self::TAG_ENTITY_TYPE_ID, StringTag::class)){
|
}elseif(($idTag = $nbt->getTag(self::TAG_ENTITY_TYPE_ID)) instanceof StringTag){
|
||||||
$this->entityTypeId = $nbt->getString(self::TAG_ENTITY_TYPE_ID);
|
$this->entityTypeId = $idTag->getValue();
|
||||||
}else{
|
}else{
|
||||||
$this->entityTypeId = ":"; //default - TODO: replace this with a constant
|
$this->entityTypeId = ":"; //default - TODO: replace this with a constant
|
||||||
}
|
}
|
||||||
|
@ -59,8 +59,8 @@ trait NameableTrait{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function loadName(CompoundTag $tag) : void{
|
protected function loadName(CompoundTag $tag) : void{
|
||||||
if($tag->hasTag(Nameable::TAG_CUSTOM_NAME, StringTag::class)){
|
if(($customNameTag = $tag->getTag(Nameable::TAG_CUSTOM_NAME)) instanceof StringTag){
|
||||||
$this->customName = $tag->getString(Nameable::TAG_CUSTOM_NAME);
|
$this->customName = $customNameTag->getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,14 +59,14 @@ class Sign extends Spawnable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function readSaveData(CompoundTag $nbt) : void{
|
public function readSaveData(CompoundTag $nbt) : void{
|
||||||
if($nbt->hasTag(self::TAG_TEXT_BLOB, StringTag::class)){ //MCPE 1.2 save format
|
if(($textBlobTag = $nbt->getTag(self::TAG_TEXT_BLOB)) instanceof StringTag){ //MCPE 1.2 save format
|
||||||
$this->text = SignText::fromBlob(mb_scrub($nbt->getString(self::TAG_TEXT_BLOB), 'UTF-8'));
|
$this->text = SignText::fromBlob(mb_scrub($textBlobTag->getValue(), 'UTF-8'));
|
||||||
}else{
|
}else{
|
||||||
$text = [];
|
$text = [];
|
||||||
for($i = 0; $i < SignText::LINE_COUNT; ++$i){
|
for($i = 0; $i < SignText::LINE_COUNT; ++$i){
|
||||||
$textKey = sprintf(self::TAG_TEXT_LINE, $i + 1);
|
$textKey = sprintf(self::TAG_TEXT_LINE, $i + 1);
|
||||||
if($nbt->hasTag($textKey, StringTag::class)){
|
if(($lineTag = $nbt->getTag($textKey)) instanceof StringTag){
|
||||||
$text[$i] = mb_scrub($nbt->getString($textKey), 'UTF-8');
|
$text[$i] = mb_scrub($lineTag->getValue(), 'UTF-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->text = new SignText($text);
|
$this->text = new SignText($text);
|
||||||
|
@ -51,9 +51,9 @@ class Skull extends Spawnable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function readSaveData(CompoundTag $nbt) : void{
|
public function readSaveData(CompoundTag $nbt) : void{
|
||||||
if($nbt->hasTag(self::TAG_SKULL_TYPE, ByteTag::class)){
|
if(($skullTypeTag = $nbt->getTag(self::TAG_SKULL_TYPE)) instanceof ByteTag){
|
||||||
try{
|
try{
|
||||||
$this->skullType = SkullType::fromMagicNumber($nbt->getByte(self::TAG_SKULL_TYPE));
|
$this->skullType = SkullType::fromMagicNumber($skullTypeTag->getValue());
|
||||||
}catch(\InvalidArgumentException $e){
|
}catch(\InvalidArgumentException $e){
|
||||||
//bad data, drop it
|
//bad data, drop it
|
||||||
}
|
}
|
||||||
|
@ -481,12 +481,12 @@ abstract class Entity{
|
|||||||
|
|
||||||
$this->fallDistance = $nbt->getFloat("FallDistance", 0.0);
|
$this->fallDistance = $nbt->getFloat("FallDistance", 0.0);
|
||||||
|
|
||||||
if($nbt->hasTag("CustomName", StringTag::class)){
|
if(($customNameTag = $nbt->getTag("CustomName")) instanceof StringTag){
|
||||||
$this->setNameTag($nbt->getString("CustomName"));
|
$this->setNameTag($customNameTag->getValue());
|
||||||
|
|
||||||
if($nbt->hasTag("CustomNameVisible", StringTag::class)){
|
if(($customNameVisibleTag = $nbt->getTag("CustomNameVisible")) instanceof StringTag){
|
||||||
//Older versions incorrectly saved this as a string (see 890f72dbf23a77f294169b79590770470041adc4)
|
//Older versions incorrectly saved this as a string (see 890f72dbf23a77f294169b79590770470041adc4)
|
||||||
$this->setNameTagVisible($nbt->getString("CustomNameVisible") !== "");
|
$this->setNameTagVisible($customNameVisibleTag->getValue() !== "");
|
||||||
}else{
|
}else{
|
||||||
$this->setNameTagVisible($nbt->getByte("CustomNameVisible", 1) !== 0);
|
$this->setNameTagVisible($nbt->getByte("CustomNameVisible", 1) !== 0);
|
||||||
}
|
}
|
||||||
|
@ -118,10 +118,10 @@ final class EntityFactory{
|
|||||||
throw new \UnexpectedValueException("Unknown painting motive");
|
throw new \UnexpectedValueException("Unknown painting motive");
|
||||||
}
|
}
|
||||||
$blockIn = new Vector3($nbt->getInt("TileX"), $nbt->getInt("TileY"), $nbt->getInt("TileZ"));
|
$blockIn = new Vector3($nbt->getInt("TileX"), $nbt->getInt("TileY"), $nbt->getInt("TileZ"));
|
||||||
if($nbt->hasTag("Direction", ByteTag::class)){
|
if(($directionTag = $nbt->getTag("Direction")) instanceof ByteTag){
|
||||||
$facing = Painting::DATA_TO_FACING[$nbt->getByte("Direction")] ?? Facing::NORTH;
|
$facing = Painting::DATA_TO_FACING[$directionTag->getValue()] ?? Facing::NORTH;
|
||||||
}elseif($nbt->hasTag("Facing", ByteTag::class)){
|
}elseif(($facingTag = $nbt->getTag("Facing")) instanceof ByteTag){
|
||||||
$facing = Painting::DATA_TO_FACING[$nbt->getByte("Facing")] ?? Facing::NORTH;
|
$facing = Painting::DATA_TO_FACING[$facingTag->getValue()] ?? Facing::NORTH;
|
||||||
}else{
|
}else{
|
||||||
throw new \UnexpectedValueException("Missing facing info");
|
throw new \UnexpectedValueException("Missing facing info");
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
|
|||||||
}
|
}
|
||||||
return new Skin( //this throws if the skin is invalid
|
return new Skin( //this throws if the skin is invalid
|
||||||
$skinTag->getString("Name"),
|
$skinTag->getString("Name"),
|
||||||
$skinTag->hasTag("Data", StringTag::class) ? $skinTag->getString("Data") : $skinTag->getByteArray("Data"), //old data (this used to be saved as a StringTag in older versions of PM)
|
($skinDataTag = $skinTag->getTag("Data")) instanceof StringTag ? $skinDataTag->getValue() : $skinTag->getByteArray("Data"), //old data (this used to be saved as a StringTag in older versions of PM)
|
||||||
$skinTag->getByteArray("CapeData", ""),
|
$skinTag->getByteArray("CapeData", ""),
|
||||||
$skinTag->getString("GeometryName", ""),
|
$skinTag->getString("GeometryName", ""),
|
||||||
$skinTag->getByteArray("GeometryData", "")
|
$skinTag->getByteArray("GeometryData", "")
|
||||||
@ -194,8 +194,8 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
|
|||||||
* For Human entities which are not players, sets their properties such as nametag, skin and UUID from NBT.
|
* For Human entities which are not players, sets their properties such as nametag, skin and UUID from NBT.
|
||||||
*/
|
*/
|
||||||
protected function initHumanData(CompoundTag $nbt) : void{
|
protected function initHumanData(CompoundTag $nbt) : void{
|
||||||
if($nbt->hasTag("NameTag", StringTag::class)){
|
if(($nameTagTag = $nbt->getTag("NameTag")) instanceof StringTag){
|
||||||
$this->setNameTag($nbt->getString("NameTag"));
|
$this->setNameTag($nameTagTag->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->uuid = UUID::fromData((string) $this->getId(), $this->skin->getSkinData(), $this->getNameTag());
|
$this->uuid = UUID::fromData((string) $this->getId(), $this->skin->getSkinData(), $this->getNameTag());
|
||||||
@ -251,8 +251,8 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
|
|||||||
$nbt->getFloat("XpP", 0.0));
|
$nbt->getFloat("XpP", 0.0));
|
||||||
$this->xpManager->setLifetimeTotalXp($nbt->getInt("XpTotal", 0));
|
$this->xpManager->setLifetimeTotalXp($nbt->getInt("XpTotal", 0));
|
||||||
|
|
||||||
if($nbt->hasTag("XpSeed", IntTag::class)){
|
if(($xpSeedTag = $nbt->getTag("XpSeed")) instanceof IntTag){
|
||||||
$this->xpSeed = $nbt->getInt("XpSeed");
|
$this->xpSeed = $xpSeedTag->getValue();
|
||||||
}else{
|
}else{
|
||||||
$this->xpSeed = random_int(Limits::INT32_MIN, Limits::INT32_MAX);
|
$this->xpSeed = random_int(Limits::INT32_MIN, Limits::INT32_MAX);
|
||||||
}
|
}
|
||||||
|
@ -134,12 +134,12 @@ abstract class Living extends Entity{
|
|||||||
|
|
||||||
$health = $this->getMaxHealth();
|
$health = $this->getMaxHealth();
|
||||||
|
|
||||||
if($nbt->hasTag("HealF", FloatTag::class)){
|
if(($healFTag = $nbt->getTag("HealF")) instanceof FloatTag){
|
||||||
$health = $nbt->getFloat("HealF");
|
$health = $healFTag->getValue();
|
||||||
}elseif($nbt->hasTag("Health", ShortTag::class)){
|
}elseif(($healthTag = $nbt->getTag("Health")) instanceof ShortTag){
|
||||||
$health = $nbt->getShort("Health"); //Older versions of PocketMine-MP incorrectly saved this as a short instead of a float
|
$health = $healthTag->getValue(); //Older versions of PocketMine-MP incorrectly saved this as a short instead of a float
|
||||||
}elseif($nbt->hasTag("Health", FloatTag::class)){
|
}elseif(($healthTag = $nbt->getTag("Health")) instanceof FloatTag){
|
||||||
$health = $nbt->getFloat("Health");
|
$health = $healthTag->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setHealth($health);
|
$this->setHealth($health);
|
||||||
|
@ -108,10 +108,10 @@ class ExperienceOrb extends Entity{
|
|||||||
$this->age = $nbt->getShort("Age", 0);
|
$this->age = $nbt->getShort("Age", 0);
|
||||||
|
|
||||||
$value = 1;
|
$value = 1;
|
||||||
if($nbt->hasTag(self::TAG_VALUE_PC, ShortTag::class)){ //PC
|
if(($valuePcTag = $nbt->getTag(self::TAG_VALUE_PC)) instanceof ShortTag){ //PC
|
||||||
$value = $nbt->getShort(self::TAG_VALUE_PC);
|
$value = $valuePcTag->getValue();
|
||||||
}elseif($nbt->hasTag(self::TAG_VALUE_PE, IntTag::class)){ //PE save format
|
}elseif(($valuePeTag = $nbt->getTag(self::TAG_VALUE_PE)) instanceof IntTag){ //PE save format
|
||||||
$value = $nbt->getInt(self::TAG_VALUE_PE);
|
$value = $valuePeTag->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setXpValue($value);
|
$this->setXpValue($value);
|
||||||
|
@ -64,10 +64,10 @@ class FallingBlock extends Entity{
|
|||||||
$blockId = 0;
|
$blockId = 0;
|
||||||
|
|
||||||
//TODO: 1.8+ save format
|
//TODO: 1.8+ save format
|
||||||
if($nbt->hasTag("TileID", IntTag::class)){
|
if(($tileIdTag = $nbt->getTag("TileID")) instanceof IntTag){
|
||||||
$blockId = $nbt->getInt("TileID");
|
$blockId = $tileIdTag->getValue();
|
||||||
}elseif($nbt->hasTag("Tile", ByteTag::class)){
|
}elseif(($tileTag = $nbt->getTag("Tile")) instanceof ByteTag){
|
||||||
$blockId = $nbt->getByte("Tile");
|
$blockId = $tileTag->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
if($blockId === 0){
|
if($blockId === 0){
|
||||||
|
@ -82,20 +82,20 @@ abstract class Projectile extends Entity{
|
|||||||
$blockId = null;
|
$blockId = null;
|
||||||
$blockData = null;
|
$blockData = null;
|
||||||
|
|
||||||
if($nbt->hasTag("tileX", IntTag::class) and $nbt->hasTag("tileY", IntTag::class) and $nbt->hasTag("tileZ", IntTag::class)){
|
if(($tileXTag = $nbt->getTag("tileX")) instanceof IntTag and ($tileYTag = $nbt->getTag("tileY")) instanceof IntTag and ($tileZTag = $nbt->getTag("tileZ")) instanceof IntTag){
|
||||||
$blockPos = new Vector3($nbt->getInt("tileX"), $nbt->getInt("tileY"), $nbt->getInt("tileZ"));
|
$blockPos = new Vector3($tileXTag->getValue(), $tileYTag->getValue(), $tileZTag->getValue());
|
||||||
}else{
|
}else{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($nbt->hasTag("blockId", IntTag::class)){
|
if(($blockIdTag = $nbt->getTag("blockId")) instanceof IntTag){
|
||||||
$blockId = $nbt->getInt("blockId");
|
$blockId = $blockIdTag->getValue();
|
||||||
}else{
|
}else{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($nbt->hasTag("blockData", ByteTag::class)){
|
if(($blockDataTag = $nbt->getTag("blockData")) instanceof ByteTag){
|
||||||
$blockData = $nbt->getByte("blockData");
|
$blockData = $blockDataTag->getValue();
|
||||||
}else{
|
}else{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -133,8 +133,8 @@ class Armor extends Durable{
|
|||||||
|
|
||||||
protected function deserializeCompoundTag(CompoundTag $tag) : void{
|
protected function deserializeCompoundTag(CompoundTag $tag) : void{
|
||||||
parent::deserializeCompoundTag($tag);
|
parent::deserializeCompoundTag($tag);
|
||||||
if($tag->hasTag(self::TAG_CUSTOM_COLOR, IntTag::class)){
|
if(($colorTag = $tag->getTag(self::TAG_CUSTOM_COLOR)) instanceof IntTag){
|
||||||
$this->customColor = Color::fromARGB(Binary::unsignInt($tag->getInt(self::TAG_CUSTOM_COLOR)));
|
$this->customColor = Color::fromARGB(Binary::unsignInt($colorTag->getValue()));
|
||||||
}else{
|
}else{
|
||||||
$this->customColor = null;
|
$this->customColor = null;
|
||||||
}
|
}
|
||||||
|
@ -647,7 +647,7 @@ class Item implements \JsonSerializable{
|
|||||||
* Deserializes an Item from an NBT CompoundTag
|
* Deserializes an Item from an NBT CompoundTag
|
||||||
*/
|
*/
|
||||||
public static function nbtDeserialize(CompoundTag $tag) : Item{
|
public static function nbtDeserialize(CompoundTag $tag) : Item{
|
||||||
if(!$tag->hasTag("id") or !$tag->hasTag("Count")){
|
if($tag->getTag("id") === null or $tag->getTag("Count") === null){
|
||||||
return ItemFactory::getInstance()->get(0);
|
return ItemFactory::getInstance()->get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,8 +137,8 @@ class TypeConverter{
|
|||||||
|
|
||||||
if($compound !== null){
|
if($compound !== null){
|
||||||
$compound = clone $compound;
|
$compound = clone $compound;
|
||||||
if($compound->hasTag(self::DAMAGE_TAG, IntTag::class)){
|
if(($damageTag = $compound->getTag(self::DAMAGE_TAG)) instanceof IntTag){
|
||||||
$meta = $compound->getInt(self::DAMAGE_TAG);
|
$meta = $damageTag->getValue();
|
||||||
$compound->removeTag(self::DAMAGE_TAG);
|
$compound->removeTag(self::DAMAGE_TAG);
|
||||||
if($compound->count() === 0){
|
if($compound->count() === 0){
|
||||||
$compound = null;
|
$compound = null;
|
||||||
|
@ -598,9 +598,9 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
if(!($nbt instanceof CompoundTag)) throw new AssumptionFailedError("PHPStan should ensure this is a CompoundTag"); //for phpstorm's benefit
|
if(!($nbt instanceof CompoundTag)) throw new AssumptionFailedError("PHPStan should ensure this is a CompoundTag"); //for phpstorm's benefit
|
||||||
|
|
||||||
if($block instanceof Sign){
|
if($block instanceof Sign){
|
||||||
if($nbt->hasTag("Text", StringTag::class)){
|
if(($textBlobTag = $nbt->getTag("Text")) instanceof StringTag){
|
||||||
try{
|
try{
|
||||||
$text = SignText::fromBlob($nbt->getString("Text"));
|
$text = SignText::fromBlob($textBlobTag->getValue());
|
||||||
}catch(\InvalidArgumentException $e){
|
}catch(\InvalidArgumentException $e){
|
||||||
throw BadPacketException::wrap($e, "Invalid sign text update");
|
throw BadPacketException::wrap($e, "Invalid sign text update");
|
||||||
}
|
}
|
||||||
|
@ -99,11 +99,11 @@ class OfflinePlayer implements IPlayer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getFirstPlayed() : ?int{
|
public function getFirstPlayed() : ?int{
|
||||||
return ($this->namedtag !== null and $this->namedtag->hasTag("firstPlayed", LongTag::class)) ? $this->namedtag->getLong("firstPlayed") : null;
|
return ($this->namedtag !== null and ($firstPlayedTag = $this->namedtag->getTag("firstPlayed")) instanceof LongTag) ? $firstPlayedTag->getValue() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLastPlayed() : ?int{
|
public function getLastPlayed() : ?int{
|
||||||
return ($this->namedtag !== null and $this->namedtag->hasTag("lastPlayed", LongTag::class)) ? $this->namedtag->getLong("lastPlayed") : null;
|
return ($this->namedtag !== null and ($lastPlayedTag = $this->namedtag->getTag("lastPlayed")) instanceof LongTag) ? $lastPlayedTag->getValue() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasPlayedBefore() : bool{
|
public function hasPlayedBefore() : bool{
|
||||||
|
@ -334,10 +334,10 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
$this->firstPlayed = $nbt->getLong("firstPlayed", $now = (int) (microtime(true) * 1000));
|
$this->firstPlayed = $nbt->getLong("firstPlayed", $now = (int) (microtime(true) * 1000));
|
||||||
$this->lastPlayed = $nbt->getLong("lastPlayed", $now);
|
$this->lastPlayed = $nbt->getLong("lastPlayed", $now);
|
||||||
|
|
||||||
if($this->server->getForceGamemode() or !$nbt->hasTag("playerGameType", IntTag::class)){
|
if(!$this->server->getForceGamemode() and ($gameModeTag = $nbt->getTag("playerGameType")) instanceof IntTag){
|
||||||
$this->internalSetGameMode($this->server->getGamemode());
|
$this->internalSetGameMode(GameMode::fromMagicNumber($gameModeTag->getValue() & 0x03)); //TODO: bad hack here to avoid crashes on corrupted data
|
||||||
}else{
|
}else{
|
||||||
$this->internalSetGameMode(GameMode::fromMagicNumber($nbt->getInt("playerGameType") & 0x03)); //TODO: bad hack here to avoid crashes on corrupted data
|
$this->internalSetGameMode($this->server->getGamemode());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->keepMovement = true;
|
$this->keepMovement = true;
|
||||||
|
@ -125,8 +125,8 @@ abstract class BaseNbtWorldData implements WorldData{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getTime() : int{
|
public function getTime() : int{
|
||||||
if($this->compoundTag->hasTag("Time", IntTag::class)){ //some older PM worlds had this in the wrong format
|
if(($timeTag = $this->compoundTag->getTag("Time")) instanceof IntTag){ //some older PM worlds had this in the wrong format
|
||||||
return $this->compoundTag->getInt("Time");
|
return $timeTag->getValue();
|
||||||
}
|
}
|
||||||
return $this->compoundTag->getLong("Time", 0);
|
return $this->compoundTag->getLong("Time", 0);
|
||||||
}
|
}
|
||||||
|
@ -134,9 +134,10 @@ class BedrockWorldData extends BaseNbtWorldData{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function fix() : void{
|
protected function fix() : void{
|
||||||
if(!$this->compoundTag->hasTag("generatorName", StringTag::class)){
|
$generatorNameTag = $this->compoundTag->getTag("generatorName");
|
||||||
if($this->compoundTag->hasTag("Generator", IntTag::class)){
|
if(!($generatorNameTag instanceof StringTag)){
|
||||||
switch($this->compoundTag->getInt("Generator")){ //Detect correct generator from MCPE data
|
if(($mcpeGeneratorTypeTag = $this->compoundTag->getTag("Generator")) instanceof IntTag){
|
||||||
|
switch($mcpeGeneratorTypeTag->getValue()){ //Detect correct generator from MCPE data
|
||||||
case self::GENERATOR_FLAT:
|
case self::GENERATOR_FLAT:
|
||||||
$this->compoundTag->setString("generatorName", "flat");
|
$this->compoundTag->setString("generatorName", "flat");
|
||||||
$this->compoundTag->setString("generatorOptions", "2;7,3,3,2;1");
|
$this->compoundTag->setString("generatorOptions", "2;7,3,3,2;1");
|
||||||
@ -154,11 +155,11 @@ class BedrockWorldData extends BaseNbtWorldData{
|
|||||||
}else{
|
}else{
|
||||||
$this->compoundTag->setString("generatorName", "default");
|
$this->compoundTag->setString("generatorName", "default");
|
||||||
}
|
}
|
||||||
}elseif(($generatorName = self::hackyFixForGeneratorClasspathInLevelDat($this->compoundTag->getString("generatorName"))) !== null){
|
}elseif(($generatorName = self::hackyFixForGeneratorClasspathInLevelDat($generatorNameTag->getValue())) !== null){
|
||||||
$this->compoundTag->setString("generatorName", $generatorName);
|
$this->compoundTag->setString("generatorName", $generatorName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->compoundTag->hasTag("generatorOptions", StringTag::class)){
|
if(!($this->compoundTag->getTag("generatorOptions")) instanceof StringTag){
|
||||||
$this->compoundTag->setString("generatorOptions", "");
|
$this->compoundTag->setString("generatorOptions", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,13 +101,14 @@ class JavaWorldData extends BaseNbtWorldData{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function fix() : void{
|
protected function fix() : void{
|
||||||
if(!$this->compoundTag->hasTag("generatorName", StringTag::class)){
|
$generatorNameTag = $this->compoundTag->getTag("generatorName");
|
||||||
|
if(!($generatorNameTag instanceof StringTag)){
|
||||||
$this->compoundTag->setString("generatorName", "default");
|
$this->compoundTag->setString("generatorName", "default");
|
||||||
}elseif(($generatorName = self::hackyFixForGeneratorClasspathInLevelDat($this->compoundTag->getString("generatorName"))) !== null){
|
}elseif(($generatorName = self::hackyFixForGeneratorClasspathInLevelDat($generatorNameTag->getValue())) !== null){
|
||||||
$this->compoundTag->setString("generatorName", $generatorName);
|
$this->compoundTag->setString("generatorName", $generatorName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->compoundTag->hasTag("generatorOptions", StringTag::class)){
|
if(!($this->compoundTag->getTag("generatorOptions") instanceof StringTag)){
|
||||||
$this->compoundTag->setString("generatorOptions", "");
|
$this->compoundTag->setString("generatorOptions", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,8 +136,8 @@ class JavaWorldData extends BaseNbtWorldData{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getRainLevel() : float{
|
public function getRainLevel() : float{
|
||||||
if($this->compoundTag->hasTag("rainLevel", FloatTag::class)){ //PocketMine/MCPE
|
if(($rainLevelTag = $this->compoundTag->getTag("rainLevel")) instanceof FloatTag){ //PocketMine/MCPE
|
||||||
return $this->compoundTag->getFloat("rainLevel");
|
return $rainLevelTag->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (float) $this->compoundTag->getByte("raining", 0); //PC vanilla
|
return (float) $this->compoundTag->getByte("raining", 0); //PC vanilla
|
||||||
@ -156,8 +157,8 @@ class JavaWorldData extends BaseNbtWorldData{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getLightningLevel() : float{
|
public function getLightningLevel() : float{
|
||||||
if($this->compoundTag->hasTag("lightningLevel", FloatTag::class)){ //PocketMine/MCPE
|
if(($lightningLevelTag = $this->compoundTag->getTag("lightningLevel")) instanceof FloatTag){ //PocketMine/MCPE
|
||||||
return $this->compoundTag->getFloat("lightningLevel");
|
return $lightningLevelTag->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (float) $this->compoundTag->getByte("thundering", 0); //PC vanilla
|
return (float) $this->compoundTag->getByte("thundering", 0); //PC vanilla
|
||||||
|
@ -86,10 +86,10 @@ trait LegacyAnvilChunkTrait{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
$biomeArray = null;
|
$biomeArray = null;
|
||||||
if($chunk->hasTag("BiomeColors", IntArrayTag::class)){
|
if(($biomeColorsTag = $chunk->getTag("BiomeColors")) instanceof IntArrayTag){
|
||||||
$biomeArray = $makeBiomeArray(ChunkUtils::convertBiomeColors($chunk->getIntArray("BiomeColors"))); //Convert back to original format
|
$biomeArray = $makeBiomeArray(ChunkUtils::convertBiomeColors($biomeColorsTag->getValue())); //Convert back to original format
|
||||||
}elseif($chunk->hasTag("Biomes", ByteArrayTag::class)){
|
}elseif(($biomesTag = $chunk->getTag("Biomes")) instanceof ByteArrayTag){
|
||||||
$biomeArray = $makeBiomeArray($chunk->getByteArray("Biomes"));
|
$biomeArray = $makeBiomeArray($biomesTag->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = new Chunk(
|
$result = new Chunk(
|
||||||
|
@ -68,8 +68,8 @@ class McRegion extends RegionWorldProvider{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$subChunks = [];
|
$subChunks = [];
|
||||||
$fullIds = $chunk->hasTag("Blocks", ByteArrayTag::class) ? $chunk->getByteArray("Blocks") : str_repeat("\x00", 32768);
|
$fullIds = ($fullIdsTag = $chunk->getTag("Blocks")) instanceof ByteArrayTag ? $fullIdsTag->getValue() : str_repeat("\x00", 32768);
|
||||||
$fullData = $chunk->hasTag("Data", ByteArrayTag::class) ? $chunk->getByteArray("Data") : str_repeat("\x00", 16384);
|
$fullData = ($fullDataTag = $chunk->getTag("Data")) instanceof ByteArrayTag ? $fullDataTag->getValue() : str_repeat("\x00", 16384);
|
||||||
|
|
||||||
for($y = 0; $y < 8; ++$y){
|
for($y = 0; $y < 8; ++$y){
|
||||||
$subChunks[$y] = new SubChunk(BlockLegacyIds::AIR << 4, [SubChunkConverter::convertSubChunkFromLegacyColumn($fullIds, $fullData, $y)]);
|
$subChunks[$y] = new SubChunk(BlockLegacyIds::AIR << 4, [SubChunkConverter::convertSubChunkFromLegacyColumn($fullIds, $fullData, $y)]);
|
||||||
@ -83,10 +83,10 @@ class McRegion extends RegionWorldProvider{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
$biomeIds = null;
|
$biomeIds = null;
|
||||||
if($chunk->hasTag("BiomeColors", IntArrayTag::class)){
|
if(($biomeColorsTag = $chunk->getTag("BiomeColors")) instanceof IntArrayTag){
|
||||||
$biomeIds = $makeBiomeArray(ChunkUtils::convertBiomeColors($chunk->getIntArray("BiomeColors"))); //Convert back to original format
|
$biomeIds = $makeBiomeArray(ChunkUtils::convertBiomeColors($biomeColorsTag->getValue())); //Convert back to original format
|
||||||
}elseif($chunk->hasTag("Biomes", ByteArrayTag::class)){
|
}elseif(($biomesTag = $chunk->getTag("Biomes")) instanceof ByteArrayTag){
|
||||||
$biomeIds = $makeBiomeArray($chunk->getByteArray("Biomes"));
|
$biomeIds = $makeBiomeArray($biomesTag->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = new Chunk(
|
$result = new Chunk(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user