Fixed a bunch of things PHPStan finds unpalatable

close #2614, fix a bunch of docs bugs, fix sendCreativeContents() crash on Human holders, move some inline variable declarations
This commit is contained in:
Dylan K. Taylor 2019-01-04 00:23:09 +00:00
parent 5e0c3333cf
commit d71a543d10
11 changed files with 62 additions and 39 deletions

View File

@ -216,12 +216,12 @@ class ParticleCommand extends VanillaCommand{
}elseif(strpos($name, "blockcrack_") === 0){ }elseif(strpos($name, "blockcrack_") === 0){
$d = explode("_", $name); $d = explode("_", $name);
if(count($d) === 2){ if(count($d) === 2){
return new TerrainParticle($pos, BlockFactory::get($d[1] & 0xff, $d[1] >> 12)); return new TerrainParticle($pos, BlockFactory::get(((int) $d[1]) & 0xff, ((int) $d[1]) >> 12));
} }
}elseif(strpos($name, "blockdust_") === 0){ }elseif(strpos($name, "blockdust_") === 0){
$d = explode("_", $name); $d = explode("_", $name);
if(count($d) >= 4){ if(count($d) >= 4){
return new DustParticle($pos, $d[1] & 0xff, $d[2] & 0xff, $d[3] & 0xff, isset($d[4]) ? $d[4] & 0xff : 255); return new DustParticle($pos, ((int) $d[1]) & 0xff, ((int) $d[2]) & 0xff, ((int) $d[3]) & 0xff, isset($d[4]) ? ((int) $d[4]) & 0xff : 255);
} }
} }

View File

@ -77,7 +77,7 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{
* @param Entity $entity * @param Entity $entity
* @param int $cause * @param int $cause
* @param float $damage * @param float $damage
* @param float|float[] $modifiers * @param float[] $modifiers
*/ */
public function __construct(Entity $entity, int $cause, float $damage, array $modifiers = []){ public function __construct(Entity $entity, int $cause, float $damage, array $modifiers = []){
$this->entity = $entity; $this->entity = $entity;

View File

@ -27,6 +27,8 @@ declare(strict_types=1);
namespace pocketmine\inventory; namespace pocketmine\inventory;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
interface Inventory{ interface Inventory{
@ -120,6 +122,15 @@ interface Inventory{
*/ */
public function setContents(array $items, bool $send = true) : void; public function setContents(array $items, bool $send = true) : void;
/**
* Drops the contents of the inventory into the specified Level at the specified position and clears the inventory
* contents.
*
* @param Level $level
* @param Vector3 $position
*/
public function dropContents(Level $level, Vector3 $position) : void;
/** /**
* @param Player|Player[] $target * @param Player|Player[] $target
*/ */

View File

@ -196,16 +196,21 @@ class PlayerInventory extends BaseInventory{
} }
public function sendCreativeContents(){ public function sendCreativeContents(){
//TODO: this mess shouldn't be in here
$holder = $this->getHolder();
if(!($holder instanceof Player)){
throw new \LogicException("Cannot send creative inventory contents to non-player inventory holder");
}
$pk = new InventoryContentPacket(); $pk = new InventoryContentPacket();
$pk->windowId = ContainerIds::CREATIVE; $pk->windowId = ContainerIds::CREATIVE;
if(!$this->getHolder()->isSpectator()){ //fill it for all gamemodes except spectator if(!$holder->isSpectator()){ //fill it for all gamemodes except spectator
foreach(Item::getCreativeItems() as $i => $item){ foreach(Item::getCreativeItems() as $i => $item){
$pk->items[$i] = clone $item; $pk->items[$i] = clone $item;
} }
} }
$this->getHolder()->dataPacket($pk); $holder->dataPacket($pk);
} }
/** /**

View File

@ -153,7 +153,7 @@ class Item implements ItemIds, \JsonSerializable{
} }
/** /**
* @param $index * @param int $index
* *
* @return Item|null * @return Item|null
*/ */

View File

@ -686,7 +686,9 @@ class Level implements ChunkManager, Metadatable{
} }
public function unregisterChunkLoader(ChunkLoader $loader, int $chunkX, int $chunkZ){ public function unregisterChunkLoader(ChunkLoader $loader, int $chunkX, int $chunkZ){
if(isset($this->chunkLoaders[$index = Level::chunkHash($chunkX, $chunkZ)][$hash = $loader->getLoaderId()])){ $index = Level::chunkHash($chunkX, $chunkZ);
$hash = $loader->getLoaderId();
if(isset($this->chunkLoaders[$index][$hash])){
unset($this->chunkLoaders[$index][$hash]); unset($this->chunkLoaders[$index][$hash]);
unset($this->playerLoaders[$index][$hash]); unset($this->playerLoaders[$index][$hash]);
if(count($this->chunkLoaders[$index]) === 0){ if(count($this->chunkLoaders[$index]) === 0){
@ -1346,9 +1348,9 @@ class Level implements ChunkManager, Metadatable{
} }
/** /**
* @param $x * @param int $x
* @param $y * @param int $y
* @param $z * @param int $z
* *
* @return int bitmap, (id << 4) | data * @return int bitmap, (id << 4) | data
*/ */
@ -2079,7 +2081,7 @@ class Level implements ChunkManager, Metadatable{
} }
/** /**
* @param $tileId * @param int $tileId
* *
* @return Tile|null * @return Tile|null
*/ */
@ -2185,7 +2187,9 @@ class Level implements ChunkManager, Metadatable{
if(!$this->isInWorld($x, $y, $z)){ //TODO: bad hack but fixing this requires BC breaks to do properly :( if(!$this->isInWorld($x, $y, $z)){ //TODO: bad hack but fixing this requires BC breaks to do properly :(
return; return;
} }
unset($this->blockCache[$chunkHash = Level::chunkHash($x >> 4, $z >> 4)][$blockHash = Level::blockHash($x, $y, $z)]); $chunkHash = Level::chunkHash($x >> 4, $z >> 4);
$blockHash = Level::blockHash($x, $y, $z);
unset($this->blockCache[$chunkHash][$blockHash]);
$this->getChunk($x >> 4, $z >> 4, true)->setBlockId($x & 0x0f, $y, $z & 0x0f, $id & 0xff); $this->getChunk($x >> 4, $z >> 4, true)->setBlockId($x & 0x0f, $y, $z & 0x0f, $id & 0xff);
if(!isset($this->changedBlocks[$chunkHash])){ if(!isset($this->changedBlocks[$chunkHash])){
@ -2222,7 +2226,9 @@ class Level implements ChunkManager, Metadatable{
if(!$this->isInWorld($x, $y, $z)){ //TODO: bad hack but fixing this requires BC breaks to do properly :( if(!$this->isInWorld($x, $y, $z)){ //TODO: bad hack but fixing this requires BC breaks to do properly :(
return; return;
} }
unset($this->blockCache[$chunkHash = Level::chunkHash($x >> 4, $z >> 4)][$blockHash = Level::blockHash($x, $y, $z)]); $chunkHash = Level::chunkHash($x >> 4, $z >> 4);
$blockHash = Level::blockHash($x, $y, $z);
unset($this->blockCache[$chunkHash][$blockHash]);
$this->getChunk($x >> 4, $z >> 4, true)->setBlockData($x & 0x0f, $y, $z & 0x0f, $data & 0x0f); $this->getChunk($x >> 4, $z >> 4, true)->setBlockData($x & 0x0f, $y, $z & 0x0f, $data & 0x0f);

View File

@ -118,7 +118,7 @@ interface LevelProvider{
public function getTime() : int; public function getTime() : int;
/** /**
* @param int * @param int $value
*/ */
public function setTime(int $value); public function setTime(int $value);
@ -128,7 +128,7 @@ interface LevelProvider{
public function getSeed() : int; public function getSeed() : int;
/** /**
* @param int * @param int $value
*/ */
public function setSeed(int $value); public function setSeed(int $value);

View File

@ -75,8 +75,9 @@ abstract class BiomeSelector{
} }
/** /**
* @param $x * TODO: not sure on types here
* @param $z * @param int|float $x
* @param int|float $z
* *
* @return Biome * @return Biome
*/ */

View File

@ -100,7 +100,7 @@ abstract class MetadataStore{
* @param Plugin $owningPlugin * @param Plugin $owningPlugin
*/ */
public function invalidateAll(Plugin $owningPlugin){ public function invalidateAll(Plugin $owningPlugin){
/** @var $values MetadataValue[] */ /** @var MetadataValue[] $values */
foreach($this->metadataMap as $values){ foreach($this->metadataMap as $values){
if(isset($values[$owningPlugin])){ if(isset($values[$owningPlugin])){
$values[$owningPlugin]->invalidate(); $values[$owningPlugin]->invalidate();

View File

@ -96,7 +96,7 @@ abstract class Tile extends Position{
* @param string $type * @param string $type
* @param Level $level * @param Level $level
* @param CompoundTag $nbt * @param CompoundTag $nbt
* @param $args * @param mixed ...$args
* *
* @return Tile|null * @return Tile|null
*/ */

View File

@ -111,7 +111,7 @@ class Config{
} }
/** /**
* @param $file * @param string $file
* @param int $type * @param int $type
* @param array $default * @param array $default
* *
@ -289,7 +289,7 @@ class Config{
} }
/** /**
* @param $k * @param string $k
* *
* @return bool|mixed * @return bool|mixed
*/ */
@ -298,15 +298,15 @@ class Config{
} }
/** /**
* @param $k * @param string $k
* @param $v * @param mixed $v
*/ */
public function __set($k, $v){ public function __set($k, $v){
$this->set($k, $v); $this->set($k, $v);
} }
/** /**
* @param $k * @param string $k
* *
* @return bool * @return bool
*/ */
@ -315,15 +315,15 @@ class Config{
} }
/** /**
* @param $k * @param string $k
*/ */
public function __unset($k){ public function __unset($k){
$this->remove($k); $this->remove($k);
} }
/** /**
* @param $key * @param string $key
* @param $value * @param mixed $value
*/ */
public function setNested($key, $value){ public function setNested($key, $value){
$vars = explode(".", $key); $vars = explode(".", $key);
@ -349,7 +349,7 @@ class Config{
} }
/** /**
* @param $key * @param string $key
* @param mixed $default * @param mixed $default
* *
* @return mixed * @return mixed
@ -401,7 +401,7 @@ class Config{
} }
/** /**
* @param $k * @param string $k
* @param mixed $default * @param mixed $default
* *
* @return bool|mixed * @return bool|mixed
@ -433,7 +433,7 @@ class Config{
} }
/** /**
* @param $k * @param string $k
* @param bool $lowercase If set, searches Config in single-case / lowercase. * @param bool $lowercase If set, searches Config in single-case / lowercase.
* *
* @return bool * @return bool
@ -449,7 +449,7 @@ class Config{
} }
/** /**
* @param $k * @param string $k
*/ */
public function remove($k){ public function remove($k){
unset($this->config[$k]); unset($this->config[$k]);