mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
PHPStan 2.0 fixes
This commit is contained in:
parent
7b1b35ab1f
commit
cd59e272bc
@ -110,7 +110,6 @@ class CraftingManager{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Item[] $items
|
* @param Item[] $items
|
||||||
* @phpstan-param list<Item> $items
|
|
||||||
*
|
*
|
||||||
* @return Item[]
|
* @return Item[]
|
||||||
* @phpstan-return list<Item>
|
* @phpstan-return list<Item>
|
||||||
@ -135,7 +134,6 @@ class CraftingManager{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Item[] $outputs
|
* @param Item[] $outputs
|
||||||
* @phpstan-param list<Item> $outputs
|
|
||||||
*/
|
*/
|
||||||
private static function hashOutputs(array $outputs) : string{
|
private static function hashOutputs(array $outputs) : string{
|
||||||
$outputs = self::pack($outputs);
|
$outputs = self::pack($outputs);
|
||||||
|
@ -37,7 +37,6 @@ use pocketmine\utils\Utils;
|
|||||||
use Symfony\Component\Filesystem\Path;
|
use Symfony\Component\Filesystem\Path;
|
||||||
use function array_key_last;
|
use function array_key_last;
|
||||||
use function array_map;
|
use function array_map;
|
||||||
use function array_values;
|
|
||||||
use function assert;
|
use function assert;
|
||||||
use function count;
|
use function count;
|
||||||
use function get_debug_type;
|
use function get_debug_type;
|
||||||
@ -138,8 +137,8 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
|
|
||||||
$convertedRemappedValuesIndex = [];
|
$convertedRemappedValuesIndex = [];
|
||||||
foreach(Utils::stringifyKeys($model->remappedPropertyValuesIndex ?? []) as $mappingKey => $mappingValues){
|
foreach(Utils::stringifyKeys($model->remappedPropertyValuesIndex ?? []) as $mappingKey => $mappingValues){
|
||||||
foreach($mappingValues as $k => $oldNew){
|
foreach($mappingValues as $oldNew){
|
||||||
$convertedRemappedValuesIndex[$mappingKey][$k] = new BlockStateUpgradeSchemaValueRemap(
|
$convertedRemappedValuesIndex[$mappingKey][] = new BlockStateUpgradeSchemaValueRemap(
|
||||||
self::jsonModelToTag($oldNew->old),
|
self::jsonModelToTag($oldNew->old),
|
||||||
self::jsonModelToTag($oldNew->new)
|
self::jsonModelToTag($oldNew->new)
|
||||||
);
|
);
|
||||||
@ -361,7 +360,7 @@ final class BlockStateUpgradeSchemaUtils{
|
|||||||
//remaps with the same number of criteria should be sorted alphabetically, but this is not strictly necessary
|
//remaps with the same number of criteria should be sorted alphabetically, but this is not strictly necessary
|
||||||
return json_encode($a->oldState ?? []) <=> json_encode($b->oldState ?? []);
|
return json_encode($a->oldState ?? []) <=> json_encode($b->oldState ?? []);
|
||||||
});
|
});
|
||||||
$result->remappedStates[$oldBlockName] = array_values($keyedRemaps);
|
$result->remappedStates[$oldBlockName] = $keyedRemaps; //usort strips keys, so this is already a list
|
||||||
}
|
}
|
||||||
if(isset($result->remappedStates)){
|
if(isset($result->remappedStates)){
|
||||||
ksort($result->remappedStates);
|
ksort($result->remappedStates);
|
||||||
|
@ -23,7 +23,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\data\runtime;
|
namespace pocketmine\data\runtime;
|
||||||
|
|
||||||
use function array_values;
|
|
||||||
use function ceil;
|
use function ceil;
|
||||||
use function count;
|
use function count;
|
||||||
use function log;
|
use function log;
|
||||||
@ -60,7 +59,7 @@ final class RuntimeEnumMetadata{
|
|||||||
usort($members, fn(\UnitEnum $a, \UnitEnum $b) => $a->name <=> $b->name); //sort by name to ensure consistent ordering (and thus consistent bit assignments)
|
usort($members, fn(\UnitEnum $a, \UnitEnum $b) => $a->name <=> $b->name); //sort by name to ensure consistent ordering (and thus consistent bit assignments)
|
||||||
|
|
||||||
$this->bits = (int) ceil(log(count($members), 2));
|
$this->bits = (int) ceil(log(count($members), 2));
|
||||||
$this->intToEnum = array_values($members);
|
$this->intToEnum = $members; //usort strips keys so this is already a list
|
||||||
|
|
||||||
$reversed = [];
|
$reversed = [];
|
||||||
foreach($this->intToEnum as $int => $enum){
|
foreach($this->intToEnum as $int => $enum){
|
||||||
|
@ -119,7 +119,7 @@ class HandlerListManager{
|
|||||||
public function getHandlersFor(string $event) : array{
|
public function getHandlersFor(string $event) : array{
|
||||||
$cache = $this->handlerCaches[$event] ?? null;
|
$cache = $this->handlerCaches[$event] ?? null;
|
||||||
//getListFor() will populate the cache for the next call
|
//getListFor() will populate the cache for the next call
|
||||||
return $cache?->list ?? $this->getListFor($event)->getListenerList();
|
return $cache->list ?? $this->getListFor($event)->getListenerList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -232,7 +232,7 @@ class InventoryTransaction{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param SlotChangeAction[] $possibleActions
|
* @param SlotChangeAction[] $possibleActions
|
||||||
* @phpstan-param list<SlotChangeAction> $possibleActions
|
* @phpstan-param array<int, SlotChangeAction> $possibleActions
|
||||||
*/
|
*/
|
||||||
protected function findResultItem(Item $needOrigin, array $possibleActions) : ?Item{
|
protected function findResultItem(Item $needOrigin, array $possibleActions) : ?Item{
|
||||||
assert(count($possibleActions) > 0);
|
assert(count($possibleActions) > 0);
|
||||||
|
@ -101,8 +101,9 @@ abstract class WritableBookBase extends Item{
|
|||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function deletePage(int $pageId) : self{
|
public function deletePage(int $pageId) : self{
|
||||||
unset($this->pages[$pageId]);
|
$newPages = $this->pages;
|
||||||
$this->pages = array_values($this->pages);
|
unset($newPages[$pageId]);
|
||||||
|
$this->pages = array_values($newPages);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ use function array_merge;
|
|||||||
use function array_search;
|
use function array_search;
|
||||||
use function array_shift;
|
use function array_shift;
|
||||||
use function array_unique;
|
use function array_unique;
|
||||||
|
use function array_values;
|
||||||
use function count;
|
use function count;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,7 +104,8 @@ final class ItemEnchantmentTagRegistry{
|
|||||||
|
|
||||||
foreach(Utils::stringifyKeys($this->tagMap) as $key => $nestedTags){
|
foreach(Utils::stringifyKeys($this->tagMap) as $key => $nestedTags){
|
||||||
if(($nestedKey = array_search($tag, $nestedTags, true)) !== false){
|
if(($nestedKey = array_search($tag, $nestedTags, true)) !== false){
|
||||||
unset($this->tagMap[$key][$nestedKey]);
|
unset($nestedTags[$nestedKey]);
|
||||||
|
$this->tagMap[$key] = array_values($nestedTags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,7 +117,7 @@ final class ItemEnchantmentTagRegistry{
|
|||||||
*/
|
*/
|
||||||
public function removeNested(string $tag, array $nestedTags) : void{
|
public function removeNested(string $tag, array $nestedTags) : void{
|
||||||
$this->assertNotInternalTag($tag);
|
$this->assertNotInternalTag($tag);
|
||||||
$this->tagMap[$tag] = array_diff($this->tagMap[$tag], $nestedTags);
|
$this->tagMap[$tag] = array_values(array_diff($this->tagMap[$tag], $nestedTags));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,7 +147,6 @@ use function count;
|
|||||||
use function explode;
|
use function explode;
|
||||||
use function floor;
|
use function floor;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
use function is_int;
|
|
||||||
use function max;
|
use function max;
|
||||||
use function mb_strlen;
|
use function mb_strlen;
|
||||||
use function microtime;
|
use function microtime;
|
||||||
@ -826,7 +825,6 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
$X = null;
|
$X = null;
|
||||||
$Z = null;
|
$Z = null;
|
||||||
World::getXZ($index, $X, $Z);
|
World::getXZ($index, $X, $Z);
|
||||||
assert(is_int($X) && is_int($Z));
|
|
||||||
|
|
||||||
++$count;
|
++$count;
|
||||||
|
|
||||||
@ -1346,7 +1344,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
$this->nextChunkOrderRun = 0;
|
$this->nextChunkOrderRun = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$revert && $distanceSquared != 0){
|
if(!$revert && $distanceSquared !== 0.0){
|
||||||
$dx = $newPos->x - $oldPos->x;
|
$dx = $newPos->x - $oldPos->x;
|
||||||
$dy = $newPos->y - $oldPos->y;
|
$dy = $newPos->y - $oldPos->y;
|
||||||
$dz = $newPos->z - $oldPos->z;
|
$dz = $newPos->z - $oldPos->z;
|
||||||
@ -2319,7 +2317,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
|
|
||||||
$ev = new PlayerQuitEvent($this, $quitMessage ?? $this->getLeaveMessage(), $reason);
|
$ev = new PlayerQuitEvent($this, $quitMessage ?? $this->getLeaveMessage(), $reason);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if(($quitMessage = $ev->getQuitMessage()) != ""){
|
if(($quitMessage = $ev->getQuitMessage()) !== ""){
|
||||||
$this->server->broadcastMessage($quitMessage);
|
$this->server->broadcastMessage($quitMessage);
|
||||||
}
|
}
|
||||||
$this->save();
|
$this->save();
|
||||||
@ -2460,7 +2458,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
$this->xpManager->setXpAndProgress(0, 0.0);
|
$this->xpManager->setXpAndProgress(0, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($ev->getDeathMessage() != ""){
|
if($ev->getDeathMessage() !== ""){
|
||||||
$this->server->broadcastMessage($ev->getDeathMessage());
|
$this->server->broadcastMessage($ev->getDeathMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,10 +47,16 @@ class ResourcePackManager{
|
|||||||
private string $path;
|
private string $path;
|
||||||
private bool $serverForceResources = false;
|
private bool $serverForceResources = false;
|
||||||
|
|
||||||
/** @var ResourcePack[] */
|
/**
|
||||||
|
* @var ResourcePack[]
|
||||||
|
* @phpstan-var list<ResourcePack>
|
||||||
|
*/
|
||||||
private array $resourcePacks = [];
|
private array $resourcePacks = [];
|
||||||
|
|
||||||
/** @var ResourcePack[] */
|
/**
|
||||||
|
* @var ResourcePack[]
|
||||||
|
* @phpstan-var array<string, ResourcePack>
|
||||||
|
*/
|
||||||
private array $uuidList = [];
|
private array $uuidList = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,6 +171,7 @@ class ResourcePackManager{
|
|||||||
/**
|
/**
|
||||||
* Returns an array of resource packs in use, sorted in order of priority.
|
* Returns an array of resource packs in use, sorted in order of priority.
|
||||||
* @return ResourcePack[]
|
* @return ResourcePack[]
|
||||||
|
* @phpstan-return list<ResourcePack>
|
||||||
*/
|
*/
|
||||||
public function getResourceStack() : array{
|
public function getResourceStack() : array{
|
||||||
return $this->resourcePacks;
|
return $this->resourcePacks;
|
||||||
|
@ -77,7 +77,10 @@ class BulkCurlTask extends AsyncTask{
|
|||||||
* @phpstan-var \Closure(list<InternetRequestResult|InternetException>) : void
|
* @phpstan-var \Closure(list<InternetRequestResult|InternetException>) : void
|
||||||
*/
|
*/
|
||||||
$callback = $this->fetchLocal(self::TLS_KEY_COMPLETION_CALLBACK);
|
$callback = $this->fetchLocal(self::TLS_KEY_COMPLETION_CALLBACK);
|
||||||
/** @var InternetRequestResult[]|InternetException[] $results */
|
/**
|
||||||
|
* @var InternetRequestResult[]|InternetException[] $results
|
||||||
|
* @phpstan-var list<InternetRequestResult|InternetException> $results
|
||||||
|
*/
|
||||||
$results = $this->getResult();
|
$results = $this->getResult();
|
||||||
$callback($results);
|
$callback($results);
|
||||||
}
|
}
|
||||||
|
@ -123,6 +123,7 @@ class TimingsHandler{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
|
* @phpstan-return list<string>
|
||||||
*/
|
*/
|
||||||
private static function printFooter() : array{
|
private static function printFooter() : array{
|
||||||
$result = [];
|
$result = [];
|
||||||
@ -173,6 +174,7 @@ class TimingsHandler{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @phpstan-var PromiseResolver<list<string>> $resolver */
|
||||||
$resolver = new PromiseResolver();
|
$resolver = new PromiseResolver();
|
||||||
Promise::all($otherThreadRecordPromises)->onCompletion(
|
Promise::all($otherThreadRecordPromises)->onCompletion(
|
||||||
function(array $promisedRecords) use ($resolver, $thisThreadRecords) : void{
|
function(array $promisedRecords) use ($resolver, $thisThreadRecords) : void{
|
||||||
|
@ -131,7 +131,7 @@ final class TimingsRecord{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function stopTiming(int $now) : void{
|
public function stopTiming(int $now) : void{
|
||||||
if($this->start == 0){
|
if($this->start === 0){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(self::$currentRecord !== $this){
|
if(self::$currentRecord !== $this){
|
||||||
|
@ -113,6 +113,7 @@ use function array_keys;
|
|||||||
use function array_map;
|
use function array_map;
|
||||||
use function array_merge;
|
use function array_merge;
|
||||||
use function array_sum;
|
use function array_sum;
|
||||||
|
use function array_values;
|
||||||
use function assert;
|
use function assert;
|
||||||
use function cos;
|
use function cos;
|
||||||
use function count;
|
use function count;
|
||||||
@ -678,7 +679,6 @@ class World implements ChunkManager{
|
|||||||
* Used for broadcasting sounds and particles with specific targets.
|
* Used for broadcasting sounds and particles with specific targets.
|
||||||
*
|
*
|
||||||
* @param Player[] $allowed
|
* @param Player[] $allowed
|
||||||
* @phpstan-param list<Player> $allowed
|
|
||||||
*
|
*
|
||||||
* @return array<int, Player>
|
* @return array<int, Player>
|
||||||
*/
|
*/
|
||||||
@ -1089,7 +1089,6 @@ class World implements ChunkManager{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Vector3[] $blocks
|
* @param Vector3[] $blocks
|
||||||
* @phpstan-param list<Vector3> $blocks
|
|
||||||
*
|
*
|
||||||
* @return ClientboundPacket[]
|
* @return ClientboundPacket[]
|
||||||
* @phpstan-return list<ClientboundPacket>
|
* @phpstan-return list<ClientboundPacket>
|
||||||
@ -1456,8 +1455,8 @@ class World implements ChunkManager{
|
|||||||
$this->provider->saveChunk($chunkX, $chunkZ, new ChunkData(
|
$this->provider->saveChunk($chunkX, $chunkZ, new ChunkData(
|
||||||
$chunk->getSubChunks(),
|
$chunk->getSubChunks(),
|
||||||
$chunk->isPopulated(),
|
$chunk->isPopulated(),
|
||||||
array_map(fn(Entity $e) => $e->saveNBT(), array_filter($this->getChunkEntities($chunkX, $chunkZ), fn(Entity $e) => $e->canSaveWithChunk())),
|
array_map(fn(Entity $e) => $e->saveNBT(), array_values(array_filter($this->getChunkEntities($chunkX, $chunkZ), fn(Entity $e) => $e->canSaveWithChunk()))),
|
||||||
array_map(fn(Tile $t) => $t->saveNBT(), $chunk->getTiles()),
|
array_map(fn(Tile $t) => $t->saveNBT(), array_values($chunk->getTiles())),
|
||||||
), $chunk->getTerrainDirtyFlags());
|
), $chunk->getTerrainDirtyFlags());
|
||||||
$chunk->clearTerrainDirtyFlags();
|
$chunk->clearTerrainDirtyFlags();
|
||||||
}
|
}
|
||||||
@ -3019,8 +3018,8 @@ class World implements ChunkManager{
|
|||||||
$this->provider->saveChunk($x, $z, new ChunkData(
|
$this->provider->saveChunk($x, $z, new ChunkData(
|
||||||
$chunk->getSubChunks(),
|
$chunk->getSubChunks(),
|
||||||
$chunk->isPopulated(),
|
$chunk->isPopulated(),
|
||||||
array_map(fn(Entity $e) => $e->saveNBT(), array_filter($this->getChunkEntities($x, $z), fn(Entity $e) => $e->canSaveWithChunk())),
|
array_map(fn(Entity $e) => $e->saveNBT(), array_values(array_filter($this->getChunkEntities($x, $z), fn(Entity $e) => $e->canSaveWithChunk()))),
|
||||||
array_map(fn(Tile $t) => $t->saveNBT(), $chunk->getTiles()),
|
array_map(fn(Tile $t) => $t->saveNBT(), array_values($chunk->getTiles())),
|
||||||
), $chunk->getTerrainDirtyFlags());
|
), $chunk->getTerrainDirtyFlags());
|
||||||
}finally{
|
}finally{
|
||||||
$this->timings->syncChunkSave->stopTiming();
|
$this->timings->syncChunkSave->stopTiming();
|
||||||
|
@ -33,10 +33,8 @@ use pocketmine\world\format\io\exception\CorruptedChunkException;
|
|||||||
use pocketmine\world\format\io\LoadedChunkData;
|
use pocketmine\world\format\io\LoadedChunkData;
|
||||||
use pocketmine\world\format\io\WorldData;
|
use pocketmine\world\format\io\WorldData;
|
||||||
use Symfony\Component\Filesystem\Path;
|
use Symfony\Component\Filesystem\Path;
|
||||||
use function assert;
|
|
||||||
use function file_exists;
|
use function file_exists;
|
||||||
use function is_dir;
|
use function is_dir;
|
||||||
use function is_int;
|
|
||||||
use function morton2d_encode;
|
use function morton2d_encode;
|
||||||
use function rename;
|
use function rename;
|
||||||
use function scandir;
|
use function scandir;
|
||||||
@ -60,7 +58,12 @@ abstract class RegionWorldProvider extends BaseWorldProvider{
|
|||||||
|
|
||||||
public static function isValid(string $path) : bool{
|
public static function isValid(string $path) : bool{
|
||||||
if(file_exists(Path::join($path, "level.dat")) && is_dir($regionPath = Path::join($path, "region"))){
|
if(file_exists(Path::join($path, "level.dat")) && is_dir($regionPath = Path::join($path, "region"))){
|
||||||
foreach(scandir($regionPath, SCANDIR_SORT_NONE) as $file){
|
$files = scandir($regionPath, SCANDIR_SORT_NONE);
|
||||||
|
if($files === false){
|
||||||
|
//we can't tell the type if we don't have read perms
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
foreach($files as $file){
|
||||||
$extPos = strrpos($file, ".");
|
$extPos = strrpos($file, ".");
|
||||||
if($extPos !== false && substr($file, $extPos + 1) === static::getRegionFileExtension()){
|
if($extPos !== false && substr($file, $extPos + 1) === static::getRegionFileExtension()){
|
||||||
//we don't care if other region types exist, we only care if this format is possible
|
//we don't care if other region types exist, we only care if this format is possible
|
||||||
@ -199,7 +202,6 @@ abstract class RegionWorldProvider extends BaseWorldProvider{
|
|||||||
public function loadChunk(int $chunkX, int $chunkZ) : ?LoadedChunkData{
|
public function loadChunk(int $chunkX, int $chunkZ) : ?LoadedChunkData{
|
||||||
$regionX = $regionZ = null;
|
$regionX = $regionZ = null;
|
||||||
self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ);
|
self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ);
|
||||||
assert(is_int($regionX) && is_int($regionZ));
|
|
||||||
|
|
||||||
if(!file_exists($this->pathToRegion($regionX, $regionZ))){
|
if(!file_exists($this->pathToRegion($regionX, $regionZ))){
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user