Fix some strict type violations reported by PhpStorm (strict types <3)

This commit is contained in:
Dylan K. Taylor 2017-06-04 09:50:49 +01:00
parent b775e8c88a
commit cf07af8b55
6 changed files with 18 additions and 17 deletions

View File

@ -1808,7 +1808,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->allowFlight = (bool) ($this->gamemode & 0x01);
if(($level = $this->server->getLevelByName($this->namedtag["Level"])) === null){
if(($level = $this->server->getLevelByName((string) $this->namedtag["Level"])) === null){
$this->setLevel($this->server->getDefaultLevel());
$this->namedtag["Level"] = $this->level->getName();
$this->namedtag["Pos"][0] = $this->level->getSpawnLocation()->x;
@ -1844,7 +1844,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
protected function completeLoginSequence(){
parent::__construct($this->level, $this->namedtag);
if(!$this->hasValidSpawnPosition() and isset($this->namedtag->SpawnLevel) and ($level = $this->server->getLevelByName($this->namedtag["SpawnLevel"])) instanceof Level){
if(!$this->hasValidSpawnPosition() and isset($this->namedtag->SpawnLevel) and ($level = $this->server->getLevelByName((string) $this->namedtag["SpawnLevel"])) instanceof Level){
$this->spawnPosition = new WeakPosition($this->namedtag["SpawnX"], $this->namedtag["SpawnY"], $this->namedtag["SpawnZ"], $level);
}

View File

@ -42,6 +42,7 @@ use pocketmine\event\level\LevelLoadEvent;
use pocketmine\event\player\PlayerDataSaveEvent;
use pocketmine\event\server\QueryRegenerateEvent;
use pocketmine\event\server\ServerCommandEvent;
use pocketmine\event\TextContainer;
use pocketmine\event\Timings;
use pocketmine\event\TimingsHandler;
use pocketmine\event\TranslationContainer;
@ -1165,7 +1166,7 @@ class Server{
return (string) $v[$variable];
}
return $this->properties->exists($variable) ? $this->properties->get($variable) : $defaultValue;
return $this->properties->exists($variable) ? (string) $this->properties->get($variable) : $defaultValue;
}
/**
@ -1654,8 +1655,8 @@ class Server{
}
/**
* @param TextContainer|string $message
* @param Player[] $recipients
* @param TextContainer|string $message
* @param Player[] $recipients
*
* @return int
*/

View File

@ -64,7 +64,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
public $eyeHeight = 1.62;
protected $skinId;
protected $skin = null;
protected $skin = "";
protected $foodTickTimer = 0;
@ -72,7 +72,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
protected $xpSeed;
public function __construct(Level $level, CompoundTag $nbt){
if($this->skin === null and (!isset($nbt->Skin) or !isset($nbt->Skin->Data) or !Player::isValidSkin($nbt->Skin->Data->getValue()))){
if($this->skin === "" and (!isset($nbt->Skin) or !isset($nbt->Skin->Data) or !Player::isValidSkin($nbt->Skin->Data->getValue()))){
throw new \InvalidStateException((new \ReflectionClass($this))->getShortName() . " must have a valid skin set");
}
@ -250,7 +250,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$this->attributeMap->getAttribute(Attribute::EXPERIENCE)->setValue($progress);
}
public function getTotalXp() : float{
public function getTotalXp() : int{
return $this->totalXp;
}
@ -319,19 +319,19 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if(!isset($this->namedtag->foodLevel) or !($this->namedtag->foodLevel instanceof IntTag)){
$this->namedtag->foodLevel = new IntTag("foodLevel", (int) $this->getFood());
}else{
$this->setFood($this->namedtag["foodLevel"]);
$this->setFood((float) $this->namedtag["foodLevel"]);
}
if(!isset($this->namedtag->foodExhaustionLevel) or !($this->namedtag->foodExhaustionLevel instanceof IntTag)){
if(!isset($this->namedtag->foodExhaustionLevel) or !($this->namedtag->foodExhaustionLevel instanceof FloatTag)){
$this->namedtag->foodExhaustionLevel = new FloatTag("foodExhaustionLevel", $this->getExhaustion());
}else{
$this->setExhaustion($this->namedtag["foodExhaustionLevel"]);
$this->setExhaustion((float) $this->namedtag["foodExhaustionLevel"]);
}
if(!isset($this->namedtag->foodSaturationLevel) or !($this->namedtag->foodSaturationLevel instanceof IntTag)){
if(!isset($this->namedtag->foodSaturationLevel) or !($this->namedtag->foodSaturationLevel instanceof FloatTag)){
$this->namedtag->foodSaturationLevel = new FloatTag("foodSaturationLevel", $this->getSaturation());
}else{
$this->setSaturation($this->namedtag["foodSaturationLevel"]);
$this->setSaturation((float) $this->namedtag["foodSaturationLevel"]);
}
if(!isset($this->namedtag->foodTickTimer) or !($this->namedtag->foodTickTimer instanceof IntTag)){
@ -343,7 +343,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if(!isset($this->namedtag->XpLevel) or !($this->namedtag->XpLevel instanceof IntTag)){
$this->namedtag->XpLevel = new IntTag("XpLevel", $this->getXpLevel());
}else{
$this->setXpLevel($this->namedtag["XpLevel"]);
$this->setXpLevel((int) $this->namedtag["XpLevel"]);
}
if(!isset($this->namedtag->XpP) or !($this->namedtag->XpP instanceof FloatTag)){

View File

@ -74,7 +74,7 @@ abstract class Projectile extends Entity{
* @return int
*/
public function getResultDamage() : int{
return ceil(sqrt($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2) * $this->damage);
return (int) ceil(sqrt($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2) * $this->damage);
}
public function onCollideWithEntity(Entity $entity){

View File

@ -51,7 +51,7 @@ class Fish extends Food{
}elseif($this->meta === self::FISH_CLOWNFISH){
return 1;
}elseif($this->meta === self::FISH_PUFFERFISH){
return 1.2;
return 1;
}
return 0;
}

View File

@ -231,7 +231,7 @@ class LevelDB extends BaseLevelProvider{
}
public function getGenerator() : string{
return $this->levelData["generatorName"];
return (string) $this->levelData["generatorName"];
}
public function getGeneratorOptions() : array{