fill in more iterable types (master)

This commit is contained in:
Dylan K. Taylor 2020-02-01 20:19:57 +00:00
parent 200209b76c
commit ff63f6d055
26 changed files with 121 additions and 3 deletions

View File

@ -1153,6 +1153,9 @@ class Server{
return count($recipients); return count($recipients);
} }
/**
* @return Player[]
*/
private function selectPermittedPlayers(string $permission) : array{ private function selectPermittedPlayers(string $permission) : array{
/** @var Player[] $players */ /** @var Player[] $players */
$players = []; $players = [];
@ -1536,6 +1539,9 @@ class Server{
exit(1); exit(1);
} }
/**
* @return mixed[]
*/
public function __debugInfo() : array{ public function __debugInfo() : array{
return []; return [];
} }

View File

@ -1695,6 +1695,9 @@ abstract class Entity{
$this->server->broadcastPackets($players ?? $this->getViewers(), [ActorEventPacket::create($this->id, $eventId, $eventData ?? 0)]); $this->server->broadcastPackets($players ?? $this->getViewers(), [ActorEventPacket::create($this->id, $eventId, $eventData ?? 0)]);
} }
/**
* @param Player[]|null $players
*/
public function broadcastAnimation(?array $players, int $animationId) : void{ public function broadcastAnimation(?array $players, int $animationId) : void{
$this->server->broadcastPackets($players ?? $this->getViewers(), [AnimatePacket::create($this->id, $animationId)]); $this->server->broadcastPackets($players ?? $this->getViewers(), [AnimatePacket::create($this->id, $animationId)]);
} }

View File

@ -109,6 +109,10 @@ class Language{
return $this->langName; return $this->langName;
} }
/**
* @return string[]
* @phpstan-return array<string, string>
*/
protected static function loadLang(string $path, string $languageCode) : array{ protected static function loadLang(string $path, string $languageCode) : array{
$file = $path . $languageCode . ".ini"; $file = $path . $languageCode . ".ini";
if(file_exists($file)){ if(file_exists($file)){

View File

@ -711,6 +711,9 @@ class NetworkSession{
$this->sendDataPacket(TextPacket::raw($message)); $this->sendDataPacket(TextPacket::raw($message));
} }
/**
* @param string[] $parameters
*/
public function onTranslatedChatMessage(string $key, array $parameters) : void{ public function onTranslatedChatMessage(string $key, array $parameters) : void{
$this->sendDataPacket(TextPacket::translation($key, $parameters)); $this->sendDataPacket(TextPacket::translation($key, $parameters));
} }

View File

@ -104,6 +104,9 @@ abstract class DataPacket extends NetworkBinaryStream implements Packet{
*/ */
abstract protected function encodePayload() : void; abstract protected function encodePayload() : void;
/**
* @return mixed[]
*/
public function __debugInfo() : array{ public function __debugInfo() : array{
$data = []; $data = [];
foreach((array) $this as $k => $v){ foreach((array) $this as $k => $v){

View File

@ -83,7 +83,10 @@ class LoginPacket extends DataPacket implements ServerboundPacket{
/** @var string[] array of encoded JWT */ /** @var string[] array of encoded JWT */
public $chainDataJwt = []; public $chainDataJwt = [];
/** @var array|null extraData index of whichever JWT has it */ /**
* @var mixed[]|null extraData index of whichever JWT has it
* @phpstan-var array<string, mixed>
*/
public $extraData = null; public $extraData = null;
/** @var string */ /** @var string */
public $clientDataJwt; public $clientDataJwt;

View File

@ -40,6 +40,9 @@ class PlayerListPacket extends DataPacket implements ClientboundPacket{
/** @var int */ /** @var int */
public $type; public $type;
/**
* @param PlayerListEntry[] $entries
*/
public static function add(array $entries) : self{ public static function add(array $entries) : self{
$result = new self; $result = new self;
$result->type = self::TYPE_ADD; $result->type = self::TYPE_ADD;
@ -47,6 +50,9 @@ class PlayerListPacket extends DataPacket implements ClientboundPacket{
return $result; return $result;
} }
/**
* @param PlayerListEntry[] $entries
*/
public static function remove(array $entries) : self{ public static function remove(array $entries) : self{
$result = new self; $result = new self;
$result->type = self::TYPE_REMOVE; $result->type = self::TYPE_REMOVE;

View File

@ -39,6 +39,10 @@ class SetActorDataPacket extends DataPacket implements ClientboundPacket, Server
*/ */
public $metadata; public $metadata;
/**
* @param MetadataProperty[] $metadata
* @phpstan-param array<int, MetadataProperty> $metadata
*/
public static function create(int $entityRuntimeId, array $metadata) : self{ public static function create(int $entityRuntimeId, array $metadata) : self{
$result = new self; $result = new self;

View File

@ -64,6 +64,9 @@ class TextPacket extends DataPacket implements ClientboundPacket, ServerboundPac
return $result; return $result;
} }
/**
* @param string[] $parameters
*/
private static function baseTranslation(int $type, string $key, array $parameters) : self{ private static function baseTranslation(int $type, string $key, array $parameters) : self{
$result = new self; $result = new self;
$result->type = $type; $result->type = $type;

View File

@ -46,6 +46,10 @@ trait IntegerishMetadataProperty{
return $other instanceof self and $other->value === $this->value; return $other instanceof self and $other->value === $this->value;
} }
/**
* @param bool[] $flags
* @phpstan-param array<int, bool> $flags
*/
public static function buildFromFlags(array $flags) : self{ public static function buildFromFlags(array $flags) : self{
$value = 0; $value = 0;
foreach($flags as $flag => $v){ foreach($flags as $flag => $v){

View File

@ -75,6 +75,9 @@ class ReleaseItemTransactionData extends TransactionData{
$stream->putVector3($this->headPos); $stream->putVector3($this->headPos);
} }
/**
* @param NetworkInventoryAction[] $actions
*/
public static function new(array $actions, int $actionType, int $hotbarSlot, Item $itemInHand, Vector3 $headPos) : self{ public static function new(array $actions, int $actionType, int $hotbarSlot, Item $itemInHand, Vector3 $headPos) : self{
$result = new self; $result = new self;
$result->actions = $actions; $result->actions = $actions;

View File

@ -91,6 +91,9 @@ class UseItemOnEntityTransactionData extends TransactionData{
$stream->putVector3($this->clickPos); $stream->putVector3($this->clickPos);
} }
/**
* @param NetworkInventoryAction[] $actions
*/
public static function new(array $actions, int $entityRuntimeId, int $actionType, int $hotbarSlot, Item $itemInHand, Vector3 $playerPos, Vector3 $clickPos) : self{ public static function new(array $actions, int $entityRuntimeId, int $actionType, int $hotbarSlot, Item $itemInHand, Vector3 $playerPos, Vector3 $clickPos) : self{
$result = new self; $result = new self;
$result->actions = $actions; $result->actions = $actions;

View File

@ -109,6 +109,9 @@ class UseItemTransactionData extends TransactionData{
$stream->putUnsignedVarInt($this->blockRuntimeId); $stream->putUnsignedVarInt($this->blockRuntimeId);
} }
/**
* @param NetworkInventoryAction[] $actions
*/
public static function new(array $actions, int $actionType, Vector3 $blockPos, int $face, int $hotbarSlot, Item $itemInHand, Vector3 $playerPos, Vector3 $clickPos, int $blockRuntimeId) : self{ public static function new(array $actions, int $actionType, Vector3 $blockPos, int $face, int $hotbarSlot, Item $itemInHand, Vector3 $playerPos, Vector3 $clickPos, int $blockRuntimeId) : self{
$result = new self; $result = new self;
$result->actions = $actions; $result->actions = $actions;

View File

@ -122,6 +122,9 @@ class PermissionParser{
/** /**
* @param Permission[] $permissions * @param Permission[] $permissions
*
* @return mixed[]
* @phpstan-return array<string, array<string, mixed>>
*/ */
public static function emitPermissions(array $permissions) : array{ public static function emitPermissions(array $permissions) : array{
$result = []; $result = [];
@ -132,6 +135,10 @@ class PermissionParser{
return $result; return $result;
} }
/**
* @return mixed[]
* @phpstan-return array<string, mixed>
*/
private static function emitPermission(Permission $permission) : array{ private static function emitPermission(Permission $permission) : array{
$result = [ $result = [
"description" => $permission->getDescription(), "description" => $permission->getDescription(),

View File

@ -90,6 +90,9 @@ final class GameMode{
/** @var string[] */ /** @var string[] */
private $aliases; private $aliases;
/**
* @param string[] $aliases
*/
private function __construct(string $enumName, int $magicNumber, string $englishName, string $translationKey, array $aliases = []){ private function __construct(string $enumName, int $magicNumber, string $englishName, string $translationKey, array $aliases = []){
$this->Enum___construct($enumName); $this->Enum___construct($enumName);
$this->magicNumber = $magicNumber; $this->magicNumber = $magicNumber;

View File

@ -837,6 +837,9 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
} }
} }
/**
* @return \Generator<int, int, void, void>
*/
protected function selectChunks() : \Generator{ protected function selectChunks() : \Generator{
$radius = $this->server->getAllowedViewDistance($this->viewDistance); $radius = $this->server->getAllowedViewDistance($this->viewDistance);
$radiusSquared = $radius ** 2; $radiusSquared = $radius ** 2;
@ -2007,6 +2010,9 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
parent::destroyCycles(); parent::destroyCycles();
} }
/**
* @return mixed[]
*/
public function __debugInfo() : array{ public function __debugInfo() : array{
return []; return [];
} }

View File

@ -42,9 +42,16 @@ class PlayerInfo{
private $locale; private $locale;
/** @var string */ /** @var string */
private $xuid; private $xuid;
/** @var array */ /**
* @var mixed[]
* @phpstan-var array<string, mixed>
*/
private $extraData; private $extraData;
/**
* @param mixed[] $extraData
* @phpstan-param array<string, mixed> $extraData
*/
public function __construct(string $username, UUID $uuid, Skin $skin, string $locale, string $xuid, array $extraData = []){ public function __construct(string $username, UUID $uuid, Skin $skin, string $locale, string $xuid, array $extraData = []){
$this->username = TextFormat::clean($username); $this->username = TextFormat::clean($username);
$this->uuid = $uuid; $this->uuid = $uuid;
@ -74,6 +81,10 @@ class PlayerInfo{
return $this->xuid; return $this->xuid;
} }
/**
* @return mixed[]
* @phpstan-return array<string, mixed>
*/
public function getExtraData() : array{ public function getExtraData() : array{
return $this->extraData; return $this->extraData;
} }

View File

@ -36,6 +36,9 @@ class PluginGraylist{
/** @var bool */ /** @var bool */
private $isWhitelist = false; private $isWhitelist = false;
/**
* @param string[] $plugins
*/
public function __construct(array $plugins = [], bool $whitelist = false){ public function __construct(array $plugins = [], bool $whitelist = false){
$this->plugins = array_flip($plugins); $this->plugins = array_flip($plugins);
$this->isWhitelist = $whitelist; $this->isWhitelist = $whitelist;
@ -59,6 +62,9 @@ class PluginGraylist{
return $this->isWhitelist() === isset($this->plugins[$name]); return $this->isWhitelist() === isset($this->plugins[$name]);
} }
/**
* @param mixed[] $array
*/
public static function fromArray(array $array) : PluginGraylist{ public static function fromArray(array $array) : PluginGraylist{
$v = new Validator(); $v = new Validator();
$v->required("mode")->inArray(['whitelist', 'blacklist'], true); $v->required("mode")->inArray(['whitelist', 'blacklist'], true);
@ -75,6 +81,10 @@ class PluginGraylist{
return new PluginGraylist($array["plugins"], $array["mode"] === 'whitelist'); return new PluginGraylist($array["plugins"], $array["mode"] === 'whitelist');
} }
/**
* @return mixed[]
* @phpstan-return array<string, mixed>
*/
public function toArray() : array{ public function toArray() : array{
return [ return [
"mode" => $this->isWhitelist ? 'whitelist' : 'blacklist', "mode" => $this->isWhitelist ? 'whitelist' : 'blacklist',

View File

@ -423,6 +423,9 @@ class World implements ChunkManager{
$this->closed = true; $this->closed = true;
} }
/**
* @param Player[]|null $players
*/
public function addSound(Vector3 $pos, Sound $sound, ?array $players = null) : void{ public function addSound(Vector3 $pos, Sound $sound, ?array $players = null) : void{
$pk = $sound->encode($pos); $pk = $sound->encode($pos);
if(!is_array($pk)){ if(!is_array($pk)){
@ -439,6 +442,9 @@ class World implements ChunkManager{
} }
} }
/**
* @param Player[]|null $players
*/
public function addParticle(Vector3 $pos, Particle $particle, ?array $players = null) : void{ public function addParticle(Vector3 $pos, Particle $particle, ?array $players = null) : void{
$pk = $particle->encode($pos); $pk = $particle->encode($pos);
if(!is_array($pk)){ if(!is_array($pk)){

View File

@ -235,7 +235,9 @@ class WorldManager{
* Generates a new world if it does not exist * Generates a new world if it does not exist
* *
* @param string $generator Class name that extends pocketmine\world\generator\Generator * @param string $generator Class name that extends pocketmine\world\generator\Generator
* @param mixed[] $options
* @phpstan-param class-string<Generator> $generator * @phpstan-param class-string<Generator> $generator
* @phpstan-param array<string, mixed> $options
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */

View File

@ -108,6 +108,9 @@ class SubChunk implements SubChunkInterface{
$this->blockLight = $data; $this->blockLight = $data;
} }
/**
* @return mixed[]
*/
public function __debugInfo() : array{ public function __debugInfo() : array{
return []; return [];
} }

View File

@ -39,6 +39,10 @@ interface WorldData{
*/ */
public function getGenerator() : string; public function getGenerator() : string;
/**
* @return mixed[]
* @phpstan-return array<string, mixed>
*/
public function getGeneratorOptions() : array; public function getGeneratorOptions() : array;
public function getSeed() : int; public function getSeed() : int;

View File

@ -53,6 +53,11 @@ class BedrockWorldData extends BaseNbtWorldData{
public const GENERATOR_INFINITE = 1; public const GENERATOR_INFINITE = 1;
public const GENERATOR_FLAT = 2; public const GENERATOR_FLAT = 2;
/**
* @param mixed[] $options
* @phpstan-param class-string<Generator> $generator
* @phpstan-param array<string, mixed> $options
*/
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []) : void{ public static function generate(string $path, string $name, int $seed, string $generator, array $options = []) : void{
Utils::testValidInstance($generator, Generator::class); Utils::testValidInstance($generator, Generator::class);
switch($generator){ switch($generator){

View File

@ -41,6 +41,11 @@ use function microtime;
class JavaWorldData extends BaseNbtWorldData{ class JavaWorldData extends BaseNbtWorldData{
/**
* @param mixed[] $options
* @phpstan-param class-string<Generator> $generator
* @phpstan-param array<string, mixed> $options
*/
public static function generate(string $path, string $name, int $seed, string $generator, array $options = [], int $version = 19133) : void{ public static function generate(string $path, string $name, int $seed, string $generator, array $options = [], int $version = 19133) : void{
Utils::testValidInstance($generator, Generator::class); Utils::testValidInstance($generator, Generator::class);
//TODO, add extra details //TODO, add extra details

View File

@ -72,6 +72,11 @@ abstract class RegionWorldProvider extends BaseWorldProvider{
return false; return false;
} }
/**
* @param mixed[] $options
* @phpstan-param class-string<Generator> $generator
* @phpstan-param array<string, mixed> $options
*/
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []) : void{ public static function generate(string $path, string $name, int $seed, string $generator, array $options = []) : void{
Utils::testValidInstance($generator, Generator::class); Utils::testValidInstance($generator, Generator::class);
if(!file_exists($path)){ if(!file_exists($path)){

View File

@ -52,7 +52,10 @@ abstract class Generator{
protected $world; protected $world;
/** @var int */ /** @var int */
protected $seed; protected $seed;
/** @var array */ /**
* @var mixed[]
* @phpstan-var array<string, mixed>
*/
protected $options; protected $options;
/** @var Random */ /** @var Random */