From 083a35f97023a2b844feee56c1d84864f5235e1d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 4 Jun 2022 18:16:32 +0100 Subject: [PATCH] Modernize property type declarations --- src/block/tile/Barrel.php | 3 +- src/block/tile/Chest.php | 6 +- src/block/tile/Comparator.php | 3 +- src/block/tile/Furnace.php | 3 +- src/block/tile/ShulkerBox.php | 6 +- src/block/tile/Sign.php | 7 +- src/block/tile/Tile.php | 9 +- src/block/utils/AnyFacingTrait.php | 3 +- src/block/utils/HorizontalFacingTrait.php | 3 +- src/block/utils/PillarRotationTrait.php | 4 +- src/command/Command.php | 9 +- src/command/SimpleCommandMap.php | 2 +- src/console/ConsoleCommandSender.php | 7 +- src/crafting/CraftingManager.php | 10 +- src/crafting/FurnaceRecipeManager.php | 2 +- src/entity/Attribute.php | 31 ++--- src/entity/object/PaintingMotive.php | 2 +- src/event/Event.php | 3 +- src/event/block/BlockBreakEvent.php | 26 ++-- src/event/block/BlockEvent.php | 9 +- src/event/block/BlockPlaceEvent.php | 23 +--- .../entity/EntityCombustByBlockEvent.php | 3 +- .../entity/EntityCombustByEntityEvent.php | 3 +- src/event/entity/EntityCombustEvent.php | 3 +- src/event/entity/EntityEvent.php | 7 +- src/event/entity/EntityExplodeEvent.php | 19 +-- src/event/entity/ExplosionPrimeEvent.php | 8 +- src/event/inventory/InventoryEvent.php | 9 +- src/event/player/PlayerChatEvent.php | 21 +-- .../player/PlayerCommandPreprocessEvent.php | 9 +- src/event/player/PlayerDataSaveEvent.php | 14 +- src/event/player/PlayerDeathEvent.php | 3 +- src/event/player/PlayerEvent.php | 3 +- src/event/player/PlayerExhaustEvent.php | 8 +- .../player/PlayerExperienceChangeEvent.php | 3 - .../player/PlayerGameModeChangeEvent.php | 11 +- src/event/player/PlayerInteractEvent.php | 28 ++-- src/event/player/PlayerJoinEvent.php | 9 +- src/event/player/PlayerKickEvent.php | 14 +- src/event/player/PlayerLoginEvent.php | 9 +- src/event/player/PlayerPreLoginEvent.php | 11 +- src/event/player/PlayerQuitEvent.php | 14 +- src/event/player/PlayerRespawnEvent.php | 9 +- src/event/player/PlayerToggleFlightEvent.php | 9 +- src/event/player/PlayerToggleSneakEvent.php | 9 +- src/event/player/PlayerToggleSprintEvent.php | 9 +- src/event/player/PlayerTransferEvent.php | 17 +-- src/event/server/CommandEvent.php | 14 +- src/event/server/NetworkInterfaceEvent.php | 9 +- src/inventory/ArmorInventory.php | 8 +- src/inventory/BaseInventory.php | 7 +- src/inventory/PlayerCursorInventory.php | 13 +- src/inventory/PlayerInventory.php | 14 +- .../transaction/CraftingTransaction.php | 10 +- .../transaction/InventoryTransaction.php | 15 +-- .../transaction/action/InventoryAction.php | 13 +- .../transaction/action/SlotChangeAction.php | 14 +- src/item/Armor.php | 3 +- src/item/Durable.php | 4 +- src/item/Item.php | 32 ++--- src/item/ItemEnchantmentHandlingTrait.php | 2 +- src/item/TieredTool.php | 4 +- .../enchantment/ProtectionEnchantment.php | 5 +- src/lang/Language.php | 8 +- src/lang/Translatable.php | 12 +- src/network/mcpe/ChunkRequestTask.php | 14 +- .../mcpe/encryption/EncryptionContext.php | 3 +- .../mcpe/handler/InGamePacketHandler.php | 12 +- src/network/mcpe/raklib/RakLibServer.php | 64 ++-------- src/permission/BanEntry.php | 3 +- src/permission/PermissionManager.php | 4 +- src/player/GameMode.php | 2 +- src/plugin/PluginLoadTriage.php | 6 +- src/plugin/PluginManager.php | 6 +- src/promise/PromiseSharedData.php | 7 +- src/resourcepacks/ZippedResourcePack.php | 12 +- src/scheduler/AsyncPool.php | 9 +- src/scheduler/AsyncTask.php | 3 +- src/scheduler/TaskHandler.php | 26 ++-- src/scheduler/TaskScheduler.php | 12 +- src/stats/SendUsageTask.php | 6 +- src/thread/CommonThreadPartsTrait.php | 6 +- src/timings/Timings.php | 120 ++++++------------ src/updater/UpdateChecker.php | 10 +- src/utils/Config.php | 2 +- src/utils/Internet.php | 6 +- src/utils/MainLogger.php | 3 +- src/utils/Random.php | 3 +- src/utils/ServerKiller.php | 13 +- src/world/Explosion.php | 28 ++-- src/world/SimpleChunkManager.php | 2 +- src/world/World.php | 11 +- src/world/biome/Biome.php | 6 +- src/world/format/Chunk.php | 16 +-- src/world/format/io/BaseWorldProvider.php | 10 +- src/world/format/io/WorldProviderManager.php | 2 +- src/world/format/io/data/BaseNbtWorldData.php | 13 +- src/world/format/io/leveldb/LevelDB.php | 3 +- src/world/format/io/region/RegionLoader.php | 18 +-- .../format/io/region/RegionWorldProvider.php | 2 +- src/world/generator/Generator.php | 15 +-- src/world/generator/GeneratorRegisterTask.php | 30 ++--- .../generator/GeneratorUnregisterTask.php | 4 +- src/world/generator/noise/Noise.php | 17 +-- src/world/generator/noise/Simplex.php | 11 +- src/world/generator/object/BirchTree.php | 8 +- src/world/generator/object/Ore.php | 12 +- src/world/generator/object/Tree.php | 19 +-- src/world/light/LightPopulationTask.php | 3 +- src/world/light/LightPropagationContext.php | 18 +-- src/world/light/LightUpdate.php | 20 +-- src/world/particle/FloatingTextParticle.php | 18 +-- src/world/particle/MobSpawnParticle.php | 12 +- src/world/utils/SubChunkExplorer.php | 24 ++-- 114 files changed, 431 insertions(+), 863 deletions(-) diff --git a/src/block/tile/Barrel.php b/src/block/tile/Barrel.php index 68491cd089..e6978fca99 100644 --- a/src/block/tile/Barrel.php +++ b/src/block/tile/Barrel.php @@ -32,8 +32,7 @@ class Barrel extends Spawnable implements Container, Nameable{ use NameableTrait; use ContainerTrait; - /** @var BarrelInventory */ - protected $inventory; + protected BarrelInventory $inventory; public function __construct(World $world, Vector3 $pos){ parent::__construct($world, $pos); diff --git a/src/block/tile/Chest.php b/src/block/tile/Chest.php index 1f49a2ddb2..6f68d4e71c 100644 --- a/src/block/tile/Chest.php +++ b/src/block/tile/Chest.php @@ -44,10 +44,8 @@ class Chest extends Spawnable implements Container, Nameable{ public const TAG_PAIRZ = "pairz"; public const TAG_PAIR_LEAD = "pairlead"; - /** @var ChestInventory */ - protected $inventory; - /** @var DoubleChestInventory|null */ - protected $doubleInventory = null; + protected ChestInventory $inventory; + protected ?DoubleChestInventory $doubleInventory = null; private ?int $pairX = null; private ?int $pairZ = null; diff --git a/src/block/tile/Comparator.php b/src/block/tile/Comparator.php index 317a682f48..acc918b2cb 100644 --- a/src/block/tile/Comparator.php +++ b/src/block/tile/Comparator.php @@ -33,8 +33,7 @@ use pocketmine\nbt\tag\CompoundTag; class Comparator extends Tile{ private const TAG_OUTPUT_SIGNAL = "OutputSignal"; //int - /** @var int */ - protected $signalStrength = 0; + protected int $signalStrength = 0; public function getSignalStrength() : int{ return $this->signalStrength; diff --git a/src/block/tile/Furnace.php b/src/block/tile/Furnace.php index 806c53a07b..389e367b84 100644 --- a/src/block/tile/Furnace.php +++ b/src/block/tile/Furnace.php @@ -48,8 +48,7 @@ abstract class Furnace extends Spawnable implements Container, Nameable{ public const TAG_COOK_TIME = "CookTime"; public const TAG_MAX_TIME = "MaxTime"; - /** @var FurnaceInventory */ - protected $inventory; + protected FurnaceInventory $inventory; private int $remainingFuelTime = 0; private int $cookTime = 0; private int $maxFuelTime = 0; diff --git a/src/block/tile/ShulkerBox.php b/src/block/tile/ShulkerBox.php index fb740c5663..a649875a97 100644 --- a/src/block/tile/ShulkerBox.php +++ b/src/block/tile/ShulkerBox.php @@ -38,11 +38,9 @@ class ShulkerBox extends Spawnable implements Container, Nameable{ public const TAG_FACING = "facing"; - /** @var int */ - protected $facing = Facing::NORTH; + protected int $facing = Facing::NORTH; - /** @var ShulkerBoxInventory */ - protected $inventory; + protected ShulkerBoxInventory $inventory; public function __construct(World $world, Vector3 $pos){ parent::__construct($world, $pos); diff --git a/src/block/tile/Sign.php b/src/block/tile/Sign.php index 38cad085ff..34c288922c 100644 --- a/src/block/tile/Sign.php +++ b/src/block/tile/Sign.php @@ -50,11 +50,8 @@ class Sign extends Spawnable{ return array_slice(array_pad(explode("\n", $blob), 4, ""), 0, 4); } - /** @var SignText */ - protected $text; - - /** @var int|null */ - protected $editorEntityRuntimeId = null; + protected SignText $text; + protected ?int $editorEntityRuntimeId = null; public function __construct(World $world, Vector3 $pos){ $this->text = new SignText(); diff --git a/src/block/tile/Tile.php b/src/block/tile/Tile.php index 00ff1bed64..cc019277de 100644 --- a/src/block/tile/Tile.php +++ b/src/block/tile/Tile.php @@ -45,12 +45,9 @@ abstract class Tile{ public const TAG_Y = "y"; public const TAG_Z = "z"; - /** @var Position */ - protected $position; - /** @var bool */ - public $closed = false; - /** @var TimingsHandler */ - protected $timings; + protected Position $position; + public bool $closed = false; + protected TimingsHandler $timings; public function __construct(World $world, Vector3 $pos){ $this->position = Position::fromObject($pos, $world); diff --git a/src/block/utils/AnyFacingTrait.php b/src/block/utils/AnyFacingTrait.php index 751e673781..b8c5d8ec58 100644 --- a/src/block/utils/AnyFacingTrait.php +++ b/src/block/utils/AnyFacingTrait.php @@ -26,8 +26,7 @@ namespace pocketmine\block\utils; use pocketmine\math\Facing; trait AnyFacingTrait{ - /** @var int */ - protected $facing = Facing::DOWN; + protected int $facing = Facing::DOWN; public function getFacing() : int{ return $this->facing; } diff --git a/src/block/utils/HorizontalFacingTrait.php b/src/block/utils/HorizontalFacingTrait.php index 54cac0cda3..380d1fa50f 100644 --- a/src/block/utils/HorizontalFacingTrait.php +++ b/src/block/utils/HorizontalFacingTrait.php @@ -27,8 +27,7 @@ use pocketmine\math\Axis; use pocketmine\math\Facing; trait HorizontalFacingTrait{ - /** @var int */ - protected $facing = Facing::NORTH; + protected int $facing = Facing::NORTH; public function getFacing() : int{ return $this->facing; } diff --git a/src/block/utils/PillarRotationTrait.php b/src/block/utils/PillarRotationTrait.php index 806782db8f..ec81a4a245 100644 --- a/src/block/utils/PillarRotationTrait.php +++ b/src/block/utils/PillarRotationTrait.php @@ -32,9 +32,7 @@ use pocketmine\player\Player; use pocketmine\world\BlockTransaction; trait PillarRotationTrait{ - - /** @var int */ - protected $axis = Axis::Y; + protected int $axis = Axis::Y; /** @see Axis */ public function getAxis() : int{ return $this->axis; } diff --git a/src/command/Command.php b/src/command/Command.php index 51e3ef51c1..d6395b651c 100644 --- a/src/command/Command.php +++ b/src/command/Command.php @@ -53,17 +53,14 @@ abstract class Command{ private ?CommandMap $commandMap = null; - /** @var Translatable|string */ - protected $description = ""; + protected Translatable|string $description = ""; - /** @var Translatable|string */ - protected $usageMessage; + protected Translatable|string $usageMessage; private ?string $permission = null; private ?string $permissionMessage = null; - /** @var TimingsHandler|null */ - public $timings = null; + public ?TimingsHandler $timings = null; /** * @param string[] $aliases diff --git a/src/command/SimpleCommandMap.php b/src/command/SimpleCommandMap.php index 548f16c39d..bce6bc7405 100644 --- a/src/command/SimpleCommandMap.php +++ b/src/command/SimpleCommandMap.php @@ -80,7 +80,7 @@ use function trim; class SimpleCommandMap implements CommandMap{ /** @var Command[] */ - protected $knownCommands = []; + protected array $knownCommands = []; public function __construct(private Server $server){ $this->setDefaultCommands(); diff --git a/src/console/ConsoleCommandSender.php b/src/console/ConsoleCommandSender.php index e08a657062..b59930da63 100644 --- a/src/console/ConsoleCommandSender.php +++ b/src/console/ConsoleCommandSender.php @@ -37,11 +37,8 @@ use const PHP_INT_MAX; class ConsoleCommandSender implements CommandSender{ use PermissibleDelegateTrait; - /** - * @var int|null - * @phpstan-var positive-int|null - */ - protected $lineHeight = null; + /** @phpstan-var positive-int|null */ + protected ?int $lineHeight = null; public function __construct( private Server $server, diff --git a/src/crafting/CraftingManager.php b/src/crafting/CraftingManager.php index f9d28bf287..5ff70bf64e 100644 --- a/src/crafting/CraftingManager.php +++ b/src/crafting/CraftingManager.php @@ -35,27 +35,27 @@ class CraftingManager{ use DestructorCallbackTrait; /** @var ShapedRecipe[][] */ - protected $shapedRecipes = []; + protected array $shapedRecipes = []; /** @var ShapelessRecipe[][] */ - protected $shapelessRecipes = []; + protected array $shapelessRecipes = []; /** * @var FurnaceRecipeManager[] * @phpstan-var array */ - protected $furnaceRecipeManagers; + protected array $furnaceRecipeManagers; /** * @var PotionTypeRecipe[][] * @phpstan-var array> */ - protected $potionTypeRecipes = []; + protected array $potionTypeRecipes = []; /** * @var PotionContainerChangeRecipe[][] * @phpstan-var array> */ - protected $potionContainerChangeRecipes = []; + protected array $potionContainerChangeRecipes = []; /** @phpstan-var ObjectSet<\Closure() : void> */ private ObjectSet $recipeRegisteredCallbacks; diff --git a/src/crafting/FurnaceRecipeManager.php b/src/crafting/FurnaceRecipeManager.php index 1f16f47070..1660d0c42b 100644 --- a/src/crafting/FurnaceRecipeManager.php +++ b/src/crafting/FurnaceRecipeManager.php @@ -28,7 +28,7 @@ use pocketmine\utils\ObjectSet; final class FurnaceRecipeManager{ /** @var FurnaceRecipe[] */ - protected $furnaceRecipes = []; + protected array $furnaceRecipes = []; /** @phpstan-var ObjectSet<\Closure(FurnaceRecipe) : void> */ private ObjectSet $recipeRegisteredCallbacks; diff --git a/src/entity/Attribute.php b/src/entity/Attribute.php index 3f9bc7faf0..3072fc7619 100644 --- a/src/entity/Attribute.php +++ b/src/entity/Attribute.php @@ -48,32 +48,19 @@ class Attribute{ public const ZOMBIE_SPAWN_REINFORCEMENTS = self::MC_PREFIX . "zombie.spawn_reinforcements"; public const LAVA_MOVEMENT = self::MC_PREFIX . "lava_movement"; - /** @var string */ - protected $id; - /** @var float */ - protected $minValue; - /** @var float */ - protected $maxValue; - /** @var float */ - protected $defaultValue; - /** @var float */ - protected $currentValue; - /** @var bool */ - protected $shouldSend; + protected float $currentValue; + protected bool $desynchronized = true; - /** @var bool */ - protected $desynchronized = true; - - public function __construct(string $id, float $minValue, float $maxValue, float $defaultValue, bool $shouldSend = true){ + public function __construct( + protected string $id, + protected float $minValue, + protected float $maxValue, + protected float $defaultValue, + protected bool $shouldSend = true + ){ if($minValue > $maxValue || $defaultValue > $maxValue || $defaultValue < $minValue){ throw new \InvalidArgumentException("Invalid ranges: min value: $minValue, max value: $maxValue, $defaultValue: $defaultValue"); } - $this->id = $id; - $this->minValue = $minValue; - $this->maxValue = $maxValue; - $this->defaultValue = $defaultValue; - $this->shouldSend = $shouldSend; - $this->currentValue = $this->defaultValue; } diff --git a/src/entity/object/PaintingMotive.php b/src/entity/object/PaintingMotive.php index a2c6f221af..dd61cf3c67 100644 --- a/src/entity/object/PaintingMotive.php +++ b/src/entity/object/PaintingMotive.php @@ -27,7 +27,7 @@ class PaintingMotive{ private static bool $initialized = false; /** @var PaintingMotive[] */ - protected static $motives = []; + protected static array $motives = []; public static function init() : void{ foreach([ diff --git a/src/event/Event.php b/src/event/Event.php index 17f0417c5d..f77b54ced4 100644 --- a/src/event/Event.php +++ b/src/event/Event.php @@ -33,8 +33,7 @@ abstract class Event{ private static int $eventCallDepth = 1; - /** @var string|null */ - protected $eventName = null; + protected ?string $eventName = null; final public function getEventName() : string{ return $this->eventName ?? get_class($this); diff --git a/src/event/block/BlockBreakEvent.php b/src/event/block/BlockBreakEvent.php index e11a71ebc9..369dca2054 100644 --- a/src/event/block/BlockBreakEvent.php +++ b/src/event/block/BlockBreakEvent.php @@ -35,30 +35,22 @@ use pocketmine\player\Player; class BlockBreakEvent extends BlockEvent implements Cancellable{ use CancellableTrait; - /** @var Player */ - protected $player; - - /** @var Item */ - protected $item; - - /** @var bool */ - protected $instaBreak = false; /** @var Item[] */ - protected $blockDrops = []; - /** @var int */ - protected $xpDrops; + protected array $blockDrops = []; /** * @param Item[] $drops */ - public function __construct(Player $player, Block $block, Item $item, bool $instaBreak = false, array $drops = [], int $xpDrops = 0){ + public function __construct( + protected Player $player, + Block $block, + protected Item $item, + protected bool $instaBreak = false, + array $drops = [], + protected int $xpDrops = 0 + ){ parent::__construct($block); - $this->item = $item; - $this->player = $player; - - $this->instaBreak = $instaBreak; $this->setDrops($drops); - $this->xpDrops = $xpDrops; } /** diff --git a/src/event/block/BlockEvent.php b/src/event/block/BlockEvent.php index d506529ba7..16e5a81e9c 100644 --- a/src/event/block/BlockEvent.php +++ b/src/event/block/BlockEvent.php @@ -30,12 +30,9 @@ use pocketmine\block\Block; use pocketmine\event\Event; abstract class BlockEvent extends Event{ - /** @var Block */ - protected $block; - - public function __construct(Block $block){ - $this->block = $block; - } + public function __construct( + protected Block $block + ){} public function getBlock() : Block{ return $this->block; diff --git a/src/event/block/BlockPlaceEvent.php b/src/event/block/BlockPlaceEvent.php index 955b901346..f5e9c218d9 100644 --- a/src/event/block/BlockPlaceEvent.php +++ b/src/event/block/BlockPlaceEvent.php @@ -35,23 +35,14 @@ use pocketmine\player\Player; class BlockPlaceEvent extends BlockEvent implements Cancellable{ use CancellableTrait; - /** @var Player */ - protected $player; - - /** @var Item */ - protected $item; - - /** @var Block */ - protected $blockReplace; - /** @var Block */ - protected $blockAgainst; - - public function __construct(Player $player, Block $blockPlace, Block $blockReplace, Block $blockAgainst, Item $item){ + public function __construct( + protected Player $player, + Block $blockPlace, + protected Block $blockReplace, + protected Block $blockAgainst, + protected Item $item + ){ parent::__construct($blockPlace); - $this->blockReplace = $blockReplace; - $this->blockAgainst = $blockAgainst; - $this->item = $item; - $this->player = $player; } /** diff --git a/src/event/entity/EntityCombustByBlockEvent.php b/src/event/entity/EntityCombustByBlockEvent.php index 9b1d56f5a6..84fc963a7d 100644 --- a/src/event/entity/EntityCombustByBlockEvent.php +++ b/src/event/entity/EntityCombustByBlockEvent.php @@ -27,8 +27,7 @@ use pocketmine\block\Block; use pocketmine\entity\Entity; class EntityCombustByBlockEvent extends EntityCombustEvent{ - /** @var Block */ - protected $combuster; + protected Block $combuster; public function __construct(Block $combuster, Entity $combustee, int $duration){ parent::__construct($combustee, $duration); diff --git a/src/event/entity/EntityCombustByEntityEvent.php b/src/event/entity/EntityCombustByEntityEvent.php index 435ab670a9..5abb723a20 100644 --- a/src/event/entity/EntityCombustByEntityEvent.php +++ b/src/event/entity/EntityCombustByEntityEvent.php @@ -26,8 +26,7 @@ namespace pocketmine\event\entity; use pocketmine\entity\Entity; class EntityCombustByEntityEvent extends EntityCombustEvent{ - /** @var Entity */ - protected $combuster; + protected Entity $combuster; public function __construct(Entity $combuster, Entity $combustee, int $duration){ parent::__construct($combustee, $duration); diff --git a/src/event/entity/EntityCombustEvent.php b/src/event/entity/EntityCombustEvent.php index 442c25f9b9..a38d82b182 100644 --- a/src/event/entity/EntityCombustEvent.php +++ b/src/event/entity/EntityCombustEvent.php @@ -33,8 +33,7 @@ use pocketmine\event\CancellableTrait; class EntityCombustEvent extends EntityEvent implements Cancellable{ use CancellableTrait; - /** @var int */ - protected $duration; + protected int $duration; public function __construct(Entity $combustee, int $duration){ $this->entity = $combustee; diff --git a/src/event/entity/EntityEvent.php b/src/event/entity/EntityEvent.php index 0a13ff0ebe..ecb234e32d 100644 --- a/src/event/entity/EntityEvent.php +++ b/src/event/entity/EntityEvent.php @@ -33,11 +33,8 @@ use pocketmine\event\Event; * @phpstan-template TEntity of Entity */ abstract class EntityEvent extends Event{ - /** - * @var Entity - * @phpstan-var TEntity - */ - protected $entity; + /** @phpstan-var TEntity */ + protected Entity $entity; /** * @return Entity diff --git a/src/event/entity/EntityExplodeEvent.php b/src/event/entity/EntityExplodeEvent.php index fa69d2fbff..333f320f4c 100644 --- a/src/event/entity/EntityExplodeEvent.php +++ b/src/event/entity/EntityExplodeEvent.php @@ -41,27 +41,20 @@ use pocketmine\world\Position; class EntityExplodeEvent extends EntityEvent implements Cancellable{ use CancellableTrait; - /** @var Position */ - protected $position; - - /** @var Block[] */ - protected $blocks; - - /** @var float */ - protected $yield; - /** * @param Block[] $blocks * @param float $yield 0-100 */ - public function __construct(Entity $entity, Position $position, array $blocks, float $yield){ + public function __construct( + Entity $entity, + protected Position $position, + protected array $blocks, + protected float $yield + ){ $this->entity = $entity; - $this->position = $position; - $this->blocks = $blocks; if($yield < 0.0 || $yield > 100.0){ throw new \InvalidArgumentException("Yield must be in range 0.0 - 100.0"); } - $this->yield = $yield; } public function getPosition() : Position{ diff --git a/src/event/entity/ExplosionPrimeEvent.php b/src/event/entity/ExplosionPrimeEvent.php index 50146a6dd9..dbbc29c6f4 100644 --- a/src/event/entity/ExplosionPrimeEvent.php +++ b/src/event/entity/ExplosionPrimeEvent.php @@ -38,16 +38,16 @@ use pocketmine\event\CancellableTrait; class ExplosionPrimeEvent extends EntityEvent implements Cancellable{ use CancellableTrait; - /** @var float */ - protected $force; private bool $blockBreaking = true; - public function __construct(Entity $entity, float $force){ + public function __construct( + Entity $entity, + protected float $force + ){ if($force <= 0){ throw new \InvalidArgumentException("Explosion radius must be positive"); } $this->entity = $entity; - $this->force = $force; } public function getForce() : float{ diff --git a/src/event/inventory/InventoryEvent.php b/src/event/inventory/InventoryEvent.php index ac19d37055..966f058003 100644 --- a/src/event/inventory/InventoryEvent.php +++ b/src/event/inventory/InventoryEvent.php @@ -31,12 +31,9 @@ use pocketmine\inventory\Inventory; use pocketmine\player\Player; abstract class InventoryEvent extends Event{ - /** @var Inventory */ - protected $inventory; - - public function __construct(Inventory $inventory){ - $this->inventory = $inventory; - } + public function __construct( + protected Inventory $inventory + ){} public function getInventory() : Inventory{ return $this->inventory; diff --git a/src/event/player/PlayerChatEvent.php b/src/event/player/PlayerChatEvent.php index 138410357e..dc8259dff7 100644 --- a/src/event/player/PlayerChatEvent.php +++ b/src/event/player/PlayerChatEvent.php @@ -35,25 +35,16 @@ use pocketmine\utils\Utils; class PlayerChatEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var string */ - protected $message; - - /** @var string */ - protected $format; - - /** @var CommandSender[] */ - protected $recipients = []; - /** * @param CommandSender[] $recipients */ - public function __construct(Player $player, string $message, array $recipients, string $format = "chat.type.text"){ + public function __construct( + Player $player, + protected string $message, + protected array $recipients, + protected string $format = "chat.type.text" + ){ $this->player = $player; - $this->message = $message; - - $this->format = $format; - - $this->recipients = $recipients; } public function getMessage() : string{ diff --git a/src/event/player/PlayerCommandPreprocessEvent.php b/src/event/player/PlayerCommandPreprocessEvent.php index afa45ddd05..4dcdb1e34b 100644 --- a/src/event/player/PlayerCommandPreprocessEvent.php +++ b/src/event/player/PlayerCommandPreprocessEvent.php @@ -41,12 +41,11 @@ use pocketmine\player\Player; class PlayerCommandPreprocessEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var string */ - protected $message; - - public function __construct(Player $player, string $message){ + public function __construct( + Player $player, + protected string $message + ){ $this->player = $player; - $this->message = $message; } public function getMessage() : string{ diff --git a/src/event/player/PlayerDataSaveEvent.php b/src/event/player/PlayerDataSaveEvent.php index a848f52562..5e840d334a 100644 --- a/src/event/player/PlayerDataSaveEvent.php +++ b/src/event/player/PlayerDataSaveEvent.php @@ -35,19 +35,11 @@ use pocketmine\player\Player; class PlayerDataSaveEvent extends Event implements Cancellable{ use CancellableTrait; - /** @var CompoundTag */ - protected $data; - /** @var string */ - protected $playerName; - public function __construct( - CompoundTag $nbt, - string $playerName, + protected CompoundTag $data, + protected string $playerName, private ?Player $player - ){ - $this->data = $nbt; - $this->playerName = $playerName; - } + ){} /** * Returns the data to be written to disk as a CompoundTag diff --git a/src/event/player/PlayerDeathEvent.php b/src/event/player/PlayerDeathEvent.php index 3c8e7ec59b..01358dd876 100644 --- a/src/event/player/PlayerDeathEvent.php +++ b/src/event/player/PlayerDeathEvent.php @@ -35,8 +35,7 @@ use pocketmine\lang\Translatable; use pocketmine\player\Player; class PlayerDeathEvent extends EntityDeathEvent{ - /** @var Player */ - protected $player; + protected Player $player; private Translatable|string $deathMessage; private bool $keepInventory = false; diff --git a/src/event/player/PlayerEvent.php b/src/event/player/PlayerEvent.php index 8be23d3509..2206363b0b 100644 --- a/src/event/player/PlayerEvent.php +++ b/src/event/player/PlayerEvent.php @@ -30,8 +30,7 @@ use pocketmine\event\Event; use pocketmine\player\Player; abstract class PlayerEvent extends Event{ - /** @var Player */ - protected $player; + protected Player $player; public function getPlayer() : Player{ return $this->player; diff --git a/src/event/player/PlayerExhaustEvent.php b/src/event/player/PlayerExhaustEvent.php index 95e3312329..ec5b1d2e9b 100644 --- a/src/event/player/PlayerExhaustEvent.php +++ b/src/event/player/PlayerExhaustEvent.php @@ -46,23 +46,19 @@ class PlayerExhaustEvent extends EntityEvent implements Cancellable{ public const CAUSE_SPRINT_JUMPING = 10; public const CAUSE_CUSTOM = 11; - /** @var Human */ - protected $player; - public function __construct( - Human $human, + protected Human $human, private float $amount, private int $cause ){ $this->entity = $human; - $this->player = $human; } /** * @return Human */ public function getPlayer(){ - return $this->player; + return $this->human; } public function getAmount() : float{ diff --git a/src/event/player/PlayerExperienceChangeEvent.php b/src/event/player/PlayerExperienceChangeEvent.php index b62f828995..908686c7f1 100644 --- a/src/event/player/PlayerExperienceChangeEvent.php +++ b/src/event/player/PlayerExperienceChangeEvent.php @@ -35,9 +35,6 @@ use pocketmine\event\entity\EntityEvent; class PlayerExperienceChangeEvent extends EntityEvent implements Cancellable{ use CancellableTrait; - /** @var Human */ - protected $entity; - public function __construct( Human $player, private int $oldLevel, diff --git a/src/event/player/PlayerGameModeChangeEvent.php b/src/event/player/PlayerGameModeChangeEvent.php index 926d17d2bc..f1c7f7e3f8 100644 --- a/src/event/player/PlayerGameModeChangeEvent.php +++ b/src/event/player/PlayerGameModeChangeEvent.php @@ -34,15 +34,14 @@ use pocketmine\player\Player; class PlayerGameModeChangeEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var GameMode */ - protected $gamemode; - - public function __construct(Player $player, GameMode $newGamemode){ + public function __construct( + Player $player, + protected GameMode $newGamemode + ){ $this->player = $player; - $this->gamemode = $newGamemode; } public function getNewGamemode() : GameMode{ - return $this->gamemode; + return $this->newGamemode; } } diff --git a/src/event/player/PlayerInteractEvent.php b/src/event/player/PlayerInteractEvent.php index b76a8226cc..a466949726 100644 --- a/src/event/player/PlayerInteractEvent.php +++ b/src/event/player/PlayerInteractEvent.php @@ -40,28 +40,18 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{ public const LEFT_CLICK_BLOCK = 0; public const RIGHT_CLICK_BLOCK = 1; - /** @var Block */ - protected $blockTouched; + protected Vector3 $touchVector; - /** @var Vector3 */ - protected $touchVector; - - /** @var int */ - protected $blockFace; - - /** @var Item */ - protected $item; - - /** @var int */ - protected $action; - - public function __construct(Player $player, Item $item, Block $block, ?Vector3 $touchVector, int $face, int $action = PlayerInteractEvent::RIGHT_CLICK_BLOCK){ + public function __construct( + Player $player, + protected Item $item, + protected Block $blockTouched, + ?Vector3 $touchVector, + protected int $blockFace, + protected int $action = PlayerInteractEvent::RIGHT_CLICK_BLOCK + ){ $this->player = $player; - $this->item = $item; - $this->blockTouched = $block; $this->touchVector = $touchVector ?? new Vector3(0, 0, 0); - $this->blockFace = $face; - $this->action = $action; } public function getAction() : int{ diff --git a/src/event/player/PlayerJoinEvent.php b/src/event/player/PlayerJoinEvent.php index e46e3fd7d5..1e5e06e768 100644 --- a/src/event/player/PlayerJoinEvent.php +++ b/src/event/player/PlayerJoinEvent.php @@ -34,12 +34,11 @@ use pocketmine\player\Player; * @see PlayerLoginEvent */ class PlayerJoinEvent extends PlayerEvent{ - /** @var string|Translatable */ - protected $joinMessage; - - public function __construct(Player $player, Translatable|string $joinMessage){ + public function __construct( + Player $player, + protected Translatable|string $joinMessage + ){ $this->player = $player; - $this->joinMessage = $joinMessage; } public function setJoinMessage(Translatable|string $joinMessage) : void{ diff --git a/src/event/player/PlayerKickEvent.php b/src/event/player/PlayerKickEvent.php index 92f7c071b3..e8a11acd2c 100644 --- a/src/event/player/PlayerKickEvent.php +++ b/src/event/player/PlayerKickEvent.php @@ -34,16 +34,12 @@ use pocketmine\player\Player; class PlayerKickEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var Translatable|string */ - protected $quitMessage; - - /** @var string */ - protected $reason; - - public function __construct(Player $player, string $reason, Translatable|string $quitMessage){ + public function __construct( + Player $player, + protected string $reason, + protected Translatable|string $quitMessage + ){ $this->player = $player; - $this->quitMessage = $quitMessage; - $this->reason = $reason; } /** diff --git a/src/event/player/PlayerLoginEvent.php b/src/event/player/PlayerLoginEvent.php index 8c418f7037..4603902c42 100644 --- a/src/event/player/PlayerLoginEvent.php +++ b/src/event/player/PlayerLoginEvent.php @@ -35,12 +35,11 @@ use pocketmine\player\Player; class PlayerLoginEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var string */ - protected $kickMessage; - - public function __construct(Player $player, string $kickMessage){ + public function __construct( + Player $player, + protected string $kickMessage + ){ $this->player = $player; - $this->kickMessage = $kickMessage; } public function setKickMessage(string $kickMessage) : void{ diff --git a/src/event/player/PlayerPreLoginEvent.php b/src/event/player/PlayerPreLoginEvent.php index b4a2867796..1f13ec372b 100644 --- a/src/event/player/PlayerPreLoginEvent.php +++ b/src/event/player/PlayerPreLoginEvent.php @@ -52,20 +52,15 @@ class PlayerPreLoginEvent extends Event implements Cancellable{ self::KICK_REASON_BANNED ]; - /** @var bool */ - protected $authRequired; - /** @var string[] reason const => associated message */ - protected $kickReasons = []; + protected array $kickReasons = []; public function __construct( private PlayerInfo $playerInfo, private string $ip, private int $port, - bool $authRequired - ){ - $this->authRequired = $authRequired; - } + protected bool $authRequired + ){} /** * Returns an object containing self-proclaimed information about the connecting player. diff --git a/src/event/player/PlayerQuitEvent.php b/src/event/player/PlayerQuitEvent.php index 3e08cb315e..f05434c24d 100644 --- a/src/event/player/PlayerQuitEvent.php +++ b/src/event/player/PlayerQuitEvent.php @@ -37,16 +37,12 @@ use pocketmine\player\Player; * @see PlayerKickEvent */ class PlayerQuitEvent extends PlayerEvent{ - - /** @var Translatable|string */ - protected $quitMessage; - /** @var string */ - protected $quitReason; - - public function __construct(Player $player, Translatable|string $quitMessage, string $quitReason){ + public function __construct( + Player $player, + protected Translatable|string $quitMessage, + protected string $quitReason + ){ $this->player = $player; - $this->quitMessage = $quitMessage; - $this->quitReason = $quitReason; } /** diff --git a/src/event/player/PlayerRespawnEvent.php b/src/event/player/PlayerRespawnEvent.php index 1bdc2446cf..4aa12e129a 100644 --- a/src/event/player/PlayerRespawnEvent.php +++ b/src/event/player/PlayerRespawnEvent.php @@ -31,12 +31,11 @@ use pocketmine\world\Position; * Called when a player is respawned */ class PlayerRespawnEvent extends PlayerEvent{ - /** @var Position */ - protected $position; - - public function __construct(Player $player, Position $position){ + public function __construct( + Player $player, + protected Position $position + ){ $this->player = $player; - $this->position = $position; } public function getRespawnPosition() : Position{ diff --git a/src/event/player/PlayerToggleFlightEvent.php b/src/event/player/PlayerToggleFlightEvent.php index b8c0f93d9e..fc94f101d8 100644 --- a/src/event/player/PlayerToggleFlightEvent.php +++ b/src/event/player/PlayerToggleFlightEvent.php @@ -30,12 +30,11 @@ use pocketmine\player\Player; class PlayerToggleFlightEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var bool */ - protected $isFlying; - - public function __construct(Player $player, bool $isFlying){ + public function __construct( + Player $player, + protected bool $isFlying + ){ $this->player = $player; - $this->isFlying = $isFlying; } public function isFlying() : bool{ diff --git a/src/event/player/PlayerToggleSneakEvent.php b/src/event/player/PlayerToggleSneakEvent.php index 0b7538975a..a8fb576efa 100644 --- a/src/event/player/PlayerToggleSneakEvent.php +++ b/src/event/player/PlayerToggleSneakEvent.php @@ -30,12 +30,11 @@ use pocketmine\player\Player; class PlayerToggleSneakEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var bool */ - protected $isSneaking; - - public function __construct(Player $player, bool $isSneaking){ + public function __construct( + Player $player, + protected bool $isSneaking + ){ $this->player = $player; - $this->isSneaking = $isSneaking; } public function isSneaking() : bool{ diff --git a/src/event/player/PlayerToggleSprintEvent.php b/src/event/player/PlayerToggleSprintEvent.php index 2da14d7b7a..ae66c94bc8 100644 --- a/src/event/player/PlayerToggleSprintEvent.php +++ b/src/event/player/PlayerToggleSprintEvent.php @@ -30,12 +30,11 @@ use pocketmine\player\Player; class PlayerToggleSprintEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var bool */ - protected $isSprinting; - - public function __construct(Player $player, bool $isSprinting){ + public function __construct( + Player $player, + protected bool $isSprinting + ){ $this->player = $player; - $this->isSprinting = $isSprinting; } public function isSprinting() : bool{ diff --git a/src/event/player/PlayerTransferEvent.php b/src/event/player/PlayerTransferEvent.php index adaa0ca5d6..3b9f88f3f5 100644 --- a/src/event/player/PlayerTransferEvent.php +++ b/src/event/player/PlayerTransferEvent.php @@ -33,18 +33,13 @@ use pocketmine\player\Player; class PlayerTransferEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var string */ - protected $address; - /** @var int */ - protected $port = 19132; - /** @var string */ - protected $message; - - public function __construct(Player $player, string $address, int $port, string $message){ + public function __construct( + Player $player, + protected string $address, + protected int $port, + protected string $message + ){ $this->player = $player; - $this->address = $address; - $this->port = $port; - $this->message = $message; } /** diff --git a/src/event/server/CommandEvent.php b/src/event/server/CommandEvent.php index 9a982d230c..9b7bce53d7 100644 --- a/src/event/server/CommandEvent.php +++ b/src/event/server/CommandEvent.php @@ -44,16 +44,10 @@ use pocketmine\event\CancellableTrait; class CommandEvent extends ServerEvent implements Cancellable{ use CancellableTrait; - /** @var string */ - protected $command; - - /** @var CommandSender */ - protected $sender; - - public function __construct(CommandSender $sender, string $command){ - $this->sender = $sender; - $this->command = $command; - } + public function __construct( + protected CommandSender $sender, + protected string $command + ){} public function getSender() : CommandSender{ return $this->sender; diff --git a/src/event/server/NetworkInterfaceEvent.php b/src/event/server/NetworkInterfaceEvent.php index 98f48f07db..5c44c909e8 100644 --- a/src/event/server/NetworkInterfaceEvent.php +++ b/src/event/server/NetworkInterfaceEvent.php @@ -26,12 +26,9 @@ namespace pocketmine\event\server; use pocketmine\network\NetworkInterface; class NetworkInterfaceEvent extends ServerEvent{ - /** @var NetworkInterface */ - protected $interface; - - public function __construct(NetworkInterface $interface){ - $this->interface = $interface; - } + public function __construct( + protected NetworkInterface $interface + ){} public function getInterface() : NetworkInterface{ return $this->interface; diff --git a/src/inventory/ArmorInventory.php b/src/inventory/ArmorInventory.php index 4754e3aff0..cbc741b535 100644 --- a/src/inventory/ArmorInventory.php +++ b/src/inventory/ArmorInventory.php @@ -32,11 +32,9 @@ class ArmorInventory extends SimpleInventory{ public const SLOT_LEGS = 2; public const SLOT_FEET = 3; - /** @var Living */ - protected $holder; - - public function __construct(Living $holder){ - $this->holder = $holder; + public function __construct( + protected Living $holder + ){ parent::__construct(4); } diff --git a/src/inventory/BaseInventory.php b/src/inventory/BaseInventory.php index e593893cea..8343b7bbf0 100644 --- a/src/inventory/BaseInventory.php +++ b/src/inventory/BaseInventory.php @@ -37,15 +37,14 @@ use function spl_object_id; * This class provides everything needed to implement an inventory, minus the underlying storage system. */ abstract class BaseInventory implements Inventory{ - /** @var int */ - protected $maxStackSize = Inventory::MAX_STACK; + protected int $maxStackSize = Inventory::MAX_STACK; /** @var Player[] */ - protected $viewers = []; + protected array $viewers = []; /** * @var InventoryListener[]|ObjectSet * @phpstan-var ObjectSet */ - protected $listeners; + protected ObjectSet $listeners; public function __construct(){ $this->listeners = new ObjectSet(); diff --git a/src/inventory/PlayerCursorInventory.php b/src/inventory/PlayerCursorInventory.php index 7c219fd007..9c83f1e8e0 100644 --- a/src/inventory/PlayerCursorInventory.php +++ b/src/inventory/PlayerCursorInventory.php @@ -26,18 +26,13 @@ namespace pocketmine\inventory; use pocketmine\player\Player; class PlayerCursorInventory extends SimpleInventory implements TemporaryInventory{ - /** @var Player */ - protected $holder; - - public function __construct(Player $holder){ - $this->holder = $holder; + public function __construct( + protected Player $holder + ){ parent::__construct(1); } - /** - * @return Player - */ - public function getHolder(){ + public function getHolder() : Player{ return $this->holder; } } diff --git a/src/inventory/PlayerInventory.php b/src/inventory/PlayerInventory.php index baeecb5af5..9272db8324 100644 --- a/src/inventory/PlayerInventory.php +++ b/src/inventory/PlayerInventory.php @@ -30,17 +30,14 @@ use pocketmine\utils\ObjectSet; class PlayerInventory extends SimpleInventory{ - /** @var Human */ - protected $holder; - - /** @var int */ - protected $itemInHandIndex = 0; + protected Human $holder; + protected int $itemInHandIndex = 0; /** * @var \Closure[]|ObjectSet * @phpstan-var ObjectSet<\Closure(int $oldIndex) : void> */ - protected $heldItemIndexChangeListeners; + protected ObjectSet $heldItemIndexChangeListeners; public function __construct(Human $player){ $this->holder = $player; @@ -123,10 +120,7 @@ class PlayerInventory extends SimpleInventory{ return 9; } - /** - * @return Human|Player - */ - public function getHolder(){ + public function getHolder() : Human{ return $this->holder; } } diff --git a/src/inventory/transaction/CraftingTransaction.php b/src/inventory/transaction/CraftingTransaction.php index 90ee1b05d0..c7f71723f2 100644 --- a/src/inventory/transaction/CraftingTransaction.php +++ b/src/inventory/transaction/CraftingTransaction.php @@ -48,15 +48,13 @@ use function intdiv; * results, with no remainder. Any leftovers are expected to be emitted back to the crafting grid. */ class CraftingTransaction extends InventoryTransaction{ - /** @var CraftingRecipe|null */ - protected $recipe; - /** @var int|null */ - protected $repetitions; + protected ?CraftingRecipe $recipe; + protected ?int $repetitions; /** @var Item[] */ - protected $inputs = []; + protected array $inputs = []; /** @var Item[] */ - protected $outputs = []; + protected array $outputs = []; private CraftingManager $craftingManager; diff --git a/src/inventory/transaction/InventoryTransaction.php b/src/inventory/transaction/InventoryTransaction.php index 82e2065501..c264425185 100644 --- a/src/inventory/transaction/InventoryTransaction.php +++ b/src/inventory/transaction/InventoryTransaction.php @@ -55,22 +55,21 @@ use function spl_object_id; * @see InventoryAction */ class InventoryTransaction{ - /** @var bool */ - protected $hasExecuted = false; - /** @var Player */ - protected $source; + protected bool $hasExecuted = false; /** @var Inventory[] */ - protected $inventories = []; + protected array $inventories = []; /** @var InventoryAction[] */ - protected $actions = []; + protected array $actions = []; /** * @param InventoryAction[] $actions */ - public function __construct(Player $source, array $actions = []){ - $this->source = $source; + public function __construct( + protected Player $source, + array $actions = [] + ){ foreach($actions as $action){ $this->addAction($action); } diff --git a/src/inventory/transaction/action/InventoryAction.php b/src/inventory/transaction/action/InventoryAction.php index 4fa3ac15e5..b0741920b5 100644 --- a/src/inventory/transaction/action/InventoryAction.php +++ b/src/inventory/transaction/action/InventoryAction.php @@ -32,15 +32,10 @@ use pocketmine\player\Player; * Represents an action involving a change that applies in some way to an inventory or other item-source. */ abstract class InventoryAction{ - /** @var Item */ - protected $sourceItem; - /** @var Item */ - protected $targetItem; - - public function __construct(Item $sourceItem, Item $targetItem){ - $this->sourceItem = $sourceItem; - $this->targetItem = $targetItem; - } + public function __construct( + protected Item $sourceItem, + protected Item $targetItem + ){} /** * Returns the item that was present before the action took place. diff --git a/src/inventory/transaction/action/SlotChangeAction.php b/src/inventory/transaction/action/SlotChangeAction.php index dd91adfb7f..18eb7acbda 100644 --- a/src/inventory/transaction/action/SlotChangeAction.php +++ b/src/inventory/transaction/action/SlotChangeAction.php @@ -33,15 +33,13 @@ use pocketmine\player\Player; * Represents an action causing a change in an inventory slot. */ class SlotChangeAction extends InventoryAction{ - - /** @var Inventory */ - protected $inventory; - private int $inventorySlot; - - public function __construct(Inventory $inventory, int $inventorySlot, Item $sourceItem, Item $targetItem){ + public function __construct( + protected Inventory $inventory, + private int $inventorySlot, + Item $sourceItem, + Item $targetItem + ){ parent::__construct($sourceItem, $targetItem); - $this->inventory = $inventory; - $this->inventorySlot = $inventorySlot; } /** diff --git a/src/item/Armor.php b/src/item/Armor.php index 7cf8e646db..9c6c8cbe0e 100644 --- a/src/item/Armor.php +++ b/src/item/Armor.php @@ -42,8 +42,7 @@ class Armor extends Durable{ private ArmorTypeInfo $armorInfo; - /** @var Color|null */ - protected $customColor = null; + protected ?Color $customColor = null; public function __construct(ItemIdentifier $identifier, string $name, ArmorTypeInfo $info){ parent::__construct($identifier, $name); diff --git a/src/item/Durable.php b/src/item/Durable.php index 33678be8c1..f867324b29 100644 --- a/src/item/Durable.php +++ b/src/item/Durable.php @@ -29,9 +29,7 @@ use function lcg_value; use function min; abstract class Durable extends Item{ - - /** @var int */ - protected $damage = 0; + protected int $damage = 0; private bool $unbreakable = false; public function getMeta() : int{ diff --git a/src/item/Item.php b/src/item/Item.php index e4b56c8959..d14e274ae8 100644 --- a/src/item/Item.php +++ b/src/item/Item.php @@ -65,36 +65,28 @@ class Item implements \JsonSerializable{ public const TAG_DISPLAY_NAME = "Name"; public const TAG_DISPLAY_LORE = "Lore"; - private ItemIdentifier $identifier; private CompoundTag $nbt; - /** @var int */ - protected $count = 1; - /** @var string */ - protected $name; + protected int $count = 1; //TODO: this stuff should be moved to itemstack properties, not mushed in with type properties - /** @var string */ - protected $customName = ""; + protected string $customName = ""; /** @var string[] */ - protected $lore = []; - /** - * TODO: this needs to die in a fire - * @var CompoundTag|null - */ - protected $blockEntityTag = null; + protected array $lore = []; + /** TODO: this needs to die in a fire */ + protected ?CompoundTag $blockEntityTag = null; /** * @var string[] * @phpstan-var array */ - protected $canPlaceOn = []; + protected array $canPlaceOn = []; /** * @var string[] * @phpstan-var array */ - protected $canDestroy; + protected array $canDestroy = []; /** * Constructs a new Item type. This constructor should ONLY be used when constructing a new item TYPE to register @@ -103,12 +95,10 @@ class Item implements \JsonSerializable{ * NOTE: This should NOT BE USED for creating items to set into an inventory. Use {@link ItemFactory#get} for that * purpose. */ - public function __construct(ItemIdentifier $identifier, string $name = "Unknown"){ - $this->identifier = $identifier; - $this->name = $name; - - $this->canPlaceOn = []; - $this->canDestroy = []; + public function __construct( + private ItemIdentifier $identifier, + protected string $name = "Unknown" + ){ $this->nbt = new CompoundTag(); } diff --git a/src/item/ItemEnchantmentHandlingTrait.php b/src/item/ItemEnchantmentHandlingTrait.php index 9ba344139b..67156ed70f 100644 --- a/src/item/ItemEnchantmentHandlingTrait.php +++ b/src/item/ItemEnchantmentHandlingTrait.php @@ -34,7 +34,7 @@ use function spl_object_id; */ trait ItemEnchantmentHandlingTrait{ /** @var EnchantmentInstance[] */ - protected $enchantments = []; + protected array $enchantments = []; public function hasEnchantments() : bool{ return count($this->enchantments) > 0; diff --git a/src/item/TieredTool.php b/src/item/TieredTool.php index cf4647481f..98af920ad3 100644 --- a/src/item/TieredTool.php +++ b/src/item/TieredTool.php @@ -24,9 +24,7 @@ declare(strict_types=1); namespace pocketmine\item; abstract class TieredTool extends Tool{ - - /** @var ToolTier */ - protected $tier; + protected ToolTier $tier; public function __construct(ItemIdentifier $identifier, string $name, ToolTier $tier){ parent::__construct($identifier, $name); diff --git a/src/item/enchantment/ProtectionEnchantment.php b/src/item/enchantment/ProtectionEnchantment.php index b6f6a91be0..84659d22f6 100644 --- a/src/item/enchantment/ProtectionEnchantment.php +++ b/src/item/enchantment/ProtectionEnchantment.php @@ -29,10 +29,9 @@ use function array_flip; use function floor; class ProtectionEnchantment extends Enchantment{ - /** @var float */ - protected $typeModifier; + protected float $typeModifier; /** @var int[]|null */ - protected $applicableDamageTypes = null; + protected ?array $applicableDamageTypes = null; /** * ProtectionEnchantment constructor. diff --git a/src/lang/Language.php b/src/lang/Language.php index bce7c5c695..adbb41eb9f 100644 --- a/src/lang/Language.php +++ b/src/lang/Language.php @@ -81,19 +81,17 @@ class Language{ throw new LanguageNotFoundException("Language directory $path does not exist or is not a directory"); } - /** @var string */ - protected $langName; - + protected string $langName; /** * @var string[] * @phpstan-var array */ - protected $lang = []; + protected array $lang = []; /** * @var string[] * @phpstan-var array */ - protected $fallbackLang = []; + protected array $fallbackLang = []; /** * @throws LanguageNotFoundException diff --git a/src/lang/Translatable.php b/src/lang/Translatable.php index 43905a1b1c..5cccd9bff8 100644 --- a/src/lang/Translatable.php +++ b/src/lang/Translatable.php @@ -24,18 +24,16 @@ declare(strict_types=1); namespace pocketmine\lang; final class Translatable{ - - /** @var string $text */ - protected $text; /** @var string[]|Translatable[] $params */ - protected $params = []; + protected array $params = []; /** * @param (float|int|string|Translatable)[] $params */ - public function __construct(string $text, array $params = []){ - $this->text = $text; - + public function __construct( + protected string $text, + array $params = [] + ){ foreach($params as $k => $param){ if(!($param instanceof Translatable)){ $this->params[$k] = (string) $param; diff --git a/src/network/mcpe/ChunkRequestTask.php b/src/network/mcpe/ChunkRequestTask.php index 712283c3f1..c16d916e0d 100644 --- a/src/network/mcpe/ChunkRequestTask.php +++ b/src/network/mcpe/ChunkRequestTask.php @@ -39,16 +39,10 @@ class ChunkRequestTask extends AsyncTask{ private const TLS_KEY_PROMISE = "promise"; private const TLS_KEY_ERROR_HOOK = "errorHook"; - /** @var string */ - protected $chunk; - /** @var int */ - protected $chunkX; - /** @var int */ - protected $chunkZ; - - /** @var Compressor */ - protected $compressor; - + protected string $chunk; + protected int $chunkX; + protected int $chunkZ; + protected Compressor $compressor; private string $tiles; /** diff --git a/src/network/mcpe/encryption/EncryptionContext.php b/src/network/mcpe/encryption/EncryptionContext.php index ff11b976da..82f780a92b 100644 --- a/src/network/mcpe/encryption/EncryptionContext.php +++ b/src/network/mcpe/encryption/EncryptionContext.php @@ -34,8 +34,7 @@ use function substr; class EncryptionContext{ private const CHECKSUM_ALGO = "sha256"; - /** @var bool */ - public static $ENABLED = true; + public static bool $ENABLED = true; private string $key; diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index ba81634518..446f5e2f06 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -135,16 +135,12 @@ use const JSON_THROW_ON_ERROR; class InGamePacketHandler extends PacketHandler{ private const MAX_FORM_RESPONSE_DEPTH = 2; //modal/simple will be 1, custom forms 2 - they will never contain anything other than string|int|float|bool|null - /** @var CraftingTransaction|null */ - protected $craftingTransaction = null; + protected ?CraftingTransaction $craftingTransaction = null; - /** @var float */ - protected $lastRightClickTime = 0.0; - /** @var UseItemTransactionData|null */ - protected $lastRightClickData = null; + protected float $lastRightClickTime = 0.0; + protected ?UseItemTransactionData $lastRightClickData = null; - /** @var bool */ - public $forceMoveSync = false; + public bool $forceMoveSync = false; public function __construct( private Player $player, diff --git a/src/network/mcpe/raklib/RakLibServer.php b/src/network/mcpe/raklib/RakLibServer.php index 674ca9e569..6bc8a65f2d 100644 --- a/src/network/mcpe/raklib/RakLibServer.php +++ b/src/network/mcpe/raklib/RakLibServer.php @@ -40,62 +40,22 @@ use function register_shutdown_function; use const PTHREADS_INHERIT_NONE; class RakLibServer extends Thread{ - private InternetAddress $address; - - /** @var \ThreadedLogger */ - protected $logger; - - /** @var bool */ - protected $cleanShutdown = false; - /** @var bool */ - protected $ready = false; - - /** @var \Threaded */ - protected $mainToThreadBuffer; - /** @var \Threaded */ - protected $threadToMainBuffer; - - /** @var string */ - protected $mainPath; - - /** @var int */ - protected $serverId; - /** @var int */ - protected $maxMtuSize; - - private int $protocolVersion; - - /** @var SleeperNotifier */ - protected $mainThreadNotifier; - - /** @var RakLibThreadCrashInfo|null */ - public $crashInfo = null; + protected bool $cleanShutdown = false; + protected bool $ready = false; + protected string $mainPath; + public ?RakLibThreadCrashInfo $crashInfo = null; public function __construct( - \ThreadedLogger $logger, - \Threaded $mainToThreadBuffer, - \Threaded $threadToMainBuffer, - InternetAddress $address, - int $serverId, - int $maxMtuSize, - int $protocolVersion, - SleeperNotifier $sleeper + protected \ThreadedLogger $logger, + protected \Threaded $mainToThreadBuffer, + protected \Threaded $threadToMainBuffer, + protected InternetAddress $address, + protected int $serverId, + protected int $maxMtuSize, + protected int $protocolVersion, + protected SleeperNotifier $mainThreadNotifier ){ - $this->address = $address; - - $this->serverId = $serverId; - $this->maxMtuSize = $maxMtuSize; - - $this->logger = $logger; - - $this->mainToThreadBuffer = $mainToThreadBuffer; - $this->threadToMainBuffer = $threadToMainBuffer; - $this->mainPath = \pocketmine\PATH; - - $this->protocolVersion = $protocolVersion; - - $this->mainThreadNotifier = $sleeper; } /** diff --git a/src/permission/BanEntry.php b/src/permission/BanEntry.php index d289cee875..e735a9e319 100644 --- a/src/permission/BanEntry.php +++ b/src/permission/BanEntry.php @@ -33,8 +33,7 @@ use function strtolower; use function trim; class BanEntry{ - /** @var string */ - public static $format = "Y-m-d H:i:s O"; + public static string $format = "Y-m-d H:i:s O"; private string $name; private \DateTime $creationDate; diff --git a/src/permission/PermissionManager.php b/src/permission/PermissionManager.php index 4123fb63d7..1297315332 100644 --- a/src/permission/PermissionManager.php +++ b/src/permission/PermissionManager.php @@ -38,9 +38,9 @@ class PermissionManager{ } /** @var Permission[] */ - protected $permissions = []; + protected array $permissions = []; /** @var PermissibleInternal[][] */ - protected $permSubs = []; + protected array $permSubs = []; public function getPermission(string $name) : ?Permission{ return $this->permissions[$name] ?? null; diff --git a/src/player/GameMode.php b/src/player/GameMode.php index 3ed7b42dc0..184ef119fb 100644 --- a/src/player/GameMode.php +++ b/src/player/GameMode.php @@ -46,7 +46,7 @@ final class GameMode{ } /** @var self[] */ - protected static $aliasMap = []; + protected static array $aliasMap = []; protected static function setup() : void{ self::registerAll( diff --git a/src/plugin/PluginLoadTriage.php b/src/plugin/PluginLoadTriage.php index c9c4fff773..d4f8891171 100644 --- a/src/plugin/PluginLoadTriage.php +++ b/src/plugin/PluginLoadTriage.php @@ -28,15 +28,15 @@ final class PluginLoadTriage{ * @var PluginLoadTriageEntry[] * @phpstan-var array */ - public $plugins = []; + public array $plugins = []; /** * @var string[][] * @phpstan-var array> */ - public $dependencies = []; + public array $dependencies = []; /** * @var string[][] * @phpstan-var array> */ - public $softDependencies = []; + public array $softDependencies = []; } diff --git a/src/plugin/PluginManager.php b/src/plugin/PluginManager.php index 36dcd91956..6770c99da4 100644 --- a/src/plugin/PluginManager.php +++ b/src/plugin/PluginManager.php @@ -70,10 +70,10 @@ use function strtolower; */ class PluginManager{ /** @var Plugin[] */ - protected $plugins = []; + protected array $plugins = []; /** @var Plugin[] */ - protected $enabledPlugins = []; + protected array $enabledPlugins = []; private bool $loadPluginsGuard = false; @@ -81,7 +81,7 @@ class PluginManager{ * @var PluginLoader[] * @phpstan-var array, PluginLoader> */ - protected $fileAssociations = []; + protected array $fileAssociations = []; public function __construct( private Server $server, diff --git a/src/promise/PromiseSharedData.php b/src/promise/PromiseSharedData.php index bccf56cc29..40fe699022 100644 --- a/src/promise/PromiseSharedData.php +++ b/src/promise/PromiseSharedData.php @@ -43,9 +43,6 @@ final class PromiseSharedData{ public bool $resolved = false; - /** - * @var mixed - * @phpstan-var TValue|null - */ - public $result = null; + /** @phpstan-var TValue|null */ + public mixed $result = null; } diff --git a/src/resourcepacks/ZippedResourcePack.php b/src/resourcepacks/ZippedResourcePack.php index 2ec39445b0..f46f0fd627 100644 --- a/src/resourcepacks/ZippedResourcePack.php +++ b/src/resourcepacks/ZippedResourcePack.php @@ -41,15 +41,9 @@ use function preg_match; use function strlen; class ZippedResourcePack implements ResourcePack{ - - /** @var string */ - protected $path; - - /** @var Manifest */ - protected $manifest; - - /** @var string|null */ - protected $sha256 = null; + protected string $path; + protected Manifest $manifest; + protected ?string $sha256 = null; /** @var resource */ protected $fileResource; diff --git a/src/scheduler/AsyncPool.php b/src/scheduler/AsyncPool.php index 184d82c8ad..46c6c61dbd 100644 --- a/src/scheduler/AsyncPool.php +++ b/src/scheduler/AsyncPool.php @@ -42,9 +42,6 @@ use const PTHREADS_INHERIT_INI; class AsyncPool{ private const WORKER_START_OPTIONS = PTHREADS_INHERIT_INI; - /** @var int */ - protected $size; - /** * @var \SplQueue[]|AsyncTask[][] * @phpstan-var array> @@ -69,14 +66,12 @@ class AsyncPool{ private array $workerStartHooks = []; public function __construct( - int $size, + protected int $size, private int $workerMemoryLimit, private \ClassLoader $classLoader, private \ThreadedLogger $logger, private SleeperHandler $eventLoop - ){ - $this->size = $size; - } + ){} /** * Returns the maximum size of the pool. Note that there may be less active workers than this number. diff --git a/src/scheduler/AsyncTask.php b/src/scheduler/AsyncTask.php index f3f506924a..1f8ea4b7f9 100644 --- a/src/scheduler/AsyncTask.php +++ b/src/scheduler/AsyncTask.php @@ -59,8 +59,7 @@ abstract class AsyncTask extends \Threaded{ /** @var AsyncWorker|null $worker */ public $worker = null; - /** @var \Threaded */ - public $progressUpdates; + public \Threaded $progressUpdates; private string|int|bool|null|float $result = null; private bool $serialized = false; diff --git a/src/scheduler/TaskHandler.php b/src/scheduler/TaskHandler.php index 2d2af86246..7fbf8e1b7a 100644 --- a/src/scheduler/TaskHandler.php +++ b/src/scheduler/TaskHandler.php @@ -27,34 +27,24 @@ use pocketmine\timings\Timings; use pocketmine\timings\TimingsHandler; class TaskHandler{ + protected int $nextRun; - /** @var Task */ - protected $task; - - /** @var int */ - protected $delay; - - /** @var int */ - protected $period; - - /** @var int */ - protected $nextRun; - - /** @var bool */ - protected $cancelled = false; + protected bool $cancelled = false; private TimingsHandler $timings; private string $taskName; private string $ownerName; - public function __construct(Task $task, int $delay = -1, int $period = -1, ?string $ownerName = null){ + public function __construct( + protected Task $task, + protected int $delay = -1, + protected int $period = -1, + ?string $ownerName = null + ){ if($task->getHandler() !== null){ throw new \InvalidArgumentException("Cannot assign multiple handlers to the same task"); } - $this->task = $task; - $this->delay = $delay; - $this->period = $period; $this->taskName = $task->getName(); $this->ownerName = $ownerName ?? "Unknown"; $this->timings = Timings::getScheduledTaskTimings($this, $period); diff --git a/src/scheduler/TaskScheduler.php b/src/scheduler/TaskScheduler.php index 86e0bb3319..e9743f375a 100644 --- a/src/scheduler/TaskScheduler.php +++ b/src/scheduler/TaskScheduler.php @@ -33,20 +33,16 @@ use pocketmine\utils\ReversePriorityQueue; class TaskScheduler{ private bool $enabled = true; - /** - * @var ReversePriorityQueue - * @phpstan-var ReversePriorityQueue - */ - protected $queue; + /** @phpstan-var ReversePriorityQueue */ + protected ReversePriorityQueue $queue; /** * @var ObjectSet|TaskHandler[] * @phpstan-var ObjectSet */ - protected $tasks; + protected ObjectSet $tasks; - /** @var int */ - protected $currentTick = 0; + protected int $currentTick = 0; public function __construct( private ?string $owner = null diff --git a/src/stats/SendUsageTask.php b/src/stats/SendUsageTask.php index 2064caf08c..59c56b2325 100644 --- a/src/stats/SendUsageTask.php +++ b/src/stats/SendUsageTask.php @@ -49,10 +49,8 @@ class SendUsageTask extends AsyncTask{ public const TYPE_STATUS = 2; public const TYPE_CLOSE = 3; - /** @var string */ - public $endpoint; - /** @var string */ - public $data; + public string $endpoint; + public string $data; /** * @param string[] $playerList diff --git a/src/thread/CommonThreadPartsTrait.php b/src/thread/CommonThreadPartsTrait.php index 3f609d8330..8085cf8d62 100644 --- a/src/thread/CommonThreadPartsTrait.php +++ b/src/thread/CommonThreadPartsTrait.php @@ -30,11 +30,9 @@ use function error_reporting; trait CommonThreadPartsTrait{ /** @var \Threaded|\ClassLoader[]|null */ private ?\Threaded $classLoaders = null; - /** @var string|null */ - protected $composerAutoloaderPath; + protected ?string $composerAutoloaderPath; - /** @var bool */ - protected $isKilled = false; + protected bool $isKilled = false; /** * @return \ClassLoader[] diff --git a/src/timings/Timings.php b/src/timings/Timings.php index d3dd855789..0fc7c52bbd 100644 --- a/src/timings/Timings.php +++ b/src/timings/Timings.php @@ -36,96 +36,58 @@ abstract class Timings{ private static bool $initialized = false; - /** @var TimingsHandler */ - public static $fullTick; - /** @var TimingsHandler */ - public static $serverTick; - /** @var TimingsHandler */ - public static $memoryManager; - /** @var TimingsHandler */ - public static $garbageCollector; - /** @var TimingsHandler */ - public static $titleTick; - /** @var TimingsHandler */ - public static $playerNetworkSend; - /** @var TimingsHandler */ - public static $playerNetworkSendCompress; - /** @var TimingsHandler */ - public static $playerNetworkSendEncrypt; - /** @var TimingsHandler */ - public static $playerNetworkReceive; - /** @var TimingsHandler */ - public static $playerNetworkReceiveDecompress; - /** @var TimingsHandler */ - public static $playerNetworkReceiveDecrypt; - /** @var TimingsHandler */ - public static $playerChunkOrder; - /** @var TimingsHandler */ - public static $playerChunkSend; - /** @var TimingsHandler */ - public static $connection; - /** @var TimingsHandler */ - public static $scheduler; - /** @var TimingsHandler */ - public static $serverCommand; - /** @var TimingsHandler */ - public static $worldLoad; - /** @var TimingsHandler */ - public static $worldSave; - /** @var TimingsHandler */ - public static $population; - /** @var TimingsHandler */ - public static $generationCallback; - /** @var TimingsHandler */ - public static $permissibleCalculation; - /** @var TimingsHandler */ - public static $permissibleCalculationDiff; - /** @var TimingsHandler */ - public static $permissibleCalculationCallback; + public static TimingsHandler $fullTick; + public static TimingsHandler $serverTick; + public static TimingsHandler $memoryManager; + public static TimingsHandler $garbageCollector; + public static TimingsHandler $titleTick; + public static TimingsHandler $playerNetworkSend; + public static TimingsHandler $playerNetworkSendCompress; + public static TimingsHandler $playerNetworkSendEncrypt; + public static TimingsHandler $playerNetworkReceive; + public static TimingsHandler $playerNetworkReceiveDecompress; + public static TimingsHandler $playerNetworkReceiveDecrypt; + public static TimingsHandler $playerChunkOrder; + public static TimingsHandler $playerChunkSend; + public static TimingsHandler $connection; + public static TimingsHandler $scheduler; + public static TimingsHandler $serverCommand; + public static TimingsHandler $worldLoad; + public static TimingsHandler $worldSave; + public static TimingsHandler $population; + public static TimingsHandler $generationCallback; + public static TimingsHandler $permissibleCalculation; + public static TimingsHandler $permissibleCalculationDiff; + public static TimingsHandler $permissibleCalculationCallback; + public static TimingsHandler $entityMove; + public static TimingsHandler $playerCheckNearEntities; + public static TimingsHandler $tickEntity; + public static TimingsHandler $tickTileEntity; + public static TimingsHandler $entityBaseTick; + public static TimingsHandler $livingEntityBaseTick; - /** @var TimingsHandler */ - public static $entityMove; - /** @var TimingsHandler */ - public static $playerCheckNearEntities; - /** @var TimingsHandler */ - public static $tickEntity; - /** @var TimingsHandler */ - public static $tickTileEntity; + public static TimingsHandler $schedulerSync; + public static TimingsHandler $schedulerAsync; - /** @var TimingsHandler */ - public static $entityBaseTick; - /** @var TimingsHandler */ - public static $livingEntityBaseTick; + public static TimingsHandler $playerCommand; - /** @var TimingsHandler */ - public static $schedulerSync; - /** @var TimingsHandler */ - public static $schedulerAsync; + public static TimingsHandler $craftingDataCacheRebuild; - /** @var TimingsHandler */ - public static $playerCommand; - - /** @var TimingsHandler */ - public static $craftingDataCacheRebuild; - - /** @var TimingsHandler */ - public static $syncPlayerDataLoad; - /** @var TimingsHandler */ - public static $syncPlayerDataSave; + public static TimingsHandler $syncPlayerDataLoad; + public static TimingsHandler $syncPlayerDataSave; /** @var TimingsHandler[] */ - public static $entityTypeTimingMap = []; + public static array $entityTypeTimingMap = []; /** @var TimingsHandler[] */ - public static $tileEntityTypeTimingMap = []; + public static array $tileEntityTypeTimingMap = []; /** @var TimingsHandler[] */ - public static $packetReceiveTimingMap = []; + public static array $packetReceiveTimingMap = []; /** @var TimingsHandler[] */ - public static $packetSendTimingMap = []; + public static array $packetSendTimingMap = []; /** @var TimingsHandler[] */ - public static $pluginTaskTimingMap = []; + public static array $pluginTaskTimingMap = []; - /** @var TimingsHandler */ - public static $broadcastPackets; + public static TimingsHandler $broadcastPackets; public static function init() : void{ if(self::$initialized){ diff --git a/src/updater/UpdateChecker.php b/src/updater/UpdateChecker.php index 298704a5a8..6eb5e7d297 100644 --- a/src/updater/UpdateChecker.php +++ b/src/updater/UpdateChecker.php @@ -33,13 +33,9 @@ use function ucfirst; class UpdateChecker{ - /** @var Server */ - protected $server; - /** @var string */ - protected $endpoint; - /** @var UpdateInfo|null */ - protected $updateInfo = null; - + protected Server $server; + protected string $endpoint; + protected ?UpdateInfo $updateInfo = null; private \Logger $logger; public function __construct(Server $server, string $endpoint){ diff --git a/src/utils/Config.php b/src/utils/Config.php index 3fa78df807..d365b11925 100644 --- a/src/utils/Config.php +++ b/src/utils/Config.php @@ -89,7 +89,7 @@ class Config{ private bool $changed = false; /** @var int[] */ - public static $formats = [ + public static array $formats = [ "properties" => Config::PROPERTIES, "cnf" => Config::CNF, "conf" => Config::CNF, diff --git a/src/utils/Internet.php b/src/utils/Internet.php index 7facf73b58..3b43f87dd9 100644 --- a/src/utils/Internet.php +++ b/src/utils/Internet.php @@ -64,10 +64,8 @@ use const SOCK_DGRAM; use const SOL_UDP; class Internet{ - /** @var string|false */ - public static $ip = false; - /** @var bool */ - public static $online = true; + public static string|false $ip = false; + public static bool $online = true; /** * Gets the External IP using an external service, it is cached diff --git a/src/utils/MainLogger.php b/src/utils/MainLogger.php index 1e0c430d8b..88d47c55b7 100644 --- a/src/utils/MainLogger.php +++ b/src/utils/MainLogger.php @@ -32,8 +32,7 @@ use const PHP_EOL; use const PTHREADS_INHERIT_NONE; class MainLogger extends \AttachableThreadedLogger implements \BufferedLogger{ - /** @var bool */ - protected $logDebug; + protected bool $logDebug; private string $format = TextFormat::AQUA . "[%s] " . TextFormat::RESET . "%s[%s/%s]: %s" . TextFormat::RESET; private bool $useFormattingCodes = false; diff --git a/src/utils/Random.php b/src/utils/Random.php index 6e932a0798..e95f8c7829 100644 --- a/src/utils/Random.php +++ b/src/utils/Random.php @@ -40,8 +40,7 @@ class Random{ private int $z; private int $w; - /** @var int */ - protected $seed; + protected int $seed; /** * @param int $seed Integer to be used as seed. diff --git a/src/utils/ServerKiller.php b/src/utils/ServerKiller.php index 67168fe877..05ad20034c 100644 --- a/src/utils/ServerKiller.php +++ b/src/utils/ServerKiller.php @@ -27,18 +27,11 @@ use pocketmine\thread\Thread; use function time; class ServerKiller extends Thread{ - - /** @var int */ - public $time; - private bool $stopped = false; - /** - * @param int $time - */ - public function __construct($time = 15){ - $this->time = $time; - } + public function __construct( + public int $time = 15 + ){} protected function onRun() : void{ $start = time(); diff --git a/src/world/Explosion.php b/src/world/Explosion.php index 209fd3e30a..48b689e56e 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -48,35 +48,27 @@ use function sqrt; class Explosion{ private int $rays = 16; - /** @var World */ - public $world; - /** @var Position */ - public $source; - /** @var float */ - public $size; + public World $world; /** @var Block[] */ - public $affectedBlocks = []; - /** @var float */ - public $stepLen = 0.3; - - private Entity|Block|null $what; + public array $affectedBlocks = []; + public float $stepLen = 0.3; private SubChunkExplorer $subChunkExplorer; - public function __construct(Position $center, float $size, Entity|Block|null $what = null){ - if(!$center->isValid()){ + public function __construct( + public Position $source, + public float $size, + private Entity|Block|null $what = null + ){ + if(!$this->source->isValid()){ throw new \InvalidArgumentException("Position does not have a valid world"); } - $this->source = $center; - $this->world = $center->getWorld(); + $this->world = $this->source->getWorld(); if($size <= 0){ throw new \InvalidArgumentException("Explosion radius must be greater than 0, got $size"); } - $this->size = $size; - - $this->what = $what; $this->subChunkExplorer = new SubChunkExplorer($this->world); } diff --git a/src/world/SimpleChunkManager.php b/src/world/SimpleChunkManager.php index a56095a17b..45c6e1b03a 100644 --- a/src/world/SimpleChunkManager.php +++ b/src/world/SimpleChunkManager.php @@ -32,7 +32,7 @@ use pocketmine\world\format\Chunk; class SimpleChunkManager implements ChunkManager{ /** @var Chunk[] */ - protected $chunks = []; + protected array $chunks = []; public function __construct( private int $minY, diff --git a/src/world/World.php b/src/world/World.php index 196c2729c1..65300005bc 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -170,7 +170,7 @@ class World implements ChunkManager{ private array $entitiesByChunk = []; /** @var Entity[] */ - public $updateEntities = []; + public array $updateEntities = []; /** @var Block[][] */ private array $blockCache = []; @@ -202,8 +202,7 @@ class World implements ChunkManager{ private array $unloadQueue = []; private int $time; - /** @var bool */ - public $stopTime = false; + public bool $stopTime = false; private float $sunAnglePercentage = 0.0; private int $skyLightReduction = 0; @@ -261,11 +260,9 @@ class World implements ChunkManager{ /** @var bool[] */ private array $randomTickBlocks = []; - /** @var WorldTimings */ - public $timings; + public WorldTimings $timings; - /** @var float */ - public $tickRateTime = 0; + public float $tickRateTime = 0; private bool $doingTick = false; diff --git a/src/world/biome/Biome.php b/src/world/biome/Biome.php index 6115beabe1..dd85f912f5 100644 --- a/src/world/biome/Biome.php +++ b/src/world/biome/Biome.php @@ -44,10 +44,8 @@ abstract class Biome{ /** @var Block[] */ private array $groundCover = []; - /** @var float */ - protected $rainfall = 0.5; - /** @var float */ - protected $temperature = 0.5; + protected float $rainfall = 0.5; + protected float $temperature = 0.5; public function clearPopulators() : void{ $this->populators = []; diff --git a/src/world/format/Chunk.php b/src/world/format/Chunk.php index b3265cbdba..825d9b7569 100644 --- a/src/world/format/Chunk.php +++ b/src/world/format/Chunk.php @@ -45,25 +45,21 @@ class Chunk{ private int $terrainDirtyFlags = 0; - /** @var bool|null */ - protected $lightPopulated = false; - /** @var bool */ - protected $terrainPopulated = false; + protected ?bool $lightPopulated = false; + protected bool $terrainPopulated = false; /** * @var \SplFixedArray|SubChunk[] * @phpstan-var \SplFixedArray */ - protected $subChunks; + protected \SplFixedArray $subChunks; /** @var Tile[] */ - protected $tiles = []; + protected array $tiles = []; - /** @var HeightArray */ - protected $heightMap; + protected HeightArray $heightMap; - /** @var BiomeArray */ - protected $biomeIds; + protected BiomeArray $biomeIds; /** * @param SubChunk[] $subChunks diff --git a/src/world/format/io/BaseWorldProvider.php b/src/world/format/io/BaseWorldProvider.php index 6404f641b8..8be5a11435 100644 --- a/src/world/format/io/BaseWorldProvider.php +++ b/src/world/format/io/BaseWorldProvider.php @@ -29,17 +29,15 @@ use pocketmine\world\WorldException; use function file_exists; abstract class BaseWorldProvider implements WorldProvider{ - /** @var string */ - protected $path; - /** @var WorldData */ - protected $worldData; + protected WorldData $worldData; - public function __construct(string $path){ + public function __construct( + protected string $path + ){ if(!file_exists($path)){ throw new WorldException("World does not exist"); } - $this->path = $path; $this->worldData = $this->loadLevelData(); } diff --git a/src/world/format/io/WorldProviderManager.php b/src/world/format/io/WorldProviderManager.php index db67c62216..9f741fcb01 100644 --- a/src/world/format/io/WorldProviderManager.php +++ b/src/world/format/io/WorldProviderManager.php @@ -36,7 +36,7 @@ final class WorldProviderManager{ * @var WorldProviderManagerEntry[] * @phpstan-var array */ - protected $providers = []; + protected array $providers = []; private WritableWorldProviderManagerEntry $default; diff --git a/src/world/format/io/data/BaseNbtWorldData.php b/src/world/format/io/data/BaseNbtWorldData.php index 43016af0a2..d0f8eb5903 100644 --- a/src/world/format/io/data/BaseNbtWorldData.php +++ b/src/world/format/io/data/BaseNbtWorldData.php @@ -32,20 +32,15 @@ use pocketmine\world\format\io\WorldData; use function file_exists; abstract class BaseNbtWorldData implements WorldData{ - - /** @var string */ - protected $dataPath; - - /** @var CompoundTag */ - protected $compoundTag; + protected CompoundTag $compoundTag; /** * @throws CorruptedWorldException * @throws UnsupportedWorldFormatException */ - public function __construct(string $dataPath){ - $this->dataPath = $dataPath; - + public function __construct( + protected string $dataPath + ){ if(!file_exists($this->dataPath)){ throw new CorruptedWorldException("World data not found at $dataPath"); } diff --git a/src/world/format/io/leveldb/LevelDB.php b/src/world/format/io/leveldb/LevelDB.php index 671acb6d99..f8fd42f10e 100644 --- a/src/world/format/io/leveldb/LevelDB.php +++ b/src/world/format/io/leveldb/LevelDB.php @@ -96,8 +96,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{ protected const CURRENT_LEVEL_CHUNK_VERSION = ChunkVersion::v1_2_0; //yes, I know this is wrong, but it ensures vanilla auto-fixes stuff we currently don't protected const CURRENT_LEVEL_SUBCHUNK_VERSION = SubChunkVersion::PALETTED_MULTI; - /** @var \LevelDB */ - protected $db; + protected \LevelDB $db; private static function checkForLevelDBExtension() : void{ if(!extension_loaded('leveldb')){ diff --git a/src/world/format/io/region/RegionLoader.php b/src/world/format/io/region/RegionLoader.php index bdd31b8dc1..71e92d477f 100644 --- a/src/world/format/io/region/RegionLoader.php +++ b/src/world/format/io/region/RegionLoader.php @@ -64,24 +64,20 @@ class RegionLoader{ public const FIRST_SECTOR = 2; //location table occupies 0 and 1 - /** @var string */ - protected $filePath; /** @var resource */ protected $filePointer; - /** @var int */ - protected $nextSector = self::FIRST_SECTOR; + protected int $nextSector = self::FIRST_SECTOR; /** @var RegionLocationTableEntry[]|null[] */ - protected $locationTable = []; - /** @var RegionGarbageMap */ - protected $garbageTable; - /** @var int */ - public $lastUsed = 0; + protected array $locationTable = []; + protected RegionGarbageMap $garbageTable; + public int $lastUsed; /** * @throws CorruptedRegionException */ - private function __construct(string $filePath){ - $this->filePath = $filePath; + private function __construct( + protected string $filePath + ){ $this->garbageTable = new RegionGarbageMap([]); $this->lastUsed = time(); diff --git a/src/world/format/io/region/RegionWorldProvider.php b/src/world/format/io/region/RegionWorldProvider.php index 25fcf65b37..23bfeb31a8 100644 --- a/src/world/format/io/region/RegionWorldProvider.php +++ b/src/world/format/io/region/RegionWorldProvider.php @@ -73,7 +73,7 @@ abstract class RegionWorldProvider extends BaseWorldProvider{ } /** @var RegionLoader[] */ - protected $regions = []; + protected array $regions = []; protected function loadLevelData() : WorldData{ return new JavaWorldData(Path::join($this->getPath(), "level.dat")); diff --git a/src/world/generator/Generator.php b/src/world/generator/Generator.php index acc8cc88fc..db58e0639c 100644 --- a/src/world/generator/Generator.php +++ b/src/world/generator/Generator.php @@ -48,17 +48,12 @@ abstract class Generator{ return $convertedSeed; } - /** @var int */ - protected $seed; + protected Random $random; - protected string $preset; - - /** @var Random */ - protected $random; - - public function __construct(int $seed, string $preset){ - $this->seed = $seed; - $this->preset = $preset; + public function __construct( + protected int $seed, + protected string $preset + ){ $this->random = new Random($seed); } diff --git a/src/world/generator/GeneratorRegisterTask.php b/src/world/generator/GeneratorRegisterTask.php index b8b2ea67d0..50e765c9c7 100644 --- a/src/world/generator/GeneratorRegisterTask.php +++ b/src/world/generator/GeneratorRegisterTask.php @@ -27,29 +27,19 @@ use pocketmine\scheduler\AsyncTask; use pocketmine\world\World; class GeneratorRegisterTask extends AsyncTask{ - - /** - * @var string - * @phpstan-var class-string - */ - public $generatorClass; - /** @var string */ - public $settings; - /** @var int */ - public $seed; - /** @var int */ - public $worldId; - /** @var int */ - public $worldMinY; - /** @var int */ - public $worldMaxY; + public int $seed; + public int $worldId; + public int $worldMinY; + public int $worldMaxY; /** * @phpstan-param class-string $generatorClass */ - public function __construct(World $world, string $generatorClass, string $generatorSettings){ - $this->generatorClass = $generatorClass; - $this->settings = $generatorSettings; + public function __construct( + World $world, + public string $generatorClass, + public string $generatorSettings + ){ $this->seed = $world->getSeed(); $this->worldId = $world->getId(); $this->worldMinY = $world->getMinY(); @@ -61,7 +51,7 @@ class GeneratorRegisterTask extends AsyncTask{ * @var Generator $generator * @see Generator::__construct() */ - $generator = new $this->generatorClass($this->seed, $this->settings); + $generator = new $this->generatorClass($this->seed, $this->generatorSettings); ThreadLocalGeneratorContext::register(new ThreadLocalGeneratorContext($generator, $this->worldMinY, $this->worldMaxY), $this->worldId); } } diff --git a/src/world/generator/GeneratorUnregisterTask.php b/src/world/generator/GeneratorUnregisterTask.php index c9022e9e2b..29ab9dc499 100644 --- a/src/world/generator/GeneratorUnregisterTask.php +++ b/src/world/generator/GeneratorUnregisterTask.php @@ -27,9 +27,7 @@ use pocketmine\scheduler\AsyncTask; use pocketmine\world\World; class GeneratorUnregisterTask extends AsyncTask{ - - /** @var int */ - public $worldId; + public int $worldId; public function __construct(World $world){ $this->worldId = $world->getId(); diff --git a/src/world/generator/noise/Noise.php b/src/world/generator/noise/Noise.php index 1d0b7b3b10..a001c1bea4 100644 --- a/src/world/generator/noise/Noise.php +++ b/src/world/generator/noise/Noise.php @@ -111,18 +111,11 @@ abstract class Noise{ ); } - /** @var float */ - protected $persistence; - /** @var float */ - protected $expansion; - /** @var int */ - protected $octaves; - - public function __construct(int $octaves, float $persistence, float $expansion){ - $this->octaves = $octaves; - $this->persistence = $persistence; - $this->expansion = $expansion; - } + public function __construct( + protected int $octaves, + protected float $persistence, + protected float $expansion + ){} /** * @param float $x diff --git a/src/world/generator/noise/Simplex.php b/src/world/generator/noise/Simplex.php index 71ef32cffc..7d92a08bb5 100644 --- a/src/world/generator/noise/Simplex.php +++ b/src/world/generator/noise/Simplex.php @@ -46,14 +46,11 @@ class Simplex extends Noise{ protected const F3 = 1.0 / 3.0; protected const G3 = 1.0 / 6.0; - /** @var float */ - protected $offsetX; - /** @var float */ - protected $offsetZ; - /** @var float */ - protected $offsetY; + protected float $offsetX; + protected float $offsetZ; + protected float $offsetY; /** @var int[] */ - protected $perm = []; + protected array $perm = []; public function __construct(Random $random, int $octaves, float $persistence, float $expansion){ parent::__construct($octaves, $persistence, $expansion); diff --git a/src/world/generator/object/BirchTree.php b/src/world/generator/object/BirchTree.php index 5bd0b98ffe..2a20ceb0da 100644 --- a/src/world/generator/object/BirchTree.php +++ b/src/world/generator/object/BirchTree.php @@ -29,12 +29,10 @@ use pocketmine\world\BlockTransaction; use pocketmine\world\ChunkManager; class BirchTree extends Tree{ - /** @var bool */ - protected $superBirch = false; - - public function __construct(bool $superBirch = false){ + public function __construct( + protected bool $superBirch = false + ){ parent::__construct(VanillaBlocks::BIRCH_LOG(), VanillaBlocks::BIRCH_LEAVES()); - $this->superBirch = $superBirch; } public function getBlockTransaction(ChunkManager $world, int $x, int $y, int $z, Random $random) : ?BlockTransaction{ diff --git a/src/world/generator/object/Ore.php b/src/world/generator/object/Ore.php index e534545c08..ce1ec3be49 100644 --- a/src/world/generator/object/Ore.php +++ b/src/world/generator/object/Ore.php @@ -30,14 +30,10 @@ use function sin; use const M_PI; class Ore{ - private Random $random; - /** @var OreType */ - public $type; - - public function __construct(Random $random, OreType $type){ - $this->type = $type; - $this->random = $random; - } + public function __construct( + private Random $random, + public OreType $type + ){} public function getType() : OreType{ return $this->type; diff --git a/src/world/generator/object/Tree.php b/src/world/generator/object/Tree.php index 9b032ad957..0a9d1e196a 100644 --- a/src/world/generator/object/Tree.php +++ b/src/world/generator/object/Tree.php @@ -33,20 +33,11 @@ use pocketmine\world\ChunkManager; use function abs; abstract class Tree{ - /** @var Block */ - protected $trunkBlock; - /** @var Block */ - protected $leafBlock; - - /** @var int */ - protected $treeHeight; - - public function __construct(Block $trunkBlock, Block $leafBlock, int $treeHeight = 7){ - $this->trunkBlock = $trunkBlock; - $this->leafBlock = $leafBlock; - - $this->treeHeight = $treeHeight; - } + public function __construct( + protected Block $trunkBlock, + protected Block $leafBlock, + protected int $treeHeight = 7 + ){} public function canPlaceObject(ChunkManager $world, int $x, int $y, int $z, Random $random) : bool{ $radiusToCheck = 0; diff --git a/src/world/light/LightPopulationTask.php b/src/world/light/LightPopulationTask.php index 94c66e6867..041f249b0c 100644 --- a/src/world/light/LightPopulationTask.php +++ b/src/world/light/LightPopulationTask.php @@ -37,8 +37,7 @@ use function igbinary_unserialize; class LightPopulationTask extends AsyncTask{ private const TLS_KEY_COMPLETION_CALLBACK = "onCompletion"; - /** @var string */ - public $chunk; + public string $chunk; private string $resultHeightMap; private string $resultSkyLightArrays; diff --git a/src/world/light/LightPropagationContext.php b/src/world/light/LightPropagationContext.php index a13e5ae200..6a7afb1cdc 100644 --- a/src/world/light/LightPropagationContext.php +++ b/src/world/light/LightPropagationContext.php @@ -25,27 +25,21 @@ namespace pocketmine\world\light; final class LightPropagationContext{ - /** - * @var \SplQueue - * @phpstan-var \SplQueue - */ - public $spreadQueue; + /** @phpstan-var \SplQueue */ + public \SplQueue $spreadQueue; /** * @var true[] * @phpstan-var array */ - public $spreadVisited = []; + public array $spreadVisited = []; - /** - * @var \SplQueue - * @phpstan-var \SplQueue - */ - public $removalQueue; + /** @phpstan-var \SplQueue */ + public \SplQueue $removalQueue; /** * @var true[] * @phpstan-var array */ - public $removalVisited = []; + public array $removalVisited = []; public function __construct(){ $this->removalQueue = new \SplQueue(); diff --git a/src/world/light/LightUpdate.php b/src/world/light/LightUpdate.php index 9570b8e037..a89fb29a80 100644 --- a/src/world/light/LightUpdate.php +++ b/src/world/light/LightUpdate.php @@ -41,30 +41,20 @@ abstract class LightUpdate{ [ 0, 0, -1] ]; - /** - * @var \SplFixedArray|int[] - * @phpstan-var \SplFixedArray - */ - protected $lightFilters; - /** * @var int[][] blockhash => [x, y, z, new light level] * @phpstan-var array */ - protected $updateNodes = []; - - /** @var SubChunkExplorer */ - protected $subChunkExplorer; + protected array $updateNodes = []; /** * @param \SplFixedArray|int[] $lightFilters * @phpstan-param \SplFixedArray $lightFilters */ - public function __construct(SubChunkExplorer $subChunkExplorer, \SplFixedArray $lightFilters){ - $this->lightFilters = $lightFilters; - - $this->subChunkExplorer = $subChunkExplorer; - } + public function __construct( + protected SubChunkExplorer $subChunkExplorer, + protected \SplFixedArray $lightFilters + ){} abstract protected function getCurrentLightArray() : LightArray; diff --git a/src/world/particle/FloatingTextParticle.php b/src/world/particle/FloatingTextParticle.php index a8358ce817..a3f1eafc4a 100644 --- a/src/world/particle/FloatingTextParticle.php +++ b/src/world/particle/FloatingTextParticle.php @@ -46,19 +46,13 @@ use function str_repeat; class FloatingTextParticle implements Particle{ //TODO: HACK! - /** @var string */ - protected $text; - /** @var string */ - protected $title; - /** @var int|null */ - protected $entityId = null; - /** @var bool */ - protected $invisible = false; + protected ?int $entityId = null; + protected bool $invisible = false; - public function __construct(string $text, string $title = ""){ - $this->text = $text; - $this->title = $title; - } + public function __construct( + protected string $text, + protected string $title = "" + ){} public function getText() : string{ return $this->text; diff --git a/src/world/particle/MobSpawnParticle.php b/src/world/particle/MobSpawnParticle.php index 07706888e8..6ccb4cf245 100644 --- a/src/world/particle/MobSpawnParticle.php +++ b/src/world/particle/MobSpawnParticle.php @@ -28,15 +28,11 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\LevelEvent; class MobSpawnParticle implements Particle{ - /** @var int */ - protected $width; - /** @var int */ - protected $height; - - public function __construct(int $width = 0, int $height = 0){ + public function __construct( + protected int $width = 0, + protected int $height = 0 + ){ //TODO: bounds checks - $this->width = $width; - $this->height = $height; } public function encode(Vector3 $pos) : array{ diff --git a/src/world/utils/SubChunkExplorer.php b/src/world/utils/SubChunkExplorer.php index 1a52dd9cbb..d4275e951f 100644 --- a/src/world/utils/SubChunkExplorer.php +++ b/src/world/utils/SubChunkExplorer.php @@ -28,24 +28,16 @@ use pocketmine\world\format\Chunk; use pocketmine\world\format\SubChunk; class SubChunkExplorer{ - /** @var ChunkManager */ - protected $world; + public ?Chunk $currentChunk; + public ?SubChunk $currentSubChunk; - /** @var Chunk|null */ - public $currentChunk; - /** @var SubChunk|null */ - public $currentSubChunk; + protected int $currentX; + protected int $currentY; + protected int $currentZ; - /** @var int */ - protected $currentX; - /** @var int */ - protected $currentY; - /** @var int */ - protected $currentZ; - - public function __construct(ChunkManager $world){ - $this->world = $world; - } + public function __construct( + protected ChunkManager $world + ){} /** * @phpstan-return SubChunkExplorerStatus::*