Promote some constructors

This commit is contained in:
Dylan K. Taylor 2022-05-17 22:34:58 +01:00
parent 8e767da29e
commit d4b7f66e15
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
30 changed files with 144 additions and 218 deletions

View File

@ -69,9 +69,6 @@ use const JSON_UNESCAPED_SLASHES;
use const SORT_NUMERIC; use const SORT_NUMERIC;
class MemoryManager{ class MemoryManager{
private Server $server;
private int $memoryLimit; private int $memoryLimit;
private int $globalMemoryLimit; private int $globalMemoryLimit;
private int $checkRate; private int $checkRate;
@ -98,8 +95,9 @@ class MemoryManager{
private \Logger $logger; private \Logger $logger;
public function __construct(Server $server){ public function __construct(
$this->server = $server; private Server $server
){
$this->logger = new \PrefixedLogger($server->getLogger(), "Memory Manager"); $this->logger = new \PrefixedLogger($server->getLogger(), "Memory Manager");
$this->init($server->getConfigGroup()); $this->init($server->getConfigGroup());

View File

@ -223,8 +223,6 @@ class Server{
private int $sendUsageTicker = 0; private int $sendUsageTicker = 0;
private \AttachableThreadedLogger $logger;
private MemoryManager $memoryManager; private MemoryManager $memoryManager;
private ConsoleReaderThread $console; private ConsoleReaderThread $console;
@ -249,7 +247,6 @@ class Server{
private UuidInterface $serverID; private UuidInterface $serverID;
private \DynamicClassLoader $autoloader;
private string $dataPath; private string $dataPath;
private string $pluginPath; private string $pluginPath;
@ -766,7 +763,12 @@ class Server{
return self::$instance; return self::$instance;
} }
public function __construct(\DynamicClassLoader $autoloader, \AttachableThreadedLogger $logger, string $dataPath, string $pluginPath){ public function __construct(
private \DynamicClassLoader $autoloader,
private \AttachableThreadedLogger $logger,
string $dataPath,
string $pluginPath
){
if(self::$instance !== null){ if(self::$instance !== null){
throw new \LogicException("Only one server instance can exist at once"); throw new \LogicException("Only one server instance can exist at once");
} }
@ -774,8 +776,6 @@ class Server{
$this->startTime = microtime(true); $this->startTime = microtime(true);
$this->tickSleeper = new SleeperHandler(); $this->tickSleeper = new SleeperHandler();
$this->autoloader = $autoloader;
$this->logger = $logger;
$this->signalHandler = new SignalHandler(function() : void{ $this->signalHandler = new SignalHandler(function() : void{
$this->logger->info("Received signal interrupt, stopping the server"); $this->logger->info("Received signal interrupt, stopping the server");

View File

@ -32,20 +32,16 @@ use function is_string;
use function strtolower; use function strtolower;
final class ServerConfigGroup{ final class ServerConfigGroup{
private Config $pocketmineYml;
private Config $serverProperties;
/** /**
* @var mixed[] * @var mixed[]
* @phpstan-var array<string, mixed> * @phpstan-var array<string, mixed>
*/ */
private array $propertyCache = []; private array $propertyCache = [];
public function __construct(Config $pocketmineYml, Config $serverProperties){ public function __construct(
$this->pocketmineYml = $pocketmineYml; private Config $pocketmineYml,
$this->serverProperties = $serverProperties; private Config $serverProperties
} ){}
/** /**
* @param mixed $defaultValue * @param mixed $defaultValue

View File

@ -38,18 +38,17 @@ class BlockBreakInfo{
*/ */
public const INCOMPATIBLE_TOOL_MULTIPLIER = 5.0; public const INCOMPATIBLE_TOOL_MULTIPLIER = 5.0;
private float $hardness;
private float $blastResistance; private float $blastResistance;
private int $toolType;
private int $toolHarvestLevel;
/** /**
* @param float|null $blastResistance default 5x hardness * @param float|null $blastResistance default 5x hardness
*/ */
public function __construct(float $hardness, int $toolType = BlockToolType::NONE, int $toolHarvestLevel = 0, ?float $blastResistance = null){ public function __construct(
$this->hardness = $hardness; private float $hardness,
$this->toolType = $toolType; private int $toolType = BlockToolType::NONE,
$this->toolHarvestLevel = $toolHarvestLevel; private int $toolHarvestLevel = 0,
?float $blastResistance = null
){
$this->blastResistance = $blastResistance ?? $hardness * 5; $this->blastResistance = $blastResistance ?? $hardness * 5;
} }

View File

@ -27,25 +27,18 @@ use pocketmine\block\tile\Tile;
use pocketmine\utils\Utils; use pocketmine\utils\Utils;
class BlockIdentifier{ class BlockIdentifier{
private int $blockId;
private int $variant;
private ?int $itemId;
/** @phpstan-var class-string<Tile>|null */
private ?string $tileClass;
/** /**
* @phpstan-param class-string<Tile>|null $tileClass * @phpstan-param class-string<Tile>|null $tileClass
*/ */
public function __construct(int $blockId, int $variant, ?int $itemId = null, ?string $tileClass = null){ public function __construct(
$this->blockId = $blockId; private int $blockId,
$this->variant = $variant; private int $variant,
$this->itemId = $itemId; private ?int $itemId = null,
private ?string $tileClass = null
){
if($tileClass !== null){ if($tileClass !== null){
Utils::testValidInstance($tileClass, Tile::class); Utils::testValidInstance($tileClass, Tile::class);
} }
$this->tileClass = $tileClass;
} }
public function getBlockId() : int{ public function getBlockId() : int{

View File

@ -24,16 +24,15 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
class Element extends Opaque{ class Element extends Opaque{
public function __construct(
private int $atomicWeight; BlockIdentifier $idInfo,
private int $group; string $name,
private string $symbol; BlockBreakInfo $breakInfo,
private string $symbol,
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo, string $symbol, int $atomicWeight, int $group){ private int $atomicWeight,
private int $group
){
parent::__construct($idInfo, $name, $breakInfo); parent::__construct($idInfo, $name, $breakInfo);
$this->atomicWeight = $atomicWeight;
$this->group = $group;
$this->symbol = $symbol;
} }
public function getAtomicWeight() : int{ public function getAtomicWeight() : int{

View File

@ -33,12 +33,10 @@ use pocketmine\world\sound\Sound;
class DoubleChestInventory extends BaseInventory implements BlockInventory, InventoryHolder{ class DoubleChestInventory extends BaseInventory implements BlockInventory, InventoryHolder{
use AnimatedBlockInventoryTrait; use AnimatedBlockInventoryTrait;
private ChestInventory $left; public function __construct(
private ChestInventory $right; private ChestInventory $left,
private ChestInventory $right
public function __construct(ChestInventory $left, ChestInventory $right){ ){
$this->left = $left;
$this->right = $right;
$this->holder = $this->left->getHolder(); $this->holder = $this->left->getHolder();
parent::__construct(); parent::__construct();
} }

View File

@ -43,12 +43,12 @@ class EnderChestInventory extends DelegateInventory implements BlockInventory{
onClose as animatedBlockInventoryTrait_onClose; onClose as animatedBlockInventoryTrait_onClose;
} }
private PlayerEnderInventory $inventory; public function __construct(
Position $holder,
public function __construct(Position $holder, PlayerEnderInventory $inventory){ private PlayerEnderInventory $inventory
){
parent::__construct($inventory); parent::__construct($inventory);
$this->holder = $holder; $this->holder = $holder;
$this->inventory = $inventory;
} }
public function getEnderInventory() : PlayerEnderInventory{ public function getEnderInventory() : PlayerEnderInventory{

View File

@ -35,11 +35,11 @@ class FurnaceInventory extends SimpleInventory implements BlockInventory{
public const SLOT_FUEL = 1; public const SLOT_FUEL = 1;
public const SLOT_RESULT = 2; public const SLOT_RESULT = 2;
private FurnaceType $furnaceType; public function __construct(
Position $holder,
public function __construct(Position $holder, FurnaceType $furnaceType){ private FurnaceType $furnaceType
){
$this->holder = $holder; $this->holder = $holder;
$this->furnaceType = $furnaceType;
parent::__construct(3); parent::__construct(3);
} }

View File

@ -45,15 +45,14 @@ class FormattedCommandAlias extends Command{
*/ */
private const FORMAT_STRING_REGEX = '/\G\$(\$)?((?!0)+\d+)(-)?/'; private const FORMAT_STRING_REGEX = '/\G\$(\$)?((?!0)+\d+)(-)?/';
/** @var string[] */
private array $formatStrings = [];
/** /**
* @param string[] $formatStrings * @param string[] $formatStrings
*/ */
public function __construct(string $alias, array $formatStrings){ public function __construct(
string $alias,
private array $formatStrings
){
parent::__construct($alias); parent::__construct($alias);
$this->formatStrings = $formatStrings;
} }
public function execute(CommandSender $sender, string $commandLabel, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){

View File

@ -26,23 +26,20 @@ namespace pocketmine\command;
use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\plugin\Plugin; use pocketmine\plugin\Plugin;
use pocketmine\plugin\PluginOwned; use pocketmine\plugin\PluginOwned;
use pocketmine\plugin\PluginOwnedTrait;
final class PluginCommand extends Command implements PluginOwned{ final class PluginCommand extends Command implements PluginOwned{
use PluginOwnedTrait; public function __construct(
string $name,
private CommandExecutor $executor; private Plugin $owner,
private CommandExecutor $executor
public function __construct(string $name, Plugin $owner, CommandExecutor $executor){ ){
parent::__construct($name); parent::__construct($name);
$this->owningPlugin = $owner;
$this->executor = $executor;
$this->usageMessage = ""; $this->usageMessage = "";
} }
public function execute(CommandSender $sender, string $commandLabel, array $args){ public function execute(CommandSender $sender, string $commandLabel, array $args){
if(!$this->owningPlugin->isEnabled()){ if(!$this->owner->isEnabled()){
return false; return false;
} }
@ -59,6 +56,10 @@ final class PluginCommand extends Command implements PluginOwned{
return $success; return $success;
} }
public function getOwningPlugin() : Plugin{
return $this->owner;
}
public function getExecutor() : CommandExecutor{ public function getExecutor() : CommandExecutor{
return $this->executor; return $this->executor;
} }

View File

@ -46,13 +46,10 @@ use const PHP_BINARY;
use const STREAM_SHUT_RDWR; use const STREAM_SHUT_RDWR;
final class ConsoleReaderThread extends Thread{ final class ConsoleReaderThread extends Thread{
private \Threaded $buffer; public function __construct(
private ?SleeperNotifier $notifier; private \Threaded $buffer,
private ?SleeperNotifier $notifier = null
public function __construct(\Threaded $buffer, ?SleeperNotifier $notifier = null){ ){}
$this->buffer = $buffer;
$this->notifier = $notifier;
}
protected function onRun() : void{ protected function onRun() : void{
$buffer = $this->buffer; $buffer = $this->buffer;

View File

@ -33,15 +33,14 @@ abstract class CraftingGrid extends SimpleInventory{
public const SIZE_SMALL = 2; public const SIZE_SMALL = 2;
public const SIZE_BIG = 3; public const SIZE_BIG = 3;
private int $gridWidth;
private ?int $startX = null; private ?int $startX = null;
private ?int $xLen = null; private ?int $xLen = null;
private ?int $startY = null; private ?int $startY = null;
private ?int $yLen = null; private ?int $yLen = null;
public function __construct(int $gridWidth){ public function __construct(
$this->gridWidth = $gridWidth; private int $gridWidth
){
parent::__construct($this->getGridWidth() ** 2); parent::__construct($this->getGridWidth() ** 2);
} }

View File

@ -29,13 +29,12 @@ use pocketmine\player\Player;
* Called when a player requests a different viewing distance than the current one. * Called when a player requests a different viewing distance than the current one.
*/ */
class PlayerViewDistanceChangeEvent extends PlayerEvent{ class PlayerViewDistanceChangeEvent extends PlayerEvent{
protected int $newDistance; public function __construct(
protected int $oldDistance; Player $player,
protected int $oldDistance,
public function __construct(Player $player, int $oldDistance, int $newDistance){ protected int $newDistance
){
$this->player = $player; $this->player = $player;
$this->oldDistance = $oldDistance;
$this->newDistance = $newDistance;
} }
/** /**

View File

@ -31,13 +31,12 @@ use function count;
* An inventory which is backed by another inventory, and acts as a proxy to that inventory. * An inventory which is backed by another inventory, and acts as a proxy to that inventory.
*/ */
class DelegateInventory extends BaseInventory{ class DelegateInventory extends BaseInventory{
private Inventory $backingInventory;
private InventoryListener $inventoryListener; private InventoryListener $inventoryListener;
public function __construct(Inventory $backingInventory){ public function __construct(
private Inventory $backingInventory
){
parent::__construct(); parent::__construct();
$this->backingInventory = $backingInventory;
$this->backingInventory->getListeners()->add($this->inventoryListener = new CallbackInventoryListener( $this->backingInventory->getListeners()->add($this->inventoryListener = new CallbackInventoryListener(
function(Inventory $unused, int $slot, Item $oldItem) : void{ function(Inventory $unused, int $slot, Item $oldItem) : void{
$this->onSlotChange($slot, $oldItem); $this->onSlotChange($slot, $oldItem);

View File

@ -26,11 +26,10 @@ namespace pocketmine\inventory;
use pocketmine\entity\Human; use pocketmine\entity\Human;
final class PlayerEnderInventory extends SimpleInventory{ final class PlayerEnderInventory extends SimpleInventory{
public function __construct(
private Human $holder; private Human $holder,
int $size = 27
public function __construct(Human $holder, int $size = 27){ ){
$this->holder = $holder;
parent::__construct($size); parent::__construct($size);
} }

View File

@ -81,8 +81,6 @@ final class PotionType{
__construct as Enum___construct; __construct as Enum___construct;
} }
private string $displayName;
protected static function setup() : void{ protected static function setup() : void{
self::registerAll( self::registerAll(
new self("water", "Water", fn() => []), new self("water", "Water", fn() => []),
@ -204,16 +202,15 @@ final class PotionType{
); );
} }
/** @phpstan-var \Closure() : list<EffectInstance> */
private \Closure $effectsGetter;
/** /**
* @phpstan-param \Closure() : list<EffectInstance> $effectsGetter * @phpstan-param \Closure() : list<EffectInstance> $effectsGetter
*/ */
private function __construct(string $enumName, string $displayName, \Closure $effectsGetter){ private function __construct(
string $enumName,
private string $displayName,
private \Closure $effectsGetter
){
$this->Enum___construct($enumName); $this->Enum___construct($enumName);
$this->displayName = $displayName;
$this->effectsGetter = $effectsGetter;
} }
public function getDisplayName() : string{ return $this->displayName; } public function getDisplayName() : string{ return $this->displayName; }

View File

@ -136,11 +136,7 @@ use const SORT_NUMERIC;
class NetworkSession{ class NetworkSession{
private \PrefixedLogger $logger; private \PrefixedLogger $logger;
private Server $server;
private ?Player $player = null; private ?Player $player = null;
private NetworkSessionManager $manager;
private string $ip;
private int $port;
private ?PlayerInfo $info = null; private ?PlayerInfo $info = null;
private ?int $ping = null; private ?int $ping = null;
@ -163,37 +159,31 @@ class NetworkSession{
* @phpstan-var \SplQueue<CompressBatchPromise> * @phpstan-var \SplQueue<CompressBatchPromise>
*/ */
private \SplQueue $compressedQueue; private \SplQueue $compressedQueue;
private Compressor $compressor;
private bool $forceAsyncCompression = true; private bool $forceAsyncCompression = true;
private PacketPool $packetPool;
private PacketSerializerContext $packetSerializerContext; private PacketSerializerContext $packetSerializerContext;
private ?InventoryManager $invManager = null; private ?InventoryManager $invManager = null;
private PacketSender $sender;
private PacketBroadcaster $broadcaster;
/** /**
* @var \Closure[]|ObjectSet * @var \Closure[]|ObjectSet
* @phpstan-var ObjectSet<\Closure() : void> * @phpstan-var ObjectSet<\Closure() : void>
*/ */
private ObjectSet $disposeHooks; private ObjectSet $disposeHooks;
public function __construct(Server $server, NetworkSessionManager $manager, PacketPool $packetPool, PacketSender $sender, PacketBroadcaster $broadcaster, Compressor $compressor, string $ip, int $port){ public function __construct(
$this->server = $server; private Server $server,
$this->manager = $manager; private NetworkSessionManager $manager,
$this->sender = $sender; private PacketPool $packetPool,
$this->broadcaster = $broadcaster; private PacketSender $sender,
$this->ip = $ip; private PacketBroadcaster $broadcaster,
$this->port = $port; private Compressor $compressor,
private string $ip,
private int $port
){
$this->logger = new \PrefixedLogger($this->server->getLogger(), $this->getLogPrefix()); $this->logger = new \PrefixedLogger($this->server->getLogger(), $this->getLogPrefix());
$this->compressedQueue = new \SplQueue(); $this->compressedQueue = new \SplQueue();
$this->compressor = $compressor;
$this->packetPool = $packetPool;
//TODO: allow this to be injected //TODO: allow this to be injected
$this->packetSerializerContext = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary()); $this->packetSerializerContext = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary());

View File

@ -56,11 +56,9 @@ final class GlobalItemTypeDictionary{
return new self(new ItemTypeDictionary($params)); return new self(new ItemTypeDictionary($params));
} }
private ItemTypeDictionary $dictionary; public function __construct(
private ItemTypeDictionary $dictionary
public function __construct(ItemTypeDictionary $dictionary){ ){}
$this->dictionary = $dictionary;
}
public function getDictionary() : ItemTypeDictionary{ return $this->dictionary; } public function getDictionary() : ItemTypeDictionary{ return $this->dictionary; }
} }

View File

@ -27,13 +27,10 @@ use pocketmine\snooze\SleeperNotifier;
use raklib\server\ipc\InterThreadChannelWriter; use raklib\server\ipc\InterThreadChannelWriter;
final class SnoozeAwarePthreadsChannelWriter implements InterThreadChannelWriter{ final class SnoozeAwarePthreadsChannelWriter implements InterThreadChannelWriter{
private \Threaded $buffer; public function __construct(
private SleeperNotifier $notifier; private \Threaded $buffer,
private SleeperNotifier $notifier
public function __construct(\Threaded $buffer, SleeperNotifier $notifier){ ){}
$this->buffer = $buffer;
$this->notifier = $notifier;
}
public function write(string $str) : void{ public function write(string $str) : void{
$this->buffer[] = $str; $this->buffer[] = $str;

View File

@ -66,19 +66,15 @@ final class PluginEnableOrder{
return self::$aliasMap[mb_strtolower($name)] ?? null; return self::$aliasMap[mb_strtolower($name)] ?? null;
} }
/**
* @var string[]
* @phpstan-var list<string>
*/
private array $aliases;
/** /**
* @param string[] $aliases * @param string[] $aliases
* @phpstan-param list<string> $aliases * @phpstan-param list<string> $aliases
*/ */
private function __construct(string $enumName, array $aliases){ private function __construct(
string $enumName,
private array $aliases
){
$this->Enum___construct($enumName); $this->Enum___construct($enumName);
$this->aliases = $aliases;
} }
/** /**

View File

@ -30,18 +30,11 @@ use Webmozart\PathUtil\Path;
* Task used to dump memory from AsyncWorkers * Task used to dump memory from AsyncWorkers
*/ */
class DumpWorkerMemoryTask extends AsyncTask{ class DumpWorkerMemoryTask extends AsyncTask{
/** @var string */ public function __construct(
private $outputFolder; private string $outputFolder,
/** @var int */ private int $maxNesting,
private $maxNesting; private int $maxStringSize
/** @var int */ ){}
private $maxStringSize;
public function __construct(string $outputFolder, int $maxNesting, int $maxStringSize){
$this->outputFolder = $outputFolder;
$this->maxNesting = $maxNesting;
$this->maxStringSize = $maxStringSize;
}
public function onRun() : void{ public function onRun() : void{
MemoryManager::dumpMemory( MemoryManager::dumpMemory(

View File

@ -32,17 +32,14 @@ use function json_decode;
class UpdateCheckTask extends AsyncTask{ class UpdateCheckTask extends AsyncTask{
private const TLS_KEY_UPDATER = "updater"; private const TLS_KEY_UPDATER = "updater";
/** @var string */ private string $error = "Unknown error";
private $endpoint;
/** @var string */
private $channel;
/** @var string */
private $error = "Unknown error";
public function __construct(UpdateChecker $updater, string $endpoint, string $channel){ public function __construct(
UpdateChecker $updater,
private string $endpoint,
private string $channel
){
$this->storeLocal(self::TLS_KEY_UPDATER, $updater); $this->storeLocal(self::TLS_KEY_UPDATER, $updater);
$this->endpoint = $endpoint;
$this->channel = $channel;
} }
public function onRun() : void{ public function onRun() : void{

View File

@ -35,19 +35,11 @@ class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{
/** @var bool */ /** @var bool */
protected $logDebug; protected $logDebug;
/** @var string */ private string $format = TextFormat::AQUA . "[%s] " . TextFormat::RESET . "%s[%s/%s]: %s" . TextFormat::RESET;
private $format = TextFormat::AQUA . "[%s] " . TextFormat::RESET . "%s[%s/%s]: %s" . TextFormat::RESET; private bool $useFormattingCodes = false;
/** @var bool */
private $useFormattingCodes = false;
private string $mainThreadName; private string $mainThreadName;
private string $timezone;
/** @var string */ private MainLoggerThread $logWriterThread;
private $timezone;
/** @var MainLoggerThread */
private $logWriterThread;
/** /**
* @throws \RuntimeException * @throws \RuntimeException

View File

@ -30,16 +30,15 @@ use function is_resource;
use function touch; use function touch;
final class MainLoggerThread extends \Thread{ final class MainLoggerThread extends \Thread{
private string $logFile;
private \Threaded $buffer; private \Threaded $buffer;
private bool $syncFlush = false; private bool $syncFlush = false;
private bool $shutdown = false; private bool $shutdown = false;
public function __construct(string $logFile){ public function __construct(
private string $logFile
){
$this->buffer = new \Threaded(); $this->buffer = new \Threaded();
touch($logFile); touch($this->logFile);
$this->logFile = $logFile;
} }
public function write(string $line) : void{ public function write(string $line) : void{

View File

@ -28,13 +28,12 @@ namespace pocketmine\world\format\io;
*/ */
class ReadOnlyWorldProviderManagerEntry extends WorldProviderManagerEntry{ class ReadOnlyWorldProviderManagerEntry extends WorldProviderManagerEntry{
/** @phpstan-var FromPath */
private \Closure $fromPath;
/** @phpstan-param FromPath $fromPath */ /** @phpstan-param FromPath $fromPath */
public function __construct(\Closure $isValid, \Closure $fromPath){ public function __construct(
\Closure $isValid,
private \Closure $fromPath
){
parent::__construct($isValid); parent::__construct($isValid);
$this->fromPath = $fromPath;
} }
public function fromPath(string $path) : WorldProvider{ return ($this->fromPath)($path); } public function fromPath(string $path) : WorldProvider{ return ($this->fromPath)($path); }

View File

@ -31,13 +31,10 @@ use pocketmine\world\format\io\exception\UnsupportedWorldFormatException;
*/ */
abstract class WorldProviderManagerEntry{ abstract class WorldProviderManagerEntry{
/** @phpstan-var IsValid */
protected \Closure $isValid;
/** @phpstan-param IsValid $isValid */ /** @phpstan-param IsValid $isValid */
protected function __construct(\Closure $isValid){ protected function __construct(
$this->isValid = $isValid; protected \Closure $isValid
} ){}
/** /**
* Tells if the path is a valid world. * Tells if the path is a valid world.

View File

@ -30,19 +30,17 @@ use pocketmine\world\WorldCreationOptions;
* @phpstan-type Generate \Closure(string $path, string $name, WorldCreationOptions $options) : void * @phpstan-type Generate \Closure(string $path, string $name, WorldCreationOptions $options) : void
*/ */
final class WritableWorldProviderManagerEntry extends WorldProviderManagerEntry{ final class WritableWorldProviderManagerEntry extends WorldProviderManagerEntry{
/** @phpstan-var FromPath */
private \Closure $fromPath;
/** @phpstan-var Generate */
private \Closure $generate;
/** /**
* @phpstan-param FromPath $fromPath * @phpstan-param FromPath $fromPath
* @phpstan-param Generate $generate * @phpstan-param Generate $generate
*/ */
public function __construct(\Closure $isValid, \Closure $fromPath, \Closure $generate){ public function __construct(
\Closure $isValid,
private \Closure $fromPath,
private \Closure $generate
){
parent::__construct($isValid); parent::__construct($isValid);
$this->fromPath = $fromPath;
$this->generate = $generate;
} }
public function fromPath(string $path) : WritableWorldProvider{ public function fromPath(string $path) : WritableWorldProvider{

View File

@ -26,13 +26,10 @@ namespace pocketmine\world\generator;
use function exp; use function exp;
final class Gaussian{ final class Gaussian{
public int $smoothSize;
/** @var float[][] */ /** @var float[][] */
public array $kernel = []; public array $kernel = [];
public function __construct(int $smoothSize){ public function __construct(public int $smoothSize){
$this->smoothSize = $smoothSize;
$bellSize = 1 / $this->smoothSize; $bellSize = 1 / $this->smoothSize;
$bellHeight = 2 * $this->smoothSize; $bellHeight = 2 * $this->smoothSize;

View File

@ -41,10 +41,6 @@ use function igbinary_unserialize;
class PopulationTask extends AsyncTask{ class PopulationTask extends AsyncTask{
private const TLS_KEY_ON_COMPLETION = "onCompletion"; private const TLS_KEY_ON_COMPLETION = "onCompletion";
private int $worldId;
private int $chunkX;
private int $chunkZ;
private ?string $chunk; private ?string $chunk;
private string $adjacentChunks; private string $adjacentChunks;
@ -54,10 +50,14 @@ class PopulationTask extends AsyncTask{
* @phpstan-param array<int, Chunk|null> $adjacentChunks * @phpstan-param array<int, Chunk|null> $adjacentChunks
* @phpstan-param OnCompletion $onCompletion * @phpstan-param OnCompletion $onCompletion
*/ */
public function __construct(int $worldId, int $chunkX, int $chunkZ, ?Chunk $chunk, array $adjacentChunks, \Closure $onCompletion){ public function __construct(
$this->worldId = $worldId; private int $worldId,
$this->chunkX = $chunkX; private int $chunkX,
$this->chunkZ = $chunkZ; private int $chunkZ,
?Chunk $chunk,
array $adjacentChunks,
\Closure $onCompletion
){
$this->chunk = $chunk !== null ? FastChunkSerializer::serializeTerrain($chunk) : null; $this->chunk = $chunk !== null ? FastChunkSerializer::serializeTerrain($chunk) : null;
$this->adjacentChunks = igbinary_serialize(array_map( $this->adjacentChunks = igbinary_serialize(array_map(