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 Player[]
*/
private function selectPermittedPlayers(string $permission) : array{
/** @var Player[] $players */
$players = [];
@ -1536,6 +1539,9 @@ class Server{
exit(1);
}
/**
* @return mixed[]
*/
public function __debugInfo() : array{
return [];
}

View File

@ -1695,6 +1695,9 @@ abstract class Entity{
$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{
$this->server->broadcastPackets($players ?? $this->getViewers(), [AnimatePacket::create($this->id, $animationId)]);
}

View File

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

View File

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

View File

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

View File

@ -83,7 +83,10 @@ class LoginPacket extends DataPacket implements ServerboundPacket{
/** @var string[] array of encoded JWT */
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;
/** @var string */
public $clientDataJwt;

View File

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

View File

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

View File

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

View File

@ -46,6 +46,10 @@ trait IntegerishMetadataProperty{
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{
$value = 0;
foreach($flags as $flag => $v){

View File

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

View File

@ -91,6 +91,9 @@ class UseItemOnEntityTransactionData extends TransactionData{
$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{
$result = new self;
$result->actions = $actions;

View File

@ -109,6 +109,9 @@ class UseItemTransactionData extends TransactionData{
$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{
$result = new self;
$result->actions = $actions;

View File

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

View File

@ -90,6 +90,9 @@ final class GameMode{
/** @var string[] */
private $aliases;
/**
* @param string[] $aliases
*/
private function __construct(string $enumName, int $magicNumber, string $englishName, string $translationKey, array $aliases = []){
$this->Enum___construct($enumName);
$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{
$radius = $this->server->getAllowedViewDistance($this->viewDistance);
$radiusSquared = $radius ** 2;
@ -2007,6 +2010,9 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
parent::destroyCycles();
}
/**
* @return mixed[]
*/
public function __debugInfo() : array{
return [];
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -53,6 +53,11 @@ class BedrockWorldData extends BaseNbtWorldData{
public const GENERATOR_INFINITE = 1;
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{
Utils::testValidInstance($generator, Generator::class);
switch($generator){

View File

@ -41,6 +41,11 @@ use function microtime;
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{
Utils::testValidInstance($generator, Generator::class);
//TODO, add extra details

View File

@ -72,6 +72,11 @@ abstract class RegionWorldProvider extends BaseWorldProvider{
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{
Utils::testValidInstance($generator, Generator::class);
if(!file_exists($path)){

View File

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