Strict type all the things and fix lots of assorted bugs exposed by strict types (#993)

Strict type all the things
This commit is contained in:
Dylan K. Taylor
2017-06-08 11:21:51 +01:00
committed by GitHub
863 changed files with 2033 additions and 308 deletions

View File

@ -19,6 +19,8 @@
*
*/
declare(strict_types=1);
namespace pocketmine;
use pocketmine\block\Air;
@ -839,6 +841,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$X = null;
$Z = null;
Level::getXZ($index, $X, $Z);
assert(is_int($X) and is_int($Z));
++$count;
@ -900,7 +903,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->getDisplayName()
])
));
if(strlen(trim($ev->getJoinMessage())) > 0){
if(strlen(trim((string) $ev->getJoinMessage())) > 0){
$this->server->broadcastMessage($ev->getJoinMessage());
}
@ -1806,7 +1809,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;
@ -1823,7 +1826,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->achievements[$achievement->getName()] = $achievement->getValue() > 0 ? true : false;
}
$this->namedtag->lastPlayed = new LongTag("lastPlayed", floor(microtime(true) * 1000));
$this->namedtag->lastPlayed = new LongTag("lastPlayed", (int) floor(microtime(true) * 1000));
if($this->server->getAutoSave()){
$this->server->saveOfflinePlayerData($this->username, $this->namedtag, true);
}
@ -1842,7 +1845,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);
}
@ -1864,12 +1867,12 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$pk->spawnX = $spawnPosition->getFloorX();
$pk->spawnY = $spawnPosition->getFloorY();
$pk->spawnZ = $spawnPosition->getFloorZ();
$pk->hasAchievementsDisabled = 1;
$pk->hasAchievementsDisabled = true;
$pk->dayCycleStopTime = -1; //TODO: implement this properly
$pk->eduMode = 0;
$pk->eduMode = false;
$pk->rainLevel = 0; //TODO: implement these properly
$pk->lightningLevel = 0;
$pk->commandsEnabled = 1;
$pk->commandsEnabled = true;
$pk->levelId = "";
$pk->worldName = $this->server->getMotd();
$this->dataPacket($pk);
@ -2598,7 +2601,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
//TODO: improve this to take stuff like swimming, ladders, enchanted tools into account, fix wrong tool break time calculations for bad tools (pmmp/PocketMine-MP#211)
$breakTime = ceil($target->getBreakTime($this->inventory->getItemInHand()) * 20);
if($breakTime > 0){
$this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_START_BREAK, 65535 / $breakTime);
$this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_START_BREAK, (int) (65535 / $breakTime));
}
}
$this->lastBreak = microtime(true);
@ -3563,7 +3566,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
/**
* Sends a direct chat message to a player
*
* @param string|TextContainer $message
* @param TextContainer|string $message
*/
public function sendMessage($message){
if($message instanceof TextContainer){
@ -3745,7 +3748,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
}
$this->namedtag["playerGameType"] = $this->gamemode;
$this->namedtag["lastPlayed"] = floor(microtime(true) * 1000);
$this->namedtag["lastPlayed"] = (int) floor(microtime(true) * 1000);
if($this->username != "" and $this->namedtag instanceof CompoundTag){
$this->server->saveOfflinePlayerData($this->username, $this->namedtag, $async);
@ -3959,6 +3962,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$pk->pitch = $pitch;
$pk->yaw = $yaw;
$pk->mode = $mode;
$pk->onGround = $this->onGround;
if($targets !== null){
$this->server->broadcastPacket($targets, $pk);