From 9930de01b9b06be10972e67a6c5379eb92a3cbec Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Apr 2022 16:38:36 +0100 Subject: [PATCH 01/29] Bump phpstan/phpstan-phpunit from 1.1.0 to 1.1.1 (#4979) Bumps [phpstan/phpstan-phpunit](https://github.com/phpstan/phpstan-phpunit) from 1.1.0 to 1.1.1. - [Release notes](https://github.com/phpstan/phpstan-phpunit/releases) - [Commits](https://github.com/phpstan/phpstan-phpunit/compare/1.1.0...1.1.1) --- updated-dependencies: - dependency-name: phpstan/phpstan-phpunit dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index b38a0c0cb..3feed4f37 100644 --- a/composer.lock +++ b/composer.lock @@ -1878,16 +1878,16 @@ }, { "name": "phpstan/phpstan-phpunit", - "version": "1.1.0", + "version": "1.1.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "09133ce914f1388a8bb8c7f8573aaa3723cff52a" + "reference": "4a3c437c09075736285d1cabb5c75bf27ed0bc84" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/09133ce914f1388a8bb8c7f8573aaa3723cff52a", - "reference": "09133ce914f1388a8bb8c7f8573aaa3723cff52a", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/4a3c437c09075736285d1cabb5c75bf27ed0bc84", + "reference": "4a3c437c09075736285d1cabb5c75bf27ed0bc84", "shasum": "" }, "require": { @@ -1924,9 +1924,9 @@ "description": "PHPUnit extensions and rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-phpunit/issues", - "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.1.0" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.1.1" }, - "time": "2022-03-28T09:20:49+00:00" + "time": "2022-04-20T15:24:25+00:00" }, { "name": "phpstan/phpstan-strict-rules", @@ -3452,5 +3452,5 @@ "platform-overrides": { "php": "8.0.0" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } From 27056b6c374b586f7994618e2aa644d68cad9414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AD=E3=82=89=E3=81=B2=E3=81=8B=E3=81=A0?= Date: Fri, 22 Apr 2022 00:39:36 +0900 Subject: [PATCH 02/29] Player: creative players should not be damaged by the void (#4978) --- src/player/Player.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/player/Player.php b/src/player/Player.php index cb9ef0a5b..61922be88 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -2315,7 +2315,6 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ if($this->isCreative() && $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE - && $source->getCause() !== EntityDamageEvent::CAUSE_VOID ){ $source->cancel(); }elseif($this->allowFlight && $source->getCause() === EntityDamageEvent::CAUSE_FALL){ From aaba8a2a9ae21d88a590512d2bb386fb57e194fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Apr 2022 16:45:16 +0100 Subject: [PATCH 03/29] Bump phpstan/phpstan from 1.5.6 to 1.5.7 (#4975) Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 1.5.6 to 1.5.7. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/1.6.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.5.6...1.5.7) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 085d3d536..8ed24acf7 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,7 @@ "webmozart/path-util": "^2.3" }, "require-dev": { - "phpstan/phpstan": "1.5.6", + "phpstan/phpstan": "1.5.7", "phpstan/phpstan-phpunit": "^1.1.0", "phpstan/phpstan-strict-rules": "^1.0.0", "phpunit/phpunit": "^9.2" diff --git a/composer.lock b/composer.lock index 3feed4f37..c3802d1af 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "bc9cfcfe04209226c67d903f77cb1620", + "content-hash": "fa508967e1ffdb63b73de2c40c5b8f11", "packages": [ { "name": "adhocore/json-comment", @@ -1819,16 +1819,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.5.6", + "version": "1.5.7", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "799dd8c2d2c9c704bb55d2078078cb970cf0f6d1" + "reference": "7fb7e2e1e9f3d59a26a413b2d3d5e47f0edb75ac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/799dd8c2d2c9c704bb55d2078078cb970cf0f6d1", - "reference": "799dd8c2d2c9c704bb55d2078078cb970cf0f6d1", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7fb7e2e1e9f3d59a26a413b2d3d5e47f0edb75ac", + "reference": "7fb7e2e1e9f3d59a26a413b2d3d5e47f0edb75ac", "shasum": "" }, "require": { @@ -1854,7 +1854,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.5.6" + "source": "https://github.com/phpstan/phpstan/tree/1.5.7" }, "funding": [ { @@ -1874,7 +1874,7 @@ "type": "tidelift" } ], - "time": "2022-04-15T11:13:37+00:00" + "time": "2022-04-20T12:20:27+00:00" }, { "name": "phpstan/phpstan-phpunit", From e8994dbc174b6269acf3a5a25165a4409750d417 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 23 Apr 2022 14:20:47 +0100 Subject: [PATCH 04/29] Bump build/php from `1fae6b8` to `7b357f8` (#4987) Bumps [build/php](https://github.com/pmmp/php-build-scripts) from `1fae6b8` to `7b357f8`. - [Release notes](https://github.com/pmmp/php-build-scripts/releases) - [Commits](https://github.com/pmmp/php-build-scripts/compare/1fae6b8d4ab89757316e7e70e77cadfd4fd26b3e...7b357f8cf9b2d2ee3a9ad247cdc76c8ad62337f9) --- updated-dependencies: - dependency-name: build/php dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- build/php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/php b/build/php index 1fae6b8d4..7b357f8cf 160000 --- a/build/php +++ b/build/php @@ -1 +1 @@ -Subproject commit 1fae6b8d4ab89757316e7e70e77cadfd4fd26b3e +Subproject commit 7b357f8cf9b2d2ee3a9ad247cdc76c8ad62337f9 From dff5c30172c99d89259346f7d77c4a48b4a4c65d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 23 Apr 2022 16:01:08 +0100 Subject: [PATCH 05/29] Updated BedrockProtocol to 9.0.1 --- composer.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index c3802d1af..7f353a9bf 100644 --- a/composer.lock +++ b/composer.lock @@ -275,16 +275,16 @@ }, { "name": "pocketmine/bedrock-protocol", - "version": "9.0.0+bedrock-1.18.30", + "version": "9.0.1+bedrock-1.18.30", "source": { "type": "git", "url": "https://github.com/pmmp/BedrockProtocol.git", - "reference": "76cf00af0070dbb3f63a3e7fe74039d011a5475e" + "reference": "9d3cc87c4d26c002dd42aa9af20c0cd47a72018e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/BedrockProtocol/zipball/76cf00af0070dbb3f63a3e7fe74039d011a5475e", - "reference": "76cf00af0070dbb3f63a3e7fe74039d011a5475e", + "url": "https://api.github.com/repos/pmmp/BedrockProtocol/zipball/9d3cc87c4d26c002dd42aa9af20c0cd47a72018e", + "reference": "9d3cc87c4d26c002dd42aa9af20c0cd47a72018e", "shasum": "" }, "require": { @@ -298,7 +298,7 @@ "ramsey/uuid": "^4.1" }, "require-dev": { - "phpstan/phpstan": "1.5.4", + "phpstan/phpstan": "1.5.7", "phpstan/phpstan-phpunit": "^1.0.0", "phpstan/phpstan-strict-rules": "^1.0.0", "phpunit/phpunit": "^9.5" @@ -316,9 +316,9 @@ "description": "An implementation of the Minecraft: Bedrock Edition protocol in PHP", "support": { "issues": "https://github.com/pmmp/BedrockProtocol/issues", - "source": "https://github.com/pmmp/BedrockProtocol/tree/9.0.0+bedrock-1.18.30" + "source": "https://github.com/pmmp/BedrockProtocol/tree/9.0.1+bedrock-1.18.30" }, - "time": "2022-04-20T12:44:11+00:00" + "time": "2022-04-23T14:48:16+00:00" }, { "name": "pocketmine/binaryutils", From f7dce4af8802ce28a8286e1c8002af19cf986c62 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 23 Apr 2022 16:03:14 +0100 Subject: [PATCH 06/29] Release 4.3.1 --- changelogs/4.3.md | 7 +++++++ src/VersionInfo.php | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/changelogs/4.3.md b/changelogs/4.3.md index 6faf3a229..b3e7bfbab 100644 --- a/changelogs/4.3.md +++ b/changelogs/4.3.md @@ -12,3 +12,10 @@ Released 20th April 2022. ## General - Added support for Minecraft: Bedrock Edition 1.18.30. - Removed support for older versions. + +# 4.3.1 +Released 23rd April 2022. + +## Fixes +- Updated BedrockProtocol dependency to fix incorrect command argument types. +- Creative players no longer die in the void. diff --git a/src/VersionInfo.php b/src/VersionInfo.php index c9db21a7e..824a0b068 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -32,7 +32,7 @@ use function str_repeat; final class VersionInfo{ public const NAME = "PocketMine-MP"; public const BASE_VERSION = "4.3.1"; - public const IS_DEVELOPMENT_BUILD = true; + public const IS_DEVELOPMENT_BUILD = false; public const BUILD_CHANNEL = "stable"; private function __construct(){ From a58551af5bb6bf65b62ddb03063530b48dc0a7bf Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 23 Apr 2022 16:03:15 +0100 Subject: [PATCH 07/29] 4.3.2 is next --- src/VersionInfo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VersionInfo.php b/src/VersionInfo.php index 824a0b068..086171251 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -31,8 +31,8 @@ use function str_repeat; final class VersionInfo{ public const NAME = "PocketMine-MP"; - public const BASE_VERSION = "4.3.1"; - public const IS_DEVELOPMENT_BUILD = false; + public const BASE_VERSION = "4.3.2"; + public const IS_DEVELOPMENT_BUILD = true; public const BUILD_CHANNEL = "stable"; private function __construct(){ From 223893fd5c10916daf4514896ebe0c6da26840f4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 24 Apr 2022 21:56:49 +0100 Subject: [PATCH 08/29] PlayerChangeSkinEvent: remove obsolete doc comment --- src/event/player/PlayerChangeSkinEvent.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/event/player/PlayerChangeSkinEvent.php b/src/event/player/PlayerChangeSkinEvent.php index 51fde74a3..69852b624 100644 --- a/src/event/player/PlayerChangeSkinEvent.php +++ b/src/event/player/PlayerChangeSkinEvent.php @@ -53,9 +53,6 @@ class PlayerChangeSkinEvent extends PlayerEvent implements Cancellable{ return $this->newSkin; } - /** - * @throws \InvalidArgumentException if the specified skin is not valid - */ public function setNewSkin(Skin $skin) : void{ $this->newSkin = $skin; } From c8a7a53d702cc74e36287748c6e8bbafb7a0a6a7 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 25 Apr 2022 00:06:26 +0100 Subject: [PATCH 09/29] event: modernize property declarations where possible only private fields are modified; protected ones can't be changed in case someone extended the classes --- src/event/block/BaseBlockChangeEvent.php | 8 +++--- src/event/block/BlockBurnEvent.php | 9 +++--- src/event/block/BlockSpreadEvent.php | 9 +++--- src/event/block/BlockTeleportEvent.php | 9 +++--- src/event/block/SignChangeEvent.php | 18 ++++-------- src/event/block/StructureGrowEvent.php | 11 ++++---- src/event/entity/EntityBlockChangeEvent.php | 13 ++++----- src/event/entity/EntityDamageByBlockEvent.php | 5 +--- .../entity/EntityDamageByChildEntityEvent.php | 3 +- .../entity/EntityDamageByEntityEvent.php | 8 ++---- src/event/entity/EntityDamageEvent.php | 28 ++++++++----------- src/event/entity/EntityDeathEvent.php | 12 ++++---- src/event/entity/EntityEffectAddEvent.php | 6 +--- src/event/entity/EntityEffectEvent.php | 9 +++--- src/event/entity/EntityMotionEvent.php | 9 +++--- src/event/entity/EntityRegainHealthEvent.php | 15 ++++------ src/event/entity/EntityShootBowEvent.php | 16 +++++------ src/event/entity/EntityTeleportEvent.php | 13 ++++----- .../entity/EntityTrampleFarmlandEvent.php | 9 +++--- src/event/entity/ExplosionPrimeEvent.php | 4 +-- src/event/entity/ProjectileHitBlockEvent.php | 10 +++---- src/event/entity/ProjectileHitEntityEvent.php | 10 +++---- src/event/entity/ProjectileHitEvent.php | 9 +++--- src/event/inventory/CraftItemEvent.php | 25 +++++------------ src/event/inventory/FurnaceBurnEvent.php | 18 ++++-------- src/event/inventory/FurnaceSmeltEvent.php | 15 ++++------ src/event/inventory/InventoryCloseEvent.php | 9 +++--- src/event/inventory/InventoryOpenEvent.php | 9 +++--- .../inventory/InventoryTransactionEvent.php | 7 +---- src/event/player/PlayerBedEnterEvent.php | 9 +++--- src/event/player/PlayerBedLeaveEvent.php | 9 +++--- src/event/player/PlayerBlockPickEvent.php | 13 ++++----- src/event/player/PlayerBucketEvent.php | 25 ++++++----------- src/event/player/PlayerChangeSkinEvent.php | 13 ++++----- src/event/player/PlayerCreationEvent.php | 21 ++++---------- src/event/player/PlayerDataSaveEvent.php | 9 +++--- src/event/player/PlayerDeathEvent.php | 6 ++-- .../player/PlayerDisplayNameChangeEvent.php | 13 ++++----- src/event/player/PlayerDropItemEvent.php | 9 +++--- .../player/PlayerDuplicateLoginEvent.php | 15 ++++------ src/event/player/PlayerEditBookEvent.php | 21 +++++--------- src/event/player/PlayerExhaustEvent.php | 13 ++++----- .../player/PlayerExperienceChangeEvent.php | 21 +++++--------- src/event/player/PlayerItemConsumeEvent.php | 9 +++--- src/event/player/PlayerItemHeldEvent.php | 13 ++++----- src/event/player/PlayerItemUseEvent.php | 13 ++++----- src/event/player/PlayerMoveEvent.php | 13 ++++----- src/event/player/PlayerPreLoginEvent.php | 16 ++++------- src/event/plugin/PluginEvent.php | 7 +---- src/event/server/DataPacketReceiveEvent.php | 13 +++------ src/event/server/DataPacketSendEvent.php | 13 +++------ src/event/server/LowMemoryEvent.php | 23 +++++---------- src/event/server/QueryRegenerateEvent.php | 7 +---- src/event/server/UpdateNotifyEvent.php | 7 +---- src/event/world/ChunkEvent.php | 17 ++++------- src/event/world/ChunkLoadEvent.php | 12 ++++---- src/event/world/SpawnChangeEvent.php | 9 +++--- src/event/world/WorldEvent.php | 7 +---- 58 files changed, 258 insertions(+), 444 deletions(-) diff --git a/src/event/block/BaseBlockChangeEvent.php b/src/event/block/BaseBlockChangeEvent.php index 1c01e629c..224f5c123 100644 --- a/src/event/block/BaseBlockChangeEvent.php +++ b/src/event/block/BaseBlockChangeEvent.php @@ -33,11 +33,11 @@ use pocketmine\event\CancellableTrait; abstract class BaseBlockChangeEvent extends BlockEvent implements Cancellable{ use CancellableTrait; - private Block $newState; - - public function __construct(Block $block, Block $newState){ + public function __construct( + Block $block, + private Block $newState + ){ parent::__construct($block); - $this->newState = $newState; } public function getNewState() : Block{ diff --git a/src/event/block/BlockBurnEvent.php b/src/event/block/BlockBurnEvent.php index 96ddb6234..b3a554e72 100644 --- a/src/event/block/BlockBurnEvent.php +++ b/src/event/block/BlockBurnEvent.php @@ -33,12 +33,11 @@ use pocketmine\event\CancellableTrait; class BlockBurnEvent extends BlockEvent implements Cancellable{ use CancellableTrait; - /** @var Block */ - private $causingBlock; - - public function __construct(Block $block, Block $causingBlock){ + public function __construct( + Block $block, + private Block $causingBlock + ){ parent::__construct($block); - $this->causingBlock = $causingBlock; } /** diff --git a/src/event/block/BlockSpreadEvent.php b/src/event/block/BlockSpreadEvent.php index bd2517d19..34f9585a1 100644 --- a/src/event/block/BlockSpreadEvent.php +++ b/src/event/block/BlockSpreadEvent.php @@ -29,12 +29,13 @@ use pocketmine\block\Block; * Called when a block spreads to another block, such as grass spreading to nearby dirt blocks. */ class BlockSpreadEvent extends BaseBlockChangeEvent{ - /** @var Block */ - private $source; - public function __construct(Block $block, Block $source, Block $newState){ + public function __construct( + Block $block, + private Block $source, + Block $newState + ){ parent::__construct($block, $newState); - $this->source = $source; } public function getSource() : Block{ diff --git a/src/event/block/BlockTeleportEvent.php b/src/event/block/BlockTeleportEvent.php index d20de90e1..38afae448 100644 --- a/src/event/block/BlockTeleportEvent.php +++ b/src/event/block/BlockTeleportEvent.php @@ -32,12 +32,11 @@ use pocketmine\utils\Utils; class BlockTeleportEvent extends BlockEvent implements Cancellable{ use CancellableTrait; - /** @var Vector3 */ - private $to; - - public function __construct(Block $block, Vector3 $to){ + public function __construct( + Block $block, + private Vector3 $to + ){ parent::__construct($block); - $this->to = $to; } public function getTo() : Vector3{ diff --git a/src/event/block/SignChangeEvent.php b/src/event/block/SignChangeEvent.php index 4864eb752..9f87c585c 100644 --- a/src/event/block/SignChangeEvent.php +++ b/src/event/block/SignChangeEvent.php @@ -35,20 +35,12 @@ use pocketmine\player\Player; class SignChangeEvent extends BlockEvent implements Cancellable{ use CancellableTrait; - /** @var BaseSign */ - private $sign; - - /** @var Player */ - private $player; - - /** @var SignText */ - private $text; - - public function __construct(BaseSign $sign, Player $player, SignText $text){ + public function __construct( + private BaseSign $sign, + private Player $player, + private SignText $text + ){ parent::__construct($sign); - $this->sign = $sign; - $this->player = $player; - $this->text = $text; } public function getSign() : BaseSign{ diff --git a/src/event/block/StructureGrowEvent.php b/src/event/block/StructureGrowEvent.php index 6dc462d7c..f0adfba90 100644 --- a/src/event/block/StructureGrowEvent.php +++ b/src/event/block/StructureGrowEvent.php @@ -17,13 +17,12 @@ use pocketmine\world\BlockTransaction; class StructureGrowEvent extends BlockEvent implements Cancellable{ use CancellableTrait; - private BlockTransaction $transaction; - private ?Player $player; - - public function __construct(Block $block, BlockTransaction $transaction, ?Player $player){ + public function __construct( + Block $block, + private BlockTransaction $transaction, + private ?Player $player + ){ parent::__construct($block); - $this->transaction = $transaction; - $this->player = $player; } public function getTransaction() : BlockTransaction{ diff --git a/src/event/entity/EntityBlockChangeEvent.php b/src/event/entity/EntityBlockChangeEvent.php index f73da94ec..7f5d59e92 100644 --- a/src/event/entity/EntityBlockChangeEvent.php +++ b/src/event/entity/EntityBlockChangeEvent.php @@ -35,15 +35,12 @@ use pocketmine\event\CancellableTrait; class EntityBlockChangeEvent extends EntityEvent implements Cancellable{ use CancellableTrait; - /** @var Block */ - private $from; - /** @var Block */ - private $to; - - public function __construct(Entity $entity, Block $from, Block $to){ + public function __construct( + Entity $entity, + private Block $from, + private Block $to + ){ $this->entity = $entity; - $this->from = $from; - $this->to = $to; } public function getBlock() : Block{ diff --git a/src/event/entity/EntityDamageByBlockEvent.php b/src/event/entity/EntityDamageByBlockEvent.php index d6699ea13..92ec5f6e8 100644 --- a/src/event/entity/EntityDamageByBlockEvent.php +++ b/src/event/entity/EntityDamageByBlockEvent.php @@ -30,14 +30,11 @@ use pocketmine\entity\Entity; * Called when an entity takes damage from a block. */ class EntityDamageByBlockEvent extends EntityDamageEvent{ - /** @var Block */ - private $damager; /** * @param float[] $modifiers */ - public function __construct(Block $damager, Entity $entity, int $cause, float $damage, array $modifiers = []){ - $this->damager = $damager; + public function __construct(private Block $damager, Entity $entity, int $cause, float $damage, array $modifiers = []){ parent::__construct($entity, $cause, $damage, $modifiers); } diff --git a/src/event/entity/EntityDamageByChildEntityEvent.php b/src/event/entity/EntityDamageByChildEntityEvent.php index e3e28ab0d..10c3b6204 100644 --- a/src/event/entity/EntityDamageByChildEntityEvent.php +++ b/src/event/entity/EntityDamageByChildEntityEvent.php @@ -29,8 +29,7 @@ use pocketmine\entity\Entity; * Called when an entity takes damage from an entity sourced from another entity, for example being hit by a snowball thrown by a Player. */ class EntityDamageByChildEntityEvent extends EntityDamageByEntityEvent{ - /** @var int */ - private $childEntityEid; + private int $childEntityEid; /** * @param float[] $modifiers diff --git a/src/event/entity/EntityDamageByEntityEvent.php b/src/event/entity/EntityDamageByEntityEvent.php index 90d487c70..84a0ed332 100644 --- a/src/event/entity/EntityDamageByEntityEvent.php +++ b/src/event/entity/EntityDamageByEntityEvent.php @@ -31,17 +31,13 @@ use pocketmine\entity\Living; * Called when an entity takes damage from another entity. */ class EntityDamageByEntityEvent extends EntityDamageEvent{ - /** @var int */ - private $damagerEntityId; - /** @var float */ - private $knockBack; + private int $damagerEntityId; /** * @param float[] $modifiers */ - public function __construct(Entity $damager, Entity $entity, int $cause, float $damage, array $modifiers = [], float $knockBack = 0.4){ + public function __construct(Entity $damager, Entity $entity, int $cause, float $damage, array $modifiers = [], private float $knockBack = 0.4){ $this->damagerEntityId = $damager->getId(); - $this->knockBack = $knockBack; parent::__construct($entity, $cause, $damage, $modifiers); $this->addAttackerModifiers($damager); } diff --git a/src/event/entity/EntityDamageEvent.php b/src/event/entity/EntityDamageEvent.php index 79775e489..1f79d1ae1 100644 --- a/src/event/entity/EntityDamageEvent.php +++ b/src/event/entity/EntityDamageEvent.php @@ -64,31 +64,25 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{ public const CAUSE_CUSTOM = 14; public const CAUSE_STARVATION = 15; - /** @var int */ - private $cause; - /** @var float */ - private $baseDamage; - /** @var float */ - private $originalBase; + private float $baseDamage; + private float $originalBase; /** @var float[] */ - private $modifiers; - /** @var float[] */ - private $originals; - - /** @var int */ - private $attackCooldown = 10; + private array $originals; + private int $attackCooldown = 10; /** * @param float[] $modifiers */ - public function __construct(Entity $entity, int $cause, float $damage, array $modifiers = []){ + public function __construct( + Entity $entity, + private int $cause, + float $damage, + private array $modifiers = [] + ){ $this->entity = $entity; - $this->cause = $cause; $this->baseDamage = $this->originalBase = $damage; - - $this->modifiers = $modifiers; - $this->originals = $this->modifiers; + $this->originals = $modifiers; } public function getCause() : int{ diff --git a/src/event/entity/EntityDeathEvent.php b/src/event/entity/EntityDeathEvent.php index c9114d0b7..216100865 100644 --- a/src/event/entity/EntityDeathEvent.php +++ b/src/event/entity/EntityDeathEvent.php @@ -31,18 +31,16 @@ use pocketmine\utils\Utils; * @phpstan-extends EntityEvent */ class EntityDeathEvent extends EntityEvent{ - /** @var Item[] */ - private $drops = []; - /** @var int */ - private $xp; /** * @param Item[] $drops */ - public function __construct(Living $entity, array $drops = [], int $xp = 0){ + public function __construct( + Living $entity, + private array $drops = [], + private int $xp = 0 + ){ $this->entity = $entity; - $this->drops = $drops; - $this->xp = $xp; } /** diff --git a/src/event/entity/EntityEffectAddEvent.php b/src/event/entity/EntityEffectAddEvent.php index 3061a399c..ff8e65984 100644 --- a/src/event/entity/EntityEffectAddEvent.php +++ b/src/event/entity/EntityEffectAddEvent.php @@ -30,12 +30,8 @@ use pocketmine\entity\Entity; * Called when an effect is added to an Entity. */ class EntityEffectAddEvent extends EntityEffectEvent{ - /** @var EffectInstance|null */ - private $oldEffect; - - public function __construct(Entity $entity, EffectInstance $effect, ?EffectInstance $oldEffect = null){ + public function __construct(Entity $entity, EffectInstance $effect, private ?EffectInstance $oldEffect = null){ parent::__construct($entity, $effect); - $this->oldEffect = $oldEffect; } /** diff --git a/src/event/entity/EntityEffectEvent.php b/src/event/entity/EntityEffectEvent.php index f93e06b72..ac7293d84 100644 --- a/src/event/entity/EntityEffectEvent.php +++ b/src/event/entity/EntityEffectEvent.php @@ -34,12 +34,11 @@ use pocketmine\event\CancellableTrait; class EntityEffectEvent extends EntityEvent implements Cancellable{ use CancellableTrait; - /** @var EffectInstance */ - private $effect; - - public function __construct(Entity $entity, EffectInstance $effect){ + public function __construct( + Entity $entity, + private EffectInstance $effect + ){ $this->entity = $entity; - $this->effect = $effect; } public function getEffect() : EffectInstance{ diff --git a/src/event/entity/EntityMotionEvent.php b/src/event/entity/EntityMotionEvent.php index dc90e2b96..9fca7c34f 100644 --- a/src/event/entity/EntityMotionEvent.php +++ b/src/event/entity/EntityMotionEvent.php @@ -34,12 +34,11 @@ use pocketmine\math\Vector3; class EntityMotionEvent extends EntityEvent implements Cancellable{ use CancellableTrait; - /** @var Vector3 */ - private $mot; - - public function __construct(Entity $entity, Vector3 $mot){ + public function __construct( + Entity $entity, + private Vector3 $mot + ){ $this->entity = $entity; - $this->mot = $mot; } public function getVector() : Vector3{ diff --git a/src/event/entity/EntityRegainHealthEvent.php b/src/event/entity/EntityRegainHealthEvent.php index cb37ee612..4d8d8b646 100644 --- a/src/event/entity/EntityRegainHealthEvent.php +++ b/src/event/entity/EntityRegainHealthEvent.php @@ -39,15 +39,12 @@ class EntityRegainHealthEvent extends EntityEvent implements Cancellable{ public const CAUSE_CUSTOM = 3; public const CAUSE_SATURATION = 4; - /** @var float */ - private $amount; - /** @var int */ - private $reason; - - public function __construct(Entity $entity, float $amount, int $regainReason){ + public function __construct( + Entity $entity, + private float $amount, + private int $regainReason + ){ $this->entity = $entity; - $this->amount = $amount; - $this->reason = $regainReason; } public function getAmount() : float{ @@ -62,6 +59,6 @@ class EntityRegainHealthEvent extends EntityEvent implements Cancellable{ * Returns one of the CAUSE_* constants to indicate why this regeneration occurred. */ public function getRegainReason() : int{ - return $this->reason; + return $this->regainReason; } } diff --git a/src/event/entity/EntityShootBowEvent.php b/src/event/entity/EntityShootBowEvent.php index 5a871f282..cf01c56cd 100644 --- a/src/event/entity/EntityShootBowEvent.php +++ b/src/event/entity/EntityShootBowEvent.php @@ -37,18 +37,16 @@ use function count; class EntityShootBowEvent extends EntityEvent implements Cancellable{ use CancellableTrait; - /** @var Item */ - private $bow; - /** @var Entity */ - private $projectile; - /** @var float */ - private $force; + private Entity $projectile; - public function __construct(Living $shooter, Item $bow, Projectile $projectile, float $force){ + public function __construct( + Living $shooter, + private Item $bow, + Projectile $projectile, + private float $force + ){ $this->entity = $shooter; - $this->bow = $bow; $this->projectile = $projectile; - $this->force = $force; } /** diff --git a/src/event/entity/EntityTeleportEvent.php b/src/event/entity/EntityTeleportEvent.php index a513b4686..4a4f91699 100644 --- a/src/event/entity/EntityTeleportEvent.php +++ b/src/event/entity/EntityTeleportEvent.php @@ -35,15 +35,12 @@ use pocketmine\world\Position; class EntityTeleportEvent extends EntityEvent implements Cancellable{ use CancellableTrait; - /** @var Position */ - private $from; - /** @var Position */ - private $to; - - public function __construct(Entity $entity, Position $from, Position $to){ + public function __construct( + Entity $entity, + private Position $from, + private Position $to + ){ $this->entity = $entity; - $this->from = $from; - $this->to = $to; } public function getFrom() : Position{ diff --git a/src/event/entity/EntityTrampleFarmlandEvent.php b/src/event/entity/EntityTrampleFarmlandEvent.php index feea85bfe..254bfb065 100644 --- a/src/event/entity/EntityTrampleFarmlandEvent.php +++ b/src/event/entity/EntityTrampleFarmlandEvent.php @@ -34,12 +34,11 @@ use pocketmine\event\CancellableTrait; class EntityTrampleFarmlandEvent extends EntityEvent implements Cancellable{ use CancellableTrait; - /** @var Block */ - private $block; - - public function __construct(Living $entity, Block $block){ + public function __construct( + Living $entity, + private Block $block + ){ $this->entity = $entity; - $this->block = $block; } public function getBlock() : Block{ diff --git a/src/event/entity/ExplosionPrimeEvent.php b/src/event/entity/ExplosionPrimeEvent.php index 68bec6fa4..4d9f21e54 100644 --- a/src/event/entity/ExplosionPrimeEvent.php +++ b/src/event/entity/ExplosionPrimeEvent.php @@ -36,13 +36,11 @@ class ExplosionPrimeEvent extends EntityEvent implements Cancellable{ /** @var float */ protected $force; - /** @var bool */ - private $blockBreaking; + private bool $blockBreaking = true; public function __construct(Entity $entity, float $force){ $this->entity = $entity; $this->force = $force; - $this->blockBreaking = true; } public function getForce() : float{ diff --git a/src/event/entity/ProjectileHitBlockEvent.php b/src/event/entity/ProjectileHitBlockEvent.php index d1929ed91..10d7e8278 100644 --- a/src/event/entity/ProjectileHitBlockEvent.php +++ b/src/event/entity/ProjectileHitBlockEvent.php @@ -28,12 +28,12 @@ use pocketmine\entity\projectile\Projectile; use pocketmine\math\RayTraceResult; class ProjectileHitBlockEvent extends ProjectileHitEvent{ - /** @var Block */ - private $blockHit; - - public function __construct(Projectile $entity, RayTraceResult $rayTraceResult, Block $blockHit){ + public function __construct( + Projectile $entity, + RayTraceResult $rayTraceResult, + private Block $blockHit + ){ parent::__construct($entity, $rayTraceResult); - $this->blockHit = $blockHit; } /** diff --git a/src/event/entity/ProjectileHitEntityEvent.php b/src/event/entity/ProjectileHitEntityEvent.php index 3fe8b42b4..05e7c0fc5 100644 --- a/src/event/entity/ProjectileHitEntityEvent.php +++ b/src/event/entity/ProjectileHitEntityEvent.php @@ -28,12 +28,12 @@ use pocketmine\entity\projectile\Projectile; use pocketmine\math\RayTraceResult; class ProjectileHitEntityEvent extends ProjectileHitEvent{ - /** @var Entity */ - private $entityHit; - - public function __construct(Projectile $entity, RayTraceResult $rayTraceResult, Entity $entityHit){ + public function __construct( + Projectile $entity, + RayTraceResult $rayTraceResult, + private Entity $entityHit + ){ parent::__construct($entity, $rayTraceResult); - $this->entityHit = $entityHit; } /** diff --git a/src/event/entity/ProjectileHitEvent.php b/src/event/entity/ProjectileHitEvent.php index 70230f3fa..d0a77e94b 100644 --- a/src/event/entity/ProjectileHitEvent.php +++ b/src/event/entity/ProjectileHitEvent.php @@ -31,12 +31,11 @@ use pocketmine\math\RayTraceResult; * @phpstan-extends EntityEvent */ abstract class ProjectileHitEvent extends EntityEvent{ - /** @var RayTraceResult */ - private $rayTraceResult; - - public function __construct(Projectile $entity, RayTraceResult $rayTraceResult){ + public function __construct( + Projectile $entity, + private RayTraceResult $rayTraceResult + ){ $this->entity = $entity; - $this->rayTraceResult = $rayTraceResult; } /** diff --git a/src/event/inventory/CraftItemEvent.php b/src/event/inventory/CraftItemEvent.php index 63773158a..eb475795e 100644 --- a/src/event/inventory/CraftItemEvent.php +++ b/src/event/inventory/CraftItemEvent.php @@ -34,28 +34,17 @@ use pocketmine\player\Player; class CraftItemEvent extends Event implements Cancellable{ use CancellableTrait; - /** @var CraftingTransaction */ - private $transaction; - /** @var CraftingRecipe */ - private $recipe; - /** @var int */ - private $repetitions; - /** @var Item[] */ - private $inputs; - /** @var Item[] */ - private $outputs; - /** * @param Item[] $inputs * @param Item[] $outputs */ - public function __construct(CraftingTransaction $transaction, CraftingRecipe $recipe, int $repetitions, array $inputs, array $outputs){ - $this->transaction = $transaction; - $this->recipe = $recipe; - $this->repetitions = $repetitions; - $this->inputs = $inputs; - $this->outputs = $outputs; - } + public function __construct( + private CraftingTransaction $transaction, + private CraftingRecipe $recipe, + private int $repetitions, + private array $inputs, + private array $outputs + ){} /** * Returns the inventory transaction involved in this crafting event. diff --git a/src/event/inventory/FurnaceBurnEvent.php b/src/event/inventory/FurnaceBurnEvent.php index d613c5d9e..6bda9f305 100644 --- a/src/event/inventory/FurnaceBurnEvent.php +++ b/src/event/inventory/FurnaceBurnEvent.php @@ -35,20 +35,14 @@ use pocketmine\item\Item; class FurnaceBurnEvent extends BlockEvent implements Cancellable{ use CancellableTrait; - /** @var Furnace */ - private $furnace; - /** @var Item */ - private $fuel; - /** @var int */ - private $burnTime; - /** @var bool */ - private $burning = true; + private bool $burning = true; - public function __construct(Furnace $furnace, Item $fuel, int $burnTime){ + public function __construct( + private Furnace $furnace, + private Item $fuel, + private int $burnTime + ){ parent::__construct($furnace->getBlock()); - $this->fuel = $fuel; - $this->burnTime = $burnTime; - $this->furnace = $furnace; } public function getFurnace() : Furnace{ diff --git a/src/event/inventory/FurnaceSmeltEvent.php b/src/event/inventory/FurnaceSmeltEvent.php index cb2b5d828..6d81f0d25 100644 --- a/src/event/inventory/FurnaceSmeltEvent.php +++ b/src/event/inventory/FurnaceSmeltEvent.php @@ -32,19 +32,14 @@ use pocketmine\item\Item; class FurnaceSmeltEvent extends BlockEvent implements Cancellable{ use CancellableTrait; - /** @var Furnace */ - private $furnace; - /** @var Item */ - private $source; - /** @var Item */ - private $result; - - public function __construct(Furnace $furnace, Item $source, Item $result){ + public function __construct( + private Furnace $furnace, + private Item $source, + private Item $result + ){ parent::__construct($furnace->getBlock()); $this->source = clone $source; $this->source->setCount(1); - $this->result = $result; - $this->furnace = $furnace; } public function getFurnace() : Furnace{ diff --git a/src/event/inventory/InventoryCloseEvent.php b/src/event/inventory/InventoryCloseEvent.php index 1ea65234d..aa782e88d 100644 --- a/src/event/inventory/InventoryCloseEvent.php +++ b/src/event/inventory/InventoryCloseEvent.php @@ -27,11 +27,10 @@ use pocketmine\inventory\Inventory; use pocketmine\player\Player; class InventoryCloseEvent extends InventoryEvent{ - /** @var Player */ - private $who; - - public function __construct(Inventory $inventory, Player $who){ - $this->who = $who; + public function __construct( + Inventory $inventory, + private Player $who + ){ parent::__construct($inventory); } diff --git a/src/event/inventory/InventoryOpenEvent.php b/src/event/inventory/InventoryOpenEvent.php index ee5c13eb5..f68d369e9 100644 --- a/src/event/inventory/InventoryOpenEvent.php +++ b/src/event/inventory/InventoryOpenEvent.php @@ -31,11 +31,10 @@ use pocketmine\player\Player; class InventoryOpenEvent extends InventoryEvent implements Cancellable{ use CancellableTrait; - /** @var Player */ - private $who; - - public function __construct(Inventory $inventory, Player $who){ - $this->who = $who; + public function __construct( + Inventory $inventory, + private Player $who + ){ parent::__construct($inventory); } diff --git a/src/event/inventory/InventoryTransactionEvent.php b/src/event/inventory/InventoryTransactionEvent.php index 7ec8c9023..c86c67b52 100644 --- a/src/event/inventory/InventoryTransactionEvent.php +++ b/src/event/inventory/InventoryTransactionEvent.php @@ -35,12 +35,7 @@ use pocketmine\inventory\transaction\InventoryTransaction; class InventoryTransactionEvent extends Event implements Cancellable{ use CancellableTrait; - /** @var InventoryTransaction */ - private $transaction; - - public function __construct(InventoryTransaction $transaction){ - $this->transaction = $transaction; - } + public function __construct(private InventoryTransaction $transaction){} public function getTransaction() : InventoryTransaction{ return $this->transaction; diff --git a/src/event/player/PlayerBedEnterEvent.php b/src/event/player/PlayerBedEnterEvent.php index a9e571c6f..7adaf6a60 100644 --- a/src/event/player/PlayerBedEnterEvent.php +++ b/src/event/player/PlayerBedEnterEvent.php @@ -31,12 +31,11 @@ use pocketmine\player\Player; class PlayerBedEnterEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var Block */ - private $bed; - - public function __construct(Player $player, Block $bed){ + public function __construct( + Player $player, + private Block $bed + ){ $this->player = $player; - $this->bed = $bed; } public function getBed() : Block{ diff --git a/src/event/player/PlayerBedLeaveEvent.php b/src/event/player/PlayerBedLeaveEvent.php index 7efe02673..80f0f2af9 100644 --- a/src/event/player/PlayerBedLeaveEvent.php +++ b/src/event/player/PlayerBedLeaveEvent.php @@ -27,12 +27,11 @@ use pocketmine\block\Block; use pocketmine\player\Player; class PlayerBedLeaveEvent extends PlayerEvent{ - /** @var Block */ - private $bed; - - public function __construct(Player $player, Block $bed){ + public function __construct( + Player $player, + private Block $bed + ){ $this->player = $player; - $this->bed = $bed; } public function getBed() : Block{ diff --git a/src/event/player/PlayerBlockPickEvent.php b/src/event/player/PlayerBlockPickEvent.php index c365cda16..88dccd5dd 100644 --- a/src/event/player/PlayerBlockPickEvent.php +++ b/src/event/player/PlayerBlockPickEvent.php @@ -35,15 +35,12 @@ use pocketmine\player\Player; class PlayerBlockPickEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var Block */ - private $blockClicked; - /** @var Item */ - private $resultItem; - - public function __construct(Player $player, Block $blockClicked, Item $resultItem){ + public function __construct( + Player $player, + private Block $blockClicked, + private Item $resultItem + ){ $this->player = $player; - $this->blockClicked = $blockClicked; - $this->resultItem = $resultItem; } public function getBlock() : Block{ diff --git a/src/event/player/PlayerBucketEvent.php b/src/event/player/PlayerBucketEvent.php index 3cea82242..5b580f9b4 100644 --- a/src/event/player/PlayerBucketEvent.php +++ b/src/event/player/PlayerBucketEvent.php @@ -35,21 +35,14 @@ use pocketmine\player\Player; abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var Block */ - private $blockClicked; - /** @var int */ - private $blockFace; - /** @var Item */ - private $bucket; - /** @var Item */ - private $item; - - public function __construct(Player $who, Block $blockClicked, int $blockFace, Item $bucket, Item $itemInHand){ + public function __construct( + Player $who, + private Block $blockClicked, + private int $blockFace, + private Item $bucket, + private Item $itemInHand + ){ $this->player = $who; - $this->blockClicked = $blockClicked; - $this->blockFace = $blockFace; - $this->item = $itemInHand; - $this->bucket = $bucket; } /** @@ -63,11 +56,11 @@ abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable{ * Returns the item in hand after the event */ public function getItem() : Item{ - return $this->item; + return $this->itemInHand; } public function setItem(Item $item) : void{ - $this->item = $item; + $this->itemInHand = $item; } public function getBlockClicked() : Block{ diff --git a/src/event/player/PlayerChangeSkinEvent.php b/src/event/player/PlayerChangeSkinEvent.php index 51fde74a3..2eed08522 100644 --- a/src/event/player/PlayerChangeSkinEvent.php +++ b/src/event/player/PlayerChangeSkinEvent.php @@ -34,15 +34,12 @@ use pocketmine\player\Player; class PlayerChangeSkinEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var Skin */ - private $oldSkin; - /** @var Skin */ - private $newSkin; - - public function __construct(Player $player, Skin $oldSkin, Skin $newSkin){ + public function __construct( + Player $player, + private Skin $oldSkin, + private Skin $newSkin + ){ $this->player = $player; - $this->oldSkin = $oldSkin; - $this->newSkin = $newSkin; } public function getOldSkin() : Skin{ diff --git a/src/event/player/PlayerCreationEvent.php b/src/event/player/PlayerCreationEvent.php index 013fcdb2a..d58bfd4c9 100644 --- a/src/event/player/PlayerCreationEvent.php +++ b/src/event/player/PlayerCreationEvent.php @@ -34,23 +34,12 @@ use function is_a; */ class PlayerCreationEvent extends Event{ - /** @var NetworkSession */ - private $session; + /** @phpstan-var class-string */ + private string $baseClass = Player::class; + /** @phpstan-var class-string */ + private string $playerClass = Player::class; - /** - * @var string - * @phpstan-var class-string - */ - private $baseClass = Player::class; - /** - * @var string - * @phpstan-var class-string - */ - private $playerClass = Player::class; - - public function __construct(NetworkSession $session){ - $this->session = $session; - } + public function __construct(private NetworkSession $session){} public function getNetworkSession() : NetworkSession{ return $this->session; diff --git a/src/event/player/PlayerDataSaveEvent.php b/src/event/player/PlayerDataSaveEvent.php index 70e744304..a848f5256 100644 --- a/src/event/player/PlayerDataSaveEvent.php +++ b/src/event/player/PlayerDataSaveEvent.php @@ -39,13 +39,14 @@ class PlayerDataSaveEvent extends Event implements Cancellable{ protected $data; /** @var string */ protected $playerName; - /** @var Player|null */ - private $player; - public function __construct(CompoundTag $nbt, string $playerName, ?Player $player){ + public function __construct( + CompoundTag $nbt, + string $playerName, + private ?Player $player + ){ $this->data = $nbt; $this->playerName = $playerName; - $this->player = $player; } /** diff --git a/src/event/player/PlayerDeathEvent.php b/src/event/player/PlayerDeathEvent.php index 6c44d3819..8eb6e6e6a 100644 --- a/src/event/player/PlayerDeathEvent.php +++ b/src/event/player/PlayerDeathEvent.php @@ -38,10 +38,8 @@ class PlayerDeathEvent extends EntityDeathEvent{ /** @var Player */ protected $player; - /** @var Translatable|string */ - private $deathMessage; - /** @var bool */ - private $keepInventory = false; + private Translatable|string $deathMessage; + private bool $keepInventory = false; /** * @param Item[] $drops diff --git a/src/event/player/PlayerDisplayNameChangeEvent.php b/src/event/player/PlayerDisplayNameChangeEvent.php index 8956ca2c4..5bcb90199 100644 --- a/src/event/player/PlayerDisplayNameChangeEvent.php +++ b/src/event/player/PlayerDisplayNameChangeEvent.php @@ -27,15 +27,12 @@ use pocketmine\player\Player; class PlayerDisplayNameChangeEvent extends PlayerEvent{ - /** @var string */ - private $oldName; - /** @var string */ - private $newName; - - public function __construct(Player $player, string $oldName, string $newName){ + public function __construct( + Player $player, + private string $oldName, + private string $newName + ){ $this->player = $player; - $this->oldName = $oldName; - $this->newName = $newName; } public function getOldName() : string{ diff --git a/src/event/player/PlayerDropItemEvent.php b/src/event/player/PlayerDropItemEvent.php index a97a6f5fa..efff2cdde 100644 --- a/src/event/player/PlayerDropItemEvent.php +++ b/src/event/player/PlayerDropItemEvent.php @@ -34,12 +34,11 @@ use pocketmine\player\Player; class PlayerDropItemEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var Item */ - private $drop; - - public function __construct(Player $player, Item $drop){ + public function __construct( + Player $player, + private Item $drop + ){ $this->player = $player; - $this->drop = $drop; } public function getItem() : Item{ diff --git a/src/event/player/PlayerDuplicateLoginEvent.php b/src/event/player/PlayerDuplicateLoginEvent.php index 92fc34547..f1bd30d25 100644 --- a/src/event/player/PlayerDuplicateLoginEvent.php +++ b/src/event/player/PlayerDuplicateLoginEvent.php @@ -35,17 +35,12 @@ use pocketmine\network\mcpe\NetworkSession; class PlayerDuplicateLoginEvent extends Event implements Cancellable{ use CancellableTrait; - /** @var NetworkSession */ - private $connectingSession; - /** @var NetworkSession */ - private $existingSession; - /** @var string */ - private $disconnectMessage = "Logged in from another location"; + private string $disconnectMessage = "Logged in from another location"; - public function __construct(NetworkSession $connectingSession, NetworkSession $existingSession){ - $this->connectingSession = $connectingSession; - $this->existingSession = $existingSession; - } + public function __construct( + private NetworkSession $connectingSession, + private NetworkSession $existingSession + ){} public function getConnectingSession() : NetworkSession{ return $this->connectingSession; diff --git a/src/event/player/PlayerEditBookEvent.php b/src/event/player/PlayerEditBookEvent.php index 9a60de137..ca73fc1f5 100644 --- a/src/event/player/PlayerEditBookEvent.php +++ b/src/event/player/PlayerEditBookEvent.php @@ -37,24 +37,17 @@ class PlayerEditBookEvent extends PlayerEvent implements Cancellable{ public const ACTION_SWAP_PAGES = 3; public const ACTION_SIGN_BOOK = 4; - /** @var WritableBookBase */ - private $oldBook; - /** @var int */ - private $action; - /** @var WritableBookBase */ - private $newBook; - /** @var int[] */ - private $modifiedPages; - /** * @param int[] $modifiedPages */ - public function __construct(Player $player, WritableBookBase $oldBook, WritableBookBase $newBook, int $action, array $modifiedPages){ + public function __construct( + Player $player, + private WritableBookBase $oldBook, + private WritableBookBase $newBook, + private int $action, + private array $modifiedPages + ){ $this->player = $player; - $this->oldBook = $oldBook; - $this->newBook = $newBook; - $this->action = $action; - $this->modifiedPages = $modifiedPages; } /** diff --git a/src/event/player/PlayerExhaustEvent.php b/src/event/player/PlayerExhaustEvent.php index 42408a7b2..95e331232 100644 --- a/src/event/player/PlayerExhaustEvent.php +++ b/src/event/player/PlayerExhaustEvent.php @@ -46,19 +46,16 @@ class PlayerExhaustEvent extends EntityEvent implements Cancellable{ public const CAUSE_SPRINT_JUMPING = 10; public const CAUSE_CUSTOM = 11; - /** @var float */ - private $amount; - /** @var int */ - private $cause; - /** @var Human */ protected $player; - public function __construct(Human $human, float $amount, int $cause){ + public function __construct( + Human $human, + private float $amount, + private int $cause + ){ $this->entity = $human; $this->player = $human; - $this->amount = $amount; - $this->cause = $cause; } /** diff --git a/src/event/player/PlayerExperienceChangeEvent.php b/src/event/player/PlayerExperienceChangeEvent.php index 0ca195bdc..b62f82899 100644 --- a/src/event/player/PlayerExperienceChangeEvent.php +++ b/src/event/player/PlayerExperienceChangeEvent.php @@ -37,22 +37,15 @@ class PlayerExperienceChangeEvent extends EntityEvent implements Cancellable{ /** @var Human */ protected $entity; - /** @var int */ - private $oldLevel; - /** @var float */ - private $oldProgress; - /** @var int|null */ - private $newLevel; - /** @var float|null */ - private $newProgress; - public function __construct(Human $player, int $oldLevel, float $oldProgress, ?int $newLevel, ?float $newProgress){ + public function __construct( + Human $player, + private int $oldLevel, + private float $oldProgress, + private ?int $newLevel, + private ?float $newProgress + ){ $this->entity = $player; - - $this->oldLevel = $oldLevel; - $this->oldProgress = $oldProgress; - $this->newLevel = $newLevel; - $this->newProgress = $newProgress; } public function getOldLevel() : int{ diff --git a/src/event/player/PlayerItemConsumeEvent.php b/src/event/player/PlayerItemConsumeEvent.php index 52bb5e243..2b63277d4 100644 --- a/src/event/player/PlayerItemConsumeEvent.php +++ b/src/event/player/PlayerItemConsumeEvent.php @@ -34,12 +34,11 @@ use pocketmine\player\Player; class PlayerItemConsumeEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var Item */ - private $item; - - public function __construct(Player $player, Item $item){ + public function __construct( + Player $player, + private Item $item + ){ $this->player = $player; - $this->item = $item; } public function getItem() : Item{ diff --git a/src/event/player/PlayerItemHeldEvent.php b/src/event/player/PlayerItemHeldEvent.php index 71f55fc53..76145b0ac 100644 --- a/src/event/player/PlayerItemHeldEvent.php +++ b/src/event/player/PlayerItemHeldEvent.php @@ -31,15 +31,12 @@ use pocketmine\player\Player; class PlayerItemHeldEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var Item */ - private $item; - /** @var int */ - private $hotbarSlot; - - public function __construct(Player $player, Item $item, int $hotbarSlot){ + public function __construct( + Player $player, + private Item $item, + private int $hotbarSlot + ){ $this->player = $player; - $this->item = $item; - $this->hotbarSlot = $hotbarSlot; } /** diff --git a/src/event/player/PlayerItemUseEvent.php b/src/event/player/PlayerItemUseEvent.php index b9216d528..594536f59 100644 --- a/src/event/player/PlayerItemUseEvent.php +++ b/src/event/player/PlayerItemUseEvent.php @@ -35,15 +35,12 @@ use pocketmine\player\Player; class PlayerItemUseEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var Item */ - private $item; - /** @var Vector3 */ - private $directionVector; - - public function __construct(Player $player, Item $item, Vector3 $directionVector){ + public function __construct( + Player $player, + private Item $item, + private Vector3 $directionVector + ){ $this->player = $player; - $this->item = $item; - $this->directionVector = $directionVector; } /** diff --git a/src/event/player/PlayerMoveEvent.php b/src/event/player/PlayerMoveEvent.php index 62b8a2843..6d405b5bc 100644 --- a/src/event/player/PlayerMoveEvent.php +++ b/src/event/player/PlayerMoveEvent.php @@ -32,15 +32,12 @@ use pocketmine\utils\Utils; class PlayerMoveEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; - /** @var Location */ - private $from; - /** @var Location */ - private $to; - - public function __construct(Player $player, Location $from, Location $to){ + public function __construct( + Player $player, + private Location $from, + private Location $to + ){ $this->player = $player; - $this->from = $from; - $this->to = $to; } public function getFrom() : Location{ diff --git a/src/event/player/PlayerPreLoginEvent.php b/src/event/player/PlayerPreLoginEvent.php index 78be4746e..b4a286779 100644 --- a/src/event/player/PlayerPreLoginEvent.php +++ b/src/event/player/PlayerPreLoginEvent.php @@ -52,22 +52,18 @@ class PlayerPreLoginEvent extends Event implements Cancellable{ self::KICK_REASON_BANNED ]; - /** @var PlayerInfo */ - private $playerInfo; - /** @var string */ - private $ip; - /** @var int */ - private $port; /** @var bool */ protected $authRequired; /** @var string[] reason const => associated message */ protected $kickReasons = []; - public function __construct(PlayerInfo $playerInfo, string $ip, int $port, bool $authRequired){ - $this->playerInfo = $playerInfo; - $this->ip = $ip; - $this->port = $port; + public function __construct( + private PlayerInfo $playerInfo, + private string $ip, + private int $port, + bool $authRequired + ){ $this->authRequired = $authRequired; } diff --git a/src/event/plugin/PluginEvent.php b/src/event/plugin/PluginEvent.php index 82faa0638..f41417575 100644 --- a/src/event/plugin/PluginEvent.php +++ b/src/event/plugin/PluginEvent.php @@ -30,12 +30,7 @@ use pocketmine\event\Event; use pocketmine\plugin\Plugin; abstract class PluginEvent extends Event{ - /** @var Plugin */ - private $plugin; - - public function __construct(Plugin $plugin){ - $this->plugin = $plugin; - } + public function __construct(private Plugin $plugin){} public function getPlugin() : Plugin{ return $this->plugin; diff --git a/src/event/server/DataPacketReceiveEvent.php b/src/event/server/DataPacketReceiveEvent.php index c3443d206..cfa118b33 100644 --- a/src/event/server/DataPacketReceiveEvent.php +++ b/src/event/server/DataPacketReceiveEvent.php @@ -31,15 +31,10 @@ use pocketmine\network\mcpe\protocol\ServerboundPacket; class DataPacketReceiveEvent extends ServerEvent implements Cancellable{ use CancellableTrait; - /** @var ServerboundPacket */ - private $packet; - /** @var NetworkSession */ - private $origin; - - public function __construct(NetworkSession $origin, ServerboundPacket $packet){ - $this->packet = $packet; - $this->origin = $origin; - } + public function __construct( + private NetworkSession $origin, + private ServerboundPacket $packet + ){} public function getPacket() : ServerboundPacket{ return $this->packet; diff --git a/src/event/server/DataPacketSendEvent.php b/src/event/server/DataPacketSendEvent.php index dac9ac819..b7492faf5 100644 --- a/src/event/server/DataPacketSendEvent.php +++ b/src/event/server/DataPacketSendEvent.php @@ -34,19 +34,14 @@ use pocketmine\network\mcpe\protocol\ClientboundPacket; class DataPacketSendEvent extends ServerEvent implements Cancellable{ use CancellableTrait; - /** @var NetworkSession[] */ - private $targets; - /** @var ClientboundPacket[] */ - private $packets; - /** * @param NetworkSession[] $targets * @param ClientboundPacket[] $packets */ - public function __construct(array $targets, array $packets){ - $this->targets = $targets; - $this->packets = $packets; - } + public function __construct( + private array $targets, + private array $packets + ){} /** * @return NetworkSession[] diff --git a/src/event/server/LowMemoryEvent.php b/src/event/server/LowMemoryEvent.php index 7c7a090a6..c333dc0a5 100644 --- a/src/event/server/LowMemoryEvent.php +++ b/src/event/server/LowMemoryEvent.php @@ -30,21 +30,12 @@ use pocketmine\utils\Process; * Plugins should free caches or other non-essential data. */ class LowMemoryEvent extends ServerEvent{ - /** @var int */ - private $memory; - /** @var int */ - private $memoryLimit; - /** @var int */ - private $triggerCount; - /** @var bool */ - private $global; - - public function __construct(int $memory, int $memoryLimit, bool $isGlobal = false, int $triggerCount = 0){ - $this->memory = $memory; - $this->memoryLimit = $memoryLimit; - $this->global = $isGlobal; - $this->triggerCount = $triggerCount; - } + public function __construct( + private int $memory, + private int $memoryLimit, + private bool $isGlobal = false, + private int $triggerCount = 0 + ){} /** * Returns the memory usage at the time of the event call (in bytes) @@ -68,7 +59,7 @@ class LowMemoryEvent extends ServerEvent{ } public function isGlobal() : bool{ - return $this->global; + return $this->isGlobal; } /** diff --git a/src/event/server/QueryRegenerateEvent.php b/src/event/server/QueryRegenerateEvent.php index 5bf879f94..8a3f41f7e 100644 --- a/src/event/server/QueryRegenerateEvent.php +++ b/src/event/server/QueryRegenerateEvent.php @@ -26,12 +26,7 @@ namespace pocketmine\event\server; use pocketmine\network\query\QueryInfo; class QueryRegenerateEvent extends ServerEvent{ - /** @var QueryInfo */ - private $queryInfo; - - public function __construct(QueryInfo $queryInfo){ - $this->queryInfo = $queryInfo; - } + public function __construct(private QueryInfo $queryInfo){} public function getQueryInfo() : QueryInfo{ return $this->queryInfo; diff --git a/src/event/server/UpdateNotifyEvent.php b/src/event/server/UpdateNotifyEvent.php index 843b2c60e..a4b40473e 100644 --- a/src/event/server/UpdateNotifyEvent.php +++ b/src/event/server/UpdateNotifyEvent.php @@ -30,12 +30,7 @@ use pocketmine\updater\UpdateChecker; * Plugins may use this event to perform actions when an update notification is received. */ class UpdateNotifyEvent extends ServerEvent{ - /** @var UpdateChecker */ - private $updater; - - public function __construct(UpdateChecker $updater){ - $this->updater = $updater; - } + public function __construct(private UpdateChecker $updater){} public function getUpdater() : UpdateChecker{ return $this->updater; diff --git a/src/event/world/ChunkEvent.php b/src/event/world/ChunkEvent.php index ebdc2be91..084a6ca9f 100644 --- a/src/event/world/ChunkEvent.php +++ b/src/event/world/ChunkEvent.php @@ -30,18 +30,13 @@ use pocketmine\world\World; * Chunk-related events */ abstract class ChunkEvent extends WorldEvent{ - /** @var Chunk */ - private $chunk; - /** @var int */ - private $chunkX; - /** @var int */ - private $chunkZ; - - public function __construct(World $world, int $chunkX, int $chunkZ, Chunk $chunk){ + public function __construct( + World $world, + private int $chunkX, + private int $chunkZ, + private Chunk $chunk + ){ parent::__construct($world); - $this->chunk = $chunk; - $this->chunkX = $chunkX; - $this->chunkZ = $chunkZ; } public function getChunk() : Chunk{ diff --git a/src/event/world/ChunkLoadEvent.php b/src/event/world/ChunkLoadEvent.php index f8f1ef776..3281b3641 100644 --- a/src/event/world/ChunkLoadEvent.php +++ b/src/event/world/ChunkLoadEvent.php @@ -30,12 +30,14 @@ use pocketmine\world\World; * Called when a Chunk is loaded */ class ChunkLoadEvent extends ChunkEvent{ - /** @var bool */ - private $newChunk; - - public function __construct(World $world, int $chunkX, int $chunkZ, Chunk $chunk, bool $newChunk){ + public function __construct( + World $world, + int $chunkX, + int $chunkZ, + Chunk $chunk, + private bool $newChunk + ){ parent::__construct($world, $chunkX, $chunkZ, $chunk); - $this->newChunk = $newChunk; } public function isNewChunk() : bool{ diff --git a/src/event/world/SpawnChangeEvent.php b/src/event/world/SpawnChangeEvent.php index dba959a64..8b84ea04f 100644 --- a/src/event/world/SpawnChangeEvent.php +++ b/src/event/world/SpawnChangeEvent.php @@ -31,12 +31,11 @@ use pocketmine\world\World; * The previous spawn is included */ class SpawnChangeEvent extends WorldEvent{ - /** @var Position */ - private $previousSpawn; - - public function __construct(World $world, Position $previousSpawn){ + public function __construct( + World $world, + private Position $previousSpawn + ){ parent::__construct($world); - $this->previousSpawn = $previousSpawn; } public function getPreviousSpawn() : Position{ diff --git a/src/event/world/WorldEvent.php b/src/event/world/WorldEvent.php index c842825ae..af8f4c6c9 100644 --- a/src/event/world/WorldEvent.php +++ b/src/event/world/WorldEvent.php @@ -30,12 +30,7 @@ use pocketmine\event\Event; use pocketmine\world\World; abstract class WorldEvent extends Event{ - /** @var World */ - private $world; - - public function __construct(World $world){ - $this->world = $world; - } + public function __construct(private World $world){} public function getWorld() : World{ return $this->world; From 9f5d4180c974fbe07a27d98b2899195d0940bc30 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 25 Apr 2022 12:46:01 +0100 Subject: [PATCH 10/29] Spawnable: remove dead code, deprecate isDirty() and setDirty() --- src/block/tile/Chest.php | 8 ++++---- src/block/tile/Spawnable.php | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/block/tile/Chest.php b/src/block/tile/Chest.php index 614d7f0cd..057aa1991 100644 --- a/src/block/tile/Chest.php +++ b/src/block/tile/Chest.php @@ -188,8 +188,8 @@ class Chest extends Spawnable implements Container, Nameable{ $this->createPair($tile); - $this->setDirty(); - $tile->setDirty(); + $this->clearSpawnCompoundCache(); + $tile->clearSpawnCompoundCache(); $this->checkPairing(); return true; @@ -211,12 +211,12 @@ class Chest extends Spawnable implements Container, Nameable{ $tile = $this->getPair(); $this->pairX = $this->pairZ = null; - $this->setDirty(); + $this->clearSpawnCompoundCache(); if($tile instanceof Chest){ $tile->pairX = $tile->pairZ = null; $tile->checkPairing(); - $tile->setDirty(); + $tile->clearSpawnCompoundCache(); } $this->checkPairing(); diff --git a/src/block/tile/Spawnable.php b/src/block/tile/Spawnable.php index 5b62f1980..5184159df 100644 --- a/src/block/tile/Spawnable.php +++ b/src/block/tile/Spawnable.php @@ -33,21 +33,23 @@ abstract class Spawnable extends Tile{ * @phpstan-var CacheableNbt<\pocketmine\nbt\tag\CompoundTag>|null */ private $spawnCompoundCache = null; - /** @var bool */ - private $dirty = true; //default dirty, until it's been spawned appropriately on the world /** - * Returns whether the tile needs to be respawned to viewers. + * @deprecated */ public function isDirty() : bool{ - return $this->dirty; + return $this->spawnCompoundCache === null; } + /** + * @deprecated + */ public function setDirty(bool $dirty = true) : void{ - if($dirty){ - $this->spawnCompoundCache = null; - } - $this->dirty = $dirty; + $this->clearSpawnCompoundCache(); + } + + public function clearSpawnCompoundCache() : void{ + $this->spawnCompoundCache = null; } /** From 09778e3f1be2d20a42dc2cffebdd3150d3c39914 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 25 Apr 2022 12:56:16 +0100 Subject: [PATCH 11/29] Fixed build failure --- src/block/Block.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/block/Block.php b/src/block/Block.php index ef2ba2b81..76376dde2 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -152,7 +152,7 @@ class Block{ $oldTile->close(); $oldTile = null; }elseif($oldTile instanceof Spawnable){ - $oldTile->setDirty(); //destroy old network cache + $oldTile->clearSpawnCompoundCache(); //destroy old network cache } } if($oldTile === null && $tileType !== null){ From 72cff0ee11825a05e8f7b149c933e3f9f9802790 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 25 Apr 2022 13:00:29 +0100 Subject: [PATCH 12/29] Modernize property declarations in pocketmine\block namespace --- src/block/BlockFactory.php | 10 ++-- src/block/inventory/DoubleChestInventory.php | 6 +-- src/block/tile/Banner.php | 5 +- src/block/tile/Beacon.php | 6 +-- src/block/tile/Bed.php | 4 +- src/block/tile/Chest.php | 6 +-- src/block/tile/FlowerPot.php | 3 +- src/block/tile/Furnace.php | 9 ++-- src/block/tile/Hopper.php | 7 +-- src/block/tile/ItemFrame.php | 9 ++-- src/block/tile/Jukebox.php | 3 +- src/block/tile/MonsterSpawner.php | 51 ++++++-------------- src/block/tile/Note.php | 3 +- src/block/tile/Skull.php | 6 +-- src/block/tile/Spawnable.php | 7 +-- src/block/tile/TileFactory.php | 4 +- src/block/utils/BannerPatternLayer.php | 12 ++--- src/block/utils/CoralType.php | 9 ++-- src/block/utils/DyeColor.php | 13 ++--- src/block/utils/RecordType.php | 14 +++--- src/block/utils/SignText.php | 2 +- src/block/utils/SkullType.php | 15 +++--- src/block/utils/TreeType.php | 15 +++--- 23 files changed, 80 insertions(+), 139 deletions(-) diff --git a/src/block/BlockFactory.php b/src/block/BlockFactory.php index 14d37d72d..3b0ca17db 100644 --- a/src/block/BlockFactory.php +++ b/src/block/BlockFactory.php @@ -74,7 +74,7 @@ class BlockFactory{ * @var \SplFixedArray|Block[] * @phpstan-var \SplFixedArray */ - private $fullList; + private \SplFixedArray $fullList; /** * @var \SplFixedArray|int[] @@ -86,22 +86,22 @@ class BlockFactory{ * @var \SplFixedArray|int[] * @phpstan-var \SplFixedArray */ - public $light; + public \SplFixedArray $light; /** * @var \SplFixedArray|int[] * @phpstan-var \SplFixedArray */ - public $lightFilter; + public \SplFixedArray $lightFilter; /** * @var \SplFixedArray|bool[] * @phpstan-var \SplFixedArray */ - public $blocksDirectSkyLight; + public \SplFixedArray $blocksDirectSkyLight; /** * @var \SplFixedArray|float[] * @phpstan-var \SplFixedArray */ - public $blastResistance; + public \SplFixedArray $blastResistance; public function __construct(){ $this->fullList = new \SplFixedArray(1024 << Block::INTERNAL_METADATA_BITS); diff --git a/src/block/inventory/DoubleChestInventory.php b/src/block/inventory/DoubleChestInventory.php index 9d99f1e2b..e09dfab35 100644 --- a/src/block/inventory/DoubleChestInventory.php +++ b/src/block/inventory/DoubleChestInventory.php @@ -33,10 +33,8 @@ use pocketmine\world\sound\Sound; class DoubleChestInventory extends BaseInventory implements BlockInventory, InventoryHolder{ use AnimatedBlockInventoryTrait; - /** @var ChestInventory */ - private $left; - /** @var ChestInventory */ - private $right; + private ChestInventory $left; + private ChestInventory $right; public function __construct(ChestInventory $left, ChestInventory $right){ $this->left = $left; diff --git a/src/block/tile/Banner.php b/src/block/tile/Banner.php index 4404a3971..4d2550f4d 100644 --- a/src/block/tile/Banner.php +++ b/src/block/tile/Banner.php @@ -44,14 +44,13 @@ class Banner extends Spawnable{ public const TAG_PATTERN_COLOR = "Color"; public const TAG_PATTERN_NAME = "Pattern"; - /** @var DyeColor */ - private $baseColor; + private DyeColor $baseColor; /** * @var BannerPatternLayer[] * @phpstan-var list */ - private $patterns = []; + private array $patterns = []; public function __construct(World $world, Vector3 $pos){ $this->baseColor = DyeColor::BLACK(); diff --git a/src/block/tile/Beacon.php b/src/block/tile/Beacon.php index 4d4b8cf6d..42c24cd38 100644 --- a/src/block/tile/Beacon.php +++ b/src/block/tile/Beacon.php @@ -29,10 +29,8 @@ final class Beacon extends Spawnable{ private const TAG_PRIMARY = "primary"; //TAG_Int private const TAG_SECONDARY = "secondary"; //TAG_Int - /** @var int */ - private $primaryEffect = 0; - /** @var int */ - private $secondaryEffect = 0; + private int $primaryEffect = 0; + private int $secondaryEffect = 0; protected function addAdditionalSpawnData(CompoundTag $nbt) : void{ $nbt->setInt(self::TAG_PRIMARY, $this->primaryEffect); diff --git a/src/block/tile/Bed.php b/src/block/tile/Bed.php index 77cca1ceb..49ac07202 100644 --- a/src/block/tile/Bed.php +++ b/src/block/tile/Bed.php @@ -32,8 +32,8 @@ use pocketmine\world\World; class Bed extends Spawnable{ public const TAG_COLOR = "color"; - /** @var DyeColor */ - private $color; + + private DyeColor $color; public function __construct(World $world, Vector3 $pos){ $this->color = DyeColor::RED(); diff --git a/src/block/tile/Chest.php b/src/block/tile/Chest.php index 057aa1991..1f49a2ddb 100644 --- a/src/block/tile/Chest.php +++ b/src/block/tile/Chest.php @@ -49,10 +49,8 @@ class Chest extends Spawnable implements Container, Nameable{ /** @var DoubleChestInventory|null */ protected $doubleInventory = null; - /** @var int|null */ - private $pairX; - /** @var int|null */ - private $pairZ; + private ?int $pairX = null; + private ?int $pairZ = null; public function __construct(World $world, Vector3 $pos){ parent::__construct($world, $pos); diff --git a/src/block/tile/FlowerPot.php b/src/block/tile/FlowerPot.php index 221453ae6..294e4fe41 100644 --- a/src/block/tile/FlowerPot.php +++ b/src/block/tile/FlowerPot.php @@ -38,8 +38,7 @@ class FlowerPot extends Spawnable{ private const TAG_ITEM = "item"; private const TAG_ITEM_DATA = "mData"; - /** @var Block|null */ - private $plant = null; + private ?Block $plant = null; public function readSaveData(CompoundTag $nbt) : void{ if(($itemIdTag = $nbt->getTag(self::TAG_ITEM)) instanceof ShortTag && ($itemMetaTag = $nbt->getTag(self::TAG_ITEM_DATA)) instanceof IntTag){ diff --git a/src/block/tile/Furnace.php b/src/block/tile/Furnace.php index 21b05f504..806c53a07 100644 --- a/src/block/tile/Furnace.php +++ b/src/block/tile/Furnace.php @@ -50,12 +50,9 @@ abstract class Furnace extends Spawnable implements Container, Nameable{ /** @var FurnaceInventory */ protected $inventory; - /** @var int */ - private $remainingFuelTime = 0; - /** @var int */ - private $cookTime = 0; - /** @var int */ - private $maxFuelTime = 0; + private int $remainingFuelTime = 0; + private int $cookTime = 0; + private int $maxFuelTime = 0; public function __construct(World $world, Vector3 $pos){ parent::__construct($world, $pos); diff --git a/src/block/tile/Hopper.php b/src/block/tile/Hopper.php index 9ebb429ef..c5fe6f167 100644 --- a/src/block/tile/Hopper.php +++ b/src/block/tile/Hopper.php @@ -35,11 +35,8 @@ class Hopper extends Spawnable implements Container, Nameable{ private const TAG_TRANSFER_COOLDOWN = "TransferCooldown"; - /** @var HopperInventory */ - private $inventory; - - /** @var int */ - private $transferCooldown = 0; + private HopperInventory $inventory; + private int $transferCooldown = 0; public function __construct(World $world, Vector3 $pos){ parent::__construct($world, $pos); diff --git a/src/block/tile/ItemFrame.php b/src/block/tile/ItemFrame.php index f4f679e7e..ecb93acc1 100644 --- a/src/block/tile/ItemFrame.php +++ b/src/block/tile/ItemFrame.php @@ -38,12 +38,9 @@ class ItemFrame extends Spawnable{ public const TAG_ITEM_DROP_CHANCE = "ItemDropChance"; public const TAG_ITEM = "Item"; - /** @var Item */ - private $item; - /** @var int */ - private $itemRotation = 0; - /** @var float */ - private $itemDropChance = 1.0; + private Item $item; + private int $itemRotation = 0; + private float $itemDropChance = 1.0; public function __construct(World $world, Vector3 $pos){ $this->item = VanillaItems::AIR(); diff --git a/src/block/tile/Jukebox.php b/src/block/tile/Jukebox.php index 35242ed8d..eb8041258 100644 --- a/src/block/tile/Jukebox.php +++ b/src/block/tile/Jukebox.php @@ -30,8 +30,7 @@ use pocketmine\nbt\tag\CompoundTag; class Jukebox extends Spawnable{ private const TAG_RECORD = "RecordItem"; //Item CompoundTag - /** @var Record|null */ - private $record = null; + private ?Record $record = null; public function getRecord() : ?Record{ return $this->record; diff --git a/src/block/tile/MonsterSpawner.php b/src/block/tile/MonsterSpawner.php index 8b6d0eeca..040d6a3ee 100644 --- a/src/block/tile/MonsterSpawner.php +++ b/src/block/tile/MonsterSpawner.php @@ -56,43 +56,24 @@ class MonsterSpawner extends Spawnable{ public const DEFAULT_SPAWN_RANGE = 4; //blocks public const DEFAULT_REQUIRED_PLAYER_RANGE = 16; - /** - * @var string - * TODO: replace this with a cached entity or something of that nature - */ - private $entityTypeId = ":"; - /** - * @var ListTag|null - * TODO: deserialize this properly and drop the NBT (PC and PE formats are different, just for fun) - */ - private $spawnPotentials = null; - /** - * @var CompoundTag|null - * TODO: deserialize this properly and drop the NBT (PC and PE formats are different, just for fun) - */ - private $spawnData = null; + /** TODO: replace this with a cached entity or something of that nature */ + private string $entityTypeId = ":"; + /** TODO: deserialize this properly and drop the NBT (PC and PE formats are different, just for fun) */ + private ?ListTag $spawnPotentials = null; + /** TODO: deserialize this properly and drop the NBT (PC and PE formats are different, just for fun) */ + private ?CompoundTag $spawnData = null; - /** @var float */ - private $displayEntityWidth = 1; - /** @var float */ - private $displayEntityHeight = 1; - /** @var float */ - private $displayEntityScale = 1; + private float $displayEntityWidth = 1.0; + private float $displayEntityHeight = 1.0; + private float $displayEntityScale = 1.0; - /** @var int */ - private $spawnDelay = self::DEFAULT_MIN_SPAWN_DELAY; - /** @var int */ - private $minSpawnDelay = self::DEFAULT_MIN_SPAWN_DELAY; - /** @var int */ - private $maxSpawnDelay = self::DEFAULT_MAX_SPAWN_DELAY; - /** @var int */ - private $spawnPerAttempt = 1; - /** @var int */ - private $maxNearbyEntities = self::DEFAULT_MAX_NEARBY_ENTITIES; - /** @var int */ - private $spawnRange = self::DEFAULT_SPAWN_RANGE; - /** @var int */ - private $requiredPlayerRange = self::DEFAULT_REQUIRED_PLAYER_RANGE; + private int $spawnDelay = self::DEFAULT_MIN_SPAWN_DELAY; + private int $minSpawnDelay = self::DEFAULT_MIN_SPAWN_DELAY; + private int $maxSpawnDelay = self::DEFAULT_MAX_SPAWN_DELAY; + private int $spawnPerAttempt = 1; + private int $maxNearbyEntities = self::DEFAULT_MAX_NEARBY_ENTITIES; + private int $spawnRange = self::DEFAULT_SPAWN_RANGE; + private int $requiredPlayerRange = self::DEFAULT_REQUIRED_PLAYER_RANGE; public function readSaveData(CompoundTag $nbt) : void{ if(($legacyIdTag = $nbt->getTag(self::TAG_LEGACY_ENTITY_TYPE_ID)) instanceof IntTag){ diff --git a/src/block/tile/Note.php b/src/block/tile/Note.php index 30c252593..bf597607c 100644 --- a/src/block/tile/Note.php +++ b/src/block/tile/Note.php @@ -30,8 +30,7 @@ use pocketmine\nbt\tag\CompoundTag; * @deprecated */ class Note extends Tile{ - /** @var int */ - private $pitch = 0; + private int $pitch = 0; public function readSaveData(CompoundTag $nbt) : void{ if(($pitch = $nbt->getByte("note", $this->pitch)) > BlockNote::MIN_PITCH && $pitch <= BlockNote::MAX_PITCH){ diff --git a/src/block/tile/Skull.php b/src/block/tile/Skull.php index 8ff40898d..30dd164c0 100644 --- a/src/block/tile/Skull.php +++ b/src/block/tile/Skull.php @@ -40,10 +40,8 @@ class Skull extends Spawnable{ private const TAG_MOUTH_MOVING = "MouthMoving"; //TAG_Byte private const TAG_MOUTH_TICK_COUNT = "MouthTickCount"; //TAG_Int - /** @var SkullType */ - private $skullType; - /** @var int */ - private $skullRotation = 0; + private SkullType $skullType; + private int $skullRotation = 0; public function __construct(World $world, Vector3 $pos){ $this->skullType = SkullType::SKELETON(); diff --git a/src/block/tile/Spawnable.php b/src/block/tile/Spawnable.php index 5184159df..b48f8a0f7 100644 --- a/src/block/tile/Spawnable.php +++ b/src/block/tile/Spawnable.php @@ -28,11 +28,8 @@ use pocketmine\network\mcpe\protocol\types\CacheableNbt; use function get_class; abstract class Spawnable extends Tile{ - /** - * @var CacheableNbt|null - * @phpstan-var CacheableNbt<\pocketmine\nbt\tag\CompoundTag>|null - */ - private $spawnCompoundCache = null; + /** @phpstan-var CacheableNbt<\pocketmine\nbt\tag\CompoundTag>|null */ + private ?CacheableNbt $spawnCompoundCache = null; /** * @deprecated diff --git a/src/block/tile/TileFactory.php b/src/block/tile/TileFactory.php index 10c09ad55..f2cc53045 100644 --- a/src/block/tile/TileFactory.php +++ b/src/block/tile/TileFactory.php @@ -42,12 +42,12 @@ final class TileFactory{ * @var string[] classes that extend Tile * @phpstan-var array> */ - private $knownTiles = []; + private array $knownTiles = []; /** * @var string[] * @phpstan-var array, string> */ - private $saveNames = []; + private array $saveNames = []; public function __construct(){ $this->register(Barrel::class, ["Barrel", "minecraft:barrel"]); diff --git a/src/block/utils/BannerPatternLayer.php b/src/block/utils/BannerPatternLayer.php index 8095102fc..00ba8caec 100644 --- a/src/block/utils/BannerPatternLayer.php +++ b/src/block/utils/BannerPatternLayer.php @@ -30,14 +30,10 @@ use pocketmine\block\BaseBanner; * @see BaseBanner */ class BannerPatternLayer{ - private BannerPatternType $type; - /** @var DyeColor */ - private $color; - - public function __construct(BannerPatternType $type, DyeColor $color){ - $this->type = $type; - $this->color = $color; - } + public function __construct( + private BannerPatternType $type, + private DyeColor $color + ){} public function getType() : BannerPatternType{ return $this->type; } diff --git a/src/block/utils/CoralType.php b/src/block/utils/CoralType.php index 07d94d7ea..2006d3799 100644 --- a/src/block/utils/CoralType.php +++ b/src/block/utils/CoralType.php @@ -42,9 +42,6 @@ final class CoralType{ __construct as Enum___construct; } - /** @var string */ - private $displayName; - protected static function setup() : void{ self::registerAll( new self("tube", "Tube"), @@ -55,9 +52,11 @@ final class CoralType{ ); } - private function __construct(string $name, string $displayName){ + private function __construct( + string $name, + private string $displayName + ){ $this->Enum___construct($name); - $this->displayName = $displayName; } public function getDisplayName() : string{ return $this->displayName; } diff --git a/src/block/utils/DyeColor.php b/src/block/utils/DyeColor.php index 91fe73fbf..a1bb941a1 100644 --- a/src/block/utils/DyeColor.php +++ b/src/block/utils/DyeColor.php @@ -75,15 +75,12 @@ final class DyeColor{ ); } - /** @var string */ - private $displayName; - /** @var Color */ - private $rgbValue; - - private function __construct(string $enumName, string $displayName, Color $rgbValue){ + private function __construct( + string $enumName, + private string $displayName, + private Color $rgbValue + ){ $this->Enum___construct($enumName); - $this->displayName = $displayName; - $this->rgbValue = $rgbValue; } public function getDisplayName() : string{ diff --git a/src/block/utils/RecordType.php b/src/block/utils/RecordType.php index e497d419c..e6692a511 100644 --- a/src/block/utils/RecordType.php +++ b/src/block/utils/RecordType.php @@ -70,15 +70,13 @@ final class RecordType{ ); } - /** @var string */ - private $soundName; - /** @var int */ - private $soundId; - - private function __construct(string $enumName, string $soundName, int $soundId, private Translatable $translatableName){ + private function __construct( + string $enumName, + private string $soundName, + private int $soundId, + private Translatable $translatableName + ){ $this->Enum___construct($enumName); - $this->soundName = $soundName; - $this->soundId = $soundId; } public function getSoundName() : string{ diff --git a/src/block/utils/SignText.php b/src/block/utils/SignText.php index 4c7eeeb02..dd7221ac2 100644 --- a/src/block/utils/SignText.php +++ b/src/block/utils/SignText.php @@ -36,7 +36,7 @@ class SignText{ public const LINE_COUNT = 4; /** @var string[] */ - private $lines; + private array $lines; /** * @param string[]|null $lines index-sensitive; omitting an index will leave it unchanged diff --git a/src/block/utils/SkullType.php b/src/block/utils/SkullType.php index 2bbb566dd..6ec6341c0 100644 --- a/src/block/utils/SkullType.php +++ b/src/block/utils/SkullType.php @@ -45,7 +45,7 @@ final class SkullType{ } /** @var SkullType[] */ - private static $numericIdMap = []; + private static array $numericIdMap = []; protected static function setup() : void{ self::registerAll( @@ -75,15 +75,12 @@ final class SkullType{ return self::$numericIdMap[$magicNumber]; } - /** @var string */ - private $displayName; - /** @var int */ - private $magicNumber; - - private function __construct(string $enumName, string $displayName, int $magicNumber){ + private function __construct( + string $enumName, + private string $displayName, + private int $magicNumber + ){ $this->Enum___construct($enumName); - $this->displayName = $displayName; - $this->magicNumber = $magicNumber; } public function getDisplayName() : string{ diff --git a/src/block/utils/TreeType.php b/src/block/utils/TreeType.php index 7667d144d..60e796db2 100644 --- a/src/block/utils/TreeType.php +++ b/src/block/utils/TreeType.php @@ -45,7 +45,7 @@ final class TreeType{ } /** @var TreeType[] */ - private static $numericIdMap = []; + private static array $numericIdMap = []; protected static function setup() : void{ self::registerAll( @@ -76,15 +76,12 @@ final class TreeType{ return self::$numericIdMap[$magicNumber]; } - /** @var string */ - private $displayName; - /** @var int */ - private $magicNumber; - - private function __construct(string $enumName, string $displayName, int $magicNumber){ + private function __construct( + string $enumName, + private string $displayName, + private int $magicNumber + ){ $this->Enum___construct($enumName); - $this->displayName = $displayName; - $this->magicNumber = $magicNumber; } public function getDisplayName() : string{ From dca457b1e0d63768fe37c7aafedeb88d3adde215 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 25 Apr 2022 13:09:14 +0100 Subject: [PATCH 13/29] Modernize property declarations in pocketmine\command namespace --- src/command/Command.php | 24 ++++++++---------------- src/command/FormattedCommandAlias.php | 2 +- src/command/PluginCommand.php | 3 +-- src/command/SimpleCommandMap.php | 6 +----- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/command/Command.php b/src/command/Command.php index 6b1d6ab33..51e3ef51c 100644 --- a/src/command/Command.php +++ b/src/command/Command.php @@ -40,23 +40,18 @@ use function str_replace; abstract class Command{ - /** @var string */ - private $name; + private string $name; - /** @var string */ - private $nextLabel; - - /** @var string */ - private $label; + private string $nextLabel; + private string $label; /** @var string[] */ - private $aliases = []; + private array $aliases = []; /** @var string[] */ - private $activeAliases = []; + private array $activeAliases = []; - /** @var CommandMap|null */ - private $commandMap = null; + private ?CommandMap $commandMap = null; /** @var Translatable|string */ protected $description = ""; @@ -64,11 +59,8 @@ abstract class Command{ /** @var Translatable|string */ protected $usageMessage; - /** @var string|null */ - private $permission = null; - - /** @var string|null */ - private $permissionMessage = null; + private ?string $permission = null; + private ?string $permissionMessage = null; /** @var TimingsHandler|null */ public $timings = null; diff --git a/src/command/FormattedCommandAlias.php b/src/command/FormattedCommandAlias.php index 968c10012..ca8908897 100644 --- a/src/command/FormattedCommandAlias.php +++ b/src/command/FormattedCommandAlias.php @@ -33,7 +33,7 @@ use function substr; class FormattedCommandAlias extends Command{ /** @var string[] */ - private $formatStrings = []; + private array $formatStrings = []; /** * @param string[] $formatStrings diff --git a/src/command/PluginCommand.php b/src/command/PluginCommand.php index 634978006..73e27a0f8 100644 --- a/src/command/PluginCommand.php +++ b/src/command/PluginCommand.php @@ -31,8 +31,7 @@ use pocketmine\plugin\PluginOwnedTrait; final class PluginCommand extends Command implements PluginOwned{ use PluginOwnedTrait; - /** @var CommandExecutor */ - private $executor; + private CommandExecutor $executor; public function __construct(string $name, Plugin $owner, CommandExecutor $executor){ parent::__construct($name); diff --git a/src/command/SimpleCommandMap.php b/src/command/SimpleCommandMap.php index 116f59c23..13d27c06f 100644 --- a/src/command/SimpleCommandMap.php +++ b/src/command/SimpleCommandMap.php @@ -84,11 +84,7 @@ class SimpleCommandMap implements CommandMap{ /** @var Command[] */ protected $knownCommands = []; - /** @var Server */ - private $server; - - public function __construct(Server $server){ - $this->server = $server; + public function __construct(private Server $server){ $this->setDefaultCommands(); } From b402df8b91188c2f7e2040483e52bc59f508424f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 25 Apr 2022 13:15:48 +0100 Subject: [PATCH 14/29] Modernize property declarations in pocketmine\crafting namespace --- src/crafting/CraftingGrid.php | 15 +++++---------- src/crafting/CraftingManager.php | 7 ++----- src/crafting/FurnaceRecipe.php | 15 ++++++--------- src/crafting/FurnaceRecipeManager.php | 7 ++----- src/crafting/ShapedRecipe.php | 12 +++++------- src/crafting/ShapelessRecipe.php | 4 ++-- 6 files changed, 22 insertions(+), 38 deletions(-) diff --git a/src/crafting/CraftingGrid.php b/src/crafting/CraftingGrid.php index b72392016..6050b5449 100644 --- a/src/crafting/CraftingGrid.php +++ b/src/crafting/CraftingGrid.php @@ -33,17 +33,12 @@ abstract class CraftingGrid extends SimpleInventory{ public const SIZE_SMALL = 2; public const SIZE_BIG = 3; - /** @var int */ - private $gridWidth; + private int $gridWidth; - /** @var int|null */ - private $startX; - /** @var int|null */ - private $xLen; - /** @var int|null */ - private $startY; - /** @var int|null */ - private $yLen; + private ?int $startX = null; + private ?int $xLen = null; + private ?int $startY = null; + private ?int $yLen = null; public function __construct(int $gridWidth){ $this->gridWidth = $gridWidth; diff --git a/src/crafting/CraftingManager.php b/src/crafting/CraftingManager.php index ba690c844..f9d28bf28 100644 --- a/src/crafting/CraftingManager.php +++ b/src/crafting/CraftingManager.php @@ -57,11 +57,8 @@ class CraftingManager{ */ protected $potionContainerChangeRecipes = []; - /** - * @var ObjectSet - * @phpstan-var ObjectSet<\Closure() : void> - */ - private $recipeRegisteredCallbacks; + /** @phpstan-var ObjectSet<\Closure() : void> */ + private ObjectSet $recipeRegisteredCallbacks; public function __construct(){ $this->recipeRegisteredCallbacks = new ObjectSet(); diff --git a/src/crafting/FurnaceRecipe.php b/src/crafting/FurnaceRecipe.php index 55a6104fe..89d414e27 100644 --- a/src/crafting/FurnaceRecipe.php +++ b/src/crafting/FurnaceRecipe.php @@ -27,14 +27,11 @@ use pocketmine\item\Item; class FurnaceRecipe{ - /** @var Item */ - private $output; - - /** @var Item */ - private $ingredient; - - public function __construct(Item $result, Item $ingredient){ - $this->output = clone $result; + public function __construct( + private Item $result, + private Item $ingredient + ){ + $this->result = clone $result; $this->ingredient = clone $ingredient; } @@ -43,6 +40,6 @@ class FurnaceRecipe{ } public function getResult() : Item{ - return clone $this->output; + return clone $this->result; } } diff --git a/src/crafting/FurnaceRecipeManager.php b/src/crafting/FurnaceRecipeManager.php index 15bdee2fe..1f16f4707 100644 --- a/src/crafting/FurnaceRecipeManager.php +++ b/src/crafting/FurnaceRecipeManager.php @@ -30,11 +30,8 @@ final class FurnaceRecipeManager{ /** @var FurnaceRecipe[] */ protected $furnaceRecipes = []; - /** - * @var ObjectSet - * @phpstan-var ObjectSet<\Closure(FurnaceRecipe) : void> - */ - private $recipeRegisteredCallbacks; + /** @phpstan-var ObjectSet<\Closure(FurnaceRecipe) : void> */ + private ObjectSet $recipeRegisteredCallbacks; public function __construct(){ $this->recipeRegisteredCallbacks = new ObjectSet(); diff --git a/src/crafting/ShapedRecipe.php b/src/crafting/ShapedRecipe.php index fc02224a9..984d17a91 100644 --- a/src/crafting/ShapedRecipe.php +++ b/src/crafting/ShapedRecipe.php @@ -34,16 +34,14 @@ use function strpos; class ShapedRecipe implements CraftingRecipe{ /** @var string[] */ - private $shape = []; + private array $shape = []; /** @var Item[] char => Item map */ - private $ingredientList = []; + private array $ingredientList = []; /** @var Item[] */ - private $results = []; + private array $results = []; - /** @var int */ - private $height; - /** @var int */ - private $width; + private int $height; + private int $width; /** * Constructs a ShapedRecipe instance. diff --git a/src/crafting/ShapelessRecipe.php b/src/crafting/ShapelessRecipe.php index 4ef3bfc1a..4e75369c0 100644 --- a/src/crafting/ShapelessRecipe.php +++ b/src/crafting/ShapelessRecipe.php @@ -29,9 +29,9 @@ use function count; class ShapelessRecipe implements CraftingRecipe{ /** @var Item[] */ - private $ingredients = []; + private array $ingredients = []; /** @var Item[] */ - private $results; + private array $results; /** * @param Item[] $ingredients No more than 9 total. This applies to sum of item stack counts, not count of array. From de12b701ac7f0350eef777d9ef51dd14def9bb9b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 13:07:58 +0100 Subject: [PATCH 15/29] Modernize type declarations in src/world/format --- src/world/format/BiomeArray.php | 4 +-- src/world/format/Chunk.php | 3 +-- src/world/format/HeightArray.php | 2 +- src/world/format/SubChunk.php | 20 +++++--------- src/world/format/io/FormatConverter.php | 27 +++++++------------ .../format/io/region/RegionGarbageMap.php | 5 ++-- .../io/region/RegionLocationTableEntry.php | 10 +++---- 7 files changed, 24 insertions(+), 47 deletions(-) diff --git a/src/world/format/BiomeArray.php b/src/world/format/BiomeArray.php index ed45e88fc..79091d7ea 100644 --- a/src/world/format/BiomeArray.php +++ b/src/world/format/BiomeArray.php @@ -29,9 +29,7 @@ use function str_repeat; use function strlen; final class BiomeArray{ - - /** @var string */ - private $payload; + private string $payload; /** * @param string $payload ZZZZXXXX key bits diff --git a/src/world/format/Chunk.php b/src/world/format/Chunk.php index 6a8dad59c..b3265cbdb 100644 --- a/src/world/format/Chunk.php +++ b/src/world/format/Chunk.php @@ -43,8 +43,7 @@ class Chunk{ public const COORD_BIT_SIZE = SubChunk::COORD_BIT_SIZE; public const COORD_MASK = SubChunk::COORD_MASK; - /** @var int */ - private $terrainDirtyFlags = 0; + private int $terrainDirtyFlags = 0; /** @var bool|null */ protected $lightPopulated = false; diff --git a/src/world/format/HeightArray.php b/src/world/format/HeightArray.php index 88df7299b..faf9e19be 100644 --- a/src/world/format/HeightArray.php +++ b/src/world/format/HeightArray.php @@ -32,7 +32,7 @@ final class HeightArray{ * @var \SplFixedArray|int[] * @phpstan-var \SplFixedArray */ - private $array; + private \SplFixedArray $array; /** * @param int[] $values ZZZZXXXX key bit order diff --git a/src/world/format/SubChunk.php b/src/world/format/SubChunk.php index ea20b917f..81a749949 100644 --- a/src/world/format/SubChunk.php +++ b/src/world/format/SubChunk.php @@ -32,27 +32,21 @@ class SubChunk{ public const COORD_MASK = ~(~0 << self::COORD_BIT_SIZE); public const EDGE_LENGTH = 1 << self::COORD_BIT_SIZE; - /** @var int */ - private $emptyBlockId; /** @var PalettedBlockArray[] */ - private $blockLayers; - - /** @var LightArray|null */ - private $blockLight; - /** @var LightArray|null */ - private $skyLight; + private array $blockLayers; /** * SubChunk constructor. * * @param PalettedBlockArray[] $blocks */ - public function __construct(int $emptyBlockId, array $blocks, ?LightArray $skyLight = null, ?LightArray $blockLight = null){ - $this->emptyBlockId = $emptyBlockId; + public function __construct( + private int $emptyBlockId, + array $blocks, //TODO: promote this once we can break BC again (needs a name change) + private ?LightArray $skyLight = null, + private ?LightArray $blockLight = null + ){ $this->blockLayers = $blocks; - - $this->skyLight = $skyLight; - $this->blockLight = $blockLight; } /** diff --git a/src/world/format/io/FormatConverter.php b/src/world/format/io/FormatConverter.php index 2599415c4..b2c2b2afb 100644 --- a/src/world/format/io/FormatConverter.php +++ b/src/world/format/io/FormatConverter.php @@ -41,26 +41,17 @@ use function rtrim; use const DIRECTORY_SEPARATOR; class FormatConverter{ + private string $backupPath; + private \Logger $logger; - /** @var WorldProvider */ - private $oldProvider; - /** @var WritableWorldProviderManagerEntry */ - private $newProvider; - - /** @var string */ - private $backupPath; - - /** @var \Logger */ - private $logger; - - /** @var int */ - private $chunksPerProgressUpdate; - - public function __construct(WorldProvider $oldProvider, WritableWorldProviderManagerEntry $newProvider, string $backupPath, \Logger $logger, int $chunksPerProgressUpdate = 256){ - $this->oldProvider = $oldProvider; - $this->newProvider = $newProvider; + public function __construct( + private WorldProvider $oldProvider, + private WritableWorldProviderManagerEntry $newProvider, + string $backupPath, + \Logger $logger, + private int $chunksPerProgressUpdate = 256 + ){ $this->logger = new \PrefixedLogger($logger, "World Converter: " . $this->oldProvider->getWorldData()->getName()); - $this->chunksPerProgressUpdate = $chunksPerProgressUpdate; if(!file_exists($backupPath)){ @mkdir($backupPath, 0777, true); diff --git a/src/world/format/io/region/RegionGarbageMap.php b/src/world/format/io/region/RegionGarbageMap.php index 9b0373449..b07b2f111 100644 --- a/src/world/format/io/region/RegionGarbageMap.php +++ b/src/world/format/io/region/RegionGarbageMap.php @@ -32,9 +32,8 @@ use const SORT_NUMERIC; final class RegionGarbageMap{ /** @var RegionLocationTableEntry[] */ - private $entries = []; - /** @var bool */ - private $clean = false; + private array $entries = []; + private bool $clean = false; /** * @param RegionLocationTableEntry[] $entries diff --git a/src/world/format/io/region/RegionLocationTableEntry.php b/src/world/format/io/region/RegionLocationTableEntry.php index c3c68be87..7ff00f6d0 100644 --- a/src/world/format/io/region/RegionLocationTableEntry.php +++ b/src/world/format/io/region/RegionLocationTableEntry.php @@ -26,13 +26,9 @@ namespace pocketmine\world\format\io\region; use function range; class RegionLocationTableEntry{ - - /** @var int */ - private $firstSector; - /** @var int */ - private $sectorCount; - /** @var int */ - private $timestamp; + private int $firstSector; + private int $sectorCount; + private int $timestamp; /** * @throws \InvalidArgumentException From 0e7e77686208c5b40c9a0aa19adf22a5fd584abd Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 13:12:12 +0100 Subject: [PATCH 16/29] Modernize property declarations in src/utils --- src/utils/Config.php | 16 +++++------- src/utils/Filesystem.php | 4 +-- src/utils/InternetRequestResult.php | 21 ++++----------- src/utils/Random.php | 15 +++-------- src/utils/Terminal.php | 3 +-- src/utils/Utils.php | 6 ++--- src/utils/VersionString.php | 40 ++++++++++------------------- 7 files changed, 34 insertions(+), 71 deletions(-) diff --git a/src/utils/Config.php b/src/utils/Config.php index f15bfe1e5..3fa78df80 100644 --- a/src/utils/Config.php +++ b/src/utils/Config.php @@ -74,23 +74,19 @@ class Config{ * @var mixed[] * @phpstan-var array */ - private $config = []; + private array $config = []; /** * @var mixed[] * @phpstan-var array */ - private $nestedCache = []; + private array $nestedCache = []; - /** @var string */ - private $file; - /** @var int */ - private $type = Config::DETECT; - /** @var int */ - private $jsonOptions = JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING; + private string $file; + private int $type = Config::DETECT; + private int $jsonOptions = JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING; - /** @var bool */ - private $changed = false; + private bool $changed = false; /** @var int[] */ public static $formats = [ diff --git a/src/utils/Filesystem.php b/src/utils/Filesystem.php index 56d45790e..3a4ef243f 100644 --- a/src/utils/Filesystem.php +++ b/src/utils/Filesystem.php @@ -61,12 +61,12 @@ use const SCANDIR_SORT_NONE; final class Filesystem{ /** @var resource[] */ - private static $lockFileHandles = []; + private static array $lockFileHandles = []; /** * @var string[] * @phpstan-var array */ - private static $cleanedPaths = [ + private static array $cleanedPaths = [ \pocketmine\PATH => self::CLEAN_PATH_SRC_PREFIX ]; diff --git a/src/utils/InternetRequestResult.php b/src/utils/InternetRequestResult.php index 481ceedb3..c952c2d6b 100644 --- a/src/utils/InternetRequestResult.php +++ b/src/utils/InternetRequestResult.php @@ -24,26 +24,15 @@ declare(strict_types=1); namespace pocketmine\utils; final class InternetRequestResult{ - - /** - * @var string[][] - * @phpstan-var list> - */ - private $headers; - /** @var string */ - private $body; - /** @var int */ - private $code; - /** * @param string[][] $headers * @phpstan-param list> $headers */ - public function __construct(array $headers, string $body, int $code){ - $this->headers = $headers; - $this->body = $body; - $this->code = $code; - } + public function __construct( + private array $headers, + private string $body, + private int $code + ){} /** * @return string[][] diff --git a/src/utils/Random.php b/src/utils/Random.php index 3c7f6cb0d..6e932a079 100644 --- a/src/utils/Random.php +++ b/src/utils/Random.php @@ -35,17 +35,10 @@ class Random{ public const Z = 521288629; public const W = 88675123; - /** @var int */ - private $x; - - /** @var int */ - private $y; - - /** @var int */ - private $z; - - /** @var int */ - private $w; + private int $x; + private int $y; + private int $z; + private int $w; /** @var int */ protected $seed; diff --git a/src/utils/Terminal.php b/src/utils/Terminal.php index 955abc660..c89ad7805 100644 --- a/src/utils/Terminal.php +++ b/src/utils/Terminal.php @@ -60,8 +60,7 @@ abstract class Terminal{ public static string $COLOR_WHITE = ""; public static string $COLOR_MINECOIN_GOLD = ""; - /** @var bool|null */ - private static $formattingCodes = null; + private static ?bool $formattingCodes = null; public static function hasFormattingCodes() : bool{ if(self::$formattingCodes === null){ diff --git a/src/utils/Utils.php b/src/utils/Utils.php index adb3187f5..b44eb9bff 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -105,10 +105,8 @@ final class Utils{ public const OS_BSD = "bsd"; public const OS_UNKNOWN = "other"; - /** @var string|null */ - private static $os; - /** @var UuidInterface|null */ - private static $serverUniqueId = null; + private static ?string $os; + private static ?UuidInterface $serverUniqueId = null; /** * Returns a readable identifier for the given Closure, including file and line. diff --git a/src/utils/VersionString.php b/src/utils/VersionString.php index 0b2aed47a..2d2cb6bca 100644 --- a/src/utils/VersionString.php +++ b/src/utils/VersionString.php @@ -30,28 +30,16 @@ use function preg_match; * Manages PocketMine-MP version strings, and compares them */ class VersionString{ - /** @var string */ - private $baseVersion; - /** @var string */ - private $suffix; - - /** @var int */ - private $major; - /** @var int */ - private $minor; - /** @var int */ - private $patch; - - /** @var int */ - private $build; - /** @var bool */ - private $development = false; - - public function __construct(string $baseVersion, bool $isDevBuild = false, int $buildNumber = 0){ - $this->baseVersion = $baseVersion; - $this->development = $isDevBuild; - $this->build = $buildNumber; + private int $major; + private int $minor; + private int $patch; + private string $suffix; + public function __construct( + private string $baseVersion, + private bool $isDevBuild = false, + private int $buildNumber = 0 + ){ preg_match('/^(\d+)\.(\d+)\.(\d+)(?:-(.*))?$/', $this->baseVersion, $matches); if(count($matches) < 4){ throw new \InvalidArgumentException("Invalid base version \"$baseVersion\", should contain at least 3 version digits"); @@ -77,10 +65,10 @@ class VersionString{ public function getFullVersion(bool $build = false) : string{ $retval = $this->baseVersion; - if($this->development){ + if($this->isDevBuild){ $retval .= "+dev"; - if($build && $this->build > 0){ - $retval .= "." . $this->build; + if($build && $this->buildNumber > 0){ + $retval .= "." . $this->buildNumber; } } @@ -104,11 +92,11 @@ class VersionString{ } public function getBuild() : int{ - return $this->build; + return $this->buildNumber; } public function isDev() : bool{ - return $this->development; + return $this->isDevBuild; } public function __toString() : string{ From 46c504e529c5c1d2d815e76a9d69580411654372 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 13:14:23 +0100 Subject: [PATCH 17/29] Modernize property declarations in src/ --- src/ServerConfigGroup.php | 8 +++----- src/VersionInfo.php | 6 ++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/ServerConfigGroup.php b/src/ServerConfigGroup.php index f69990cf8..d92938edd 100644 --- a/src/ServerConfigGroup.php +++ b/src/ServerConfigGroup.php @@ -33,16 +33,14 @@ use function strtolower; final class ServerConfigGroup{ - /** @var Config */ - private $pocketmineYml; - /** @var Config */ - private $serverProperties; + private Config $pocketmineYml; + private Config $serverProperties; /** * @var mixed[] * @phpstan-var array */ - private $propertyCache = []; + private array $propertyCache = []; public function __construct(Config $pocketmineYml, Config $serverProperties){ $this->pocketmineYml = $pocketmineYml; diff --git a/src/VersionInfo.php b/src/VersionInfo.php index c2b9b3974..e416314bf 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -39,8 +39,7 @@ final class VersionInfo{ //NOOP } - /** @var string|null */ - private static $gitHash = null; + private static ?string $gitHash = null; public static function GIT_HASH() : string{ if(self::$gitHash === null){ @@ -79,8 +78,7 @@ final class VersionInfo{ return self::$buildNumber; } - /** @var VersionString|null */ - private static $fullVersion = null; + private static ?VersionString $fullVersion = null; public static function VERSION() : VersionString{ if(self::$fullVersion === null){ From ed2a239334d447516337645de6547d695d4d735c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 13:16:21 +0100 Subject: [PATCH 18/29] Modernize property declarations in src/world/generator --- src/world/generator/Flat.php | 6 ++---- src/world/generator/Gaussian.php | 6 ++---- src/world/generator/GeneratorManager.php | 2 +- .../generator/ThreadLocalGeneratorContext.php | 20 ++++++------------- src/world/generator/biome/BiomeSelector.php | 8 +++----- 5 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/world/generator/Flat.php b/src/world/generator/Flat.php index 06dadc517..29420030f 100644 --- a/src/world/generator/Flat.php +++ b/src/world/generator/Flat.php @@ -34,11 +34,9 @@ use pocketmine\world\generator\populator\Populator; use function count; class Flat extends Generator{ - - /** @var Chunk */ - private $chunk; + private Chunk $chunk; /** @var Populator[] */ - private $populators = []; + private array $populators = []; private FlatGeneratorOptions $options; diff --git a/src/world/generator/Gaussian.php b/src/world/generator/Gaussian.php index 61b0f86d9..324fc03c4 100644 --- a/src/world/generator/Gaussian.php +++ b/src/world/generator/Gaussian.php @@ -26,11 +26,9 @@ namespace pocketmine\world\generator; use function exp; final class Gaussian{ - - /** @var int */ - public $smoothSize; + public int $smoothSize; /** @var float[][] */ - public $kernel = []; + public array $kernel = []; public function __construct(int $smoothSize){ $this->smoothSize = $smoothSize; diff --git a/src/world/generator/GeneratorManager.php b/src/world/generator/GeneratorManager.php index 76bda57b6..4bc427da4 100644 --- a/src/world/generator/GeneratorManager.php +++ b/src/world/generator/GeneratorManager.php @@ -37,7 +37,7 @@ final class GeneratorManager{ * @var GeneratorManagerEntry[] name => classname mapping * @phpstan-var array */ - private $list = []; + private array $list = []; public function __construct(){ $this->addGenerator(Flat::class, "flat", \Closure::fromCallable(function(string $preset) : ?InvalidGeneratorOptionsException{ diff --git a/src/world/generator/ThreadLocalGeneratorContext.php b/src/world/generator/ThreadLocalGeneratorContext.php index 56a9b78f6..1fd120437 100644 --- a/src/world/generator/ThreadLocalGeneratorContext.php +++ b/src/world/generator/ThreadLocalGeneratorContext.php @@ -31,7 +31,7 @@ final class ThreadLocalGeneratorContext{ * @var self[] * @phpstan-var array */ - private static $contexts = []; + private static array $contexts = []; public static function register(self $context, int $worldId) : void{ self::$contexts[$worldId] = $context; @@ -45,19 +45,11 @@ final class ThreadLocalGeneratorContext{ return self::$contexts[$worldId] ?? null; } - /** @var Generator */ - private $generator; - - /** @var int */ - private $worldMinY; - /** @var int */ - private $worldMaxY; - - public function __construct(Generator $generator, int $worldMinY, int $worldMaxY){ - $this->generator = $generator; - $this->worldMinY = $worldMinY; - $this->worldMaxY = $worldMaxY; - } + public function __construct( + private Generator $generator, + private int $worldMinY, + private int $worldMaxY + ){} public function getGenerator() : Generator{ return $this->generator; } diff --git a/src/world/generator/biome/BiomeSelector.php b/src/world/generator/biome/BiomeSelector.php index f61f534ce..7daf9ee20 100644 --- a/src/world/generator/biome/BiomeSelector.php +++ b/src/world/generator/biome/BiomeSelector.php @@ -30,16 +30,14 @@ use pocketmine\world\biome\UnknownBiome; use pocketmine\world\generator\noise\Simplex; abstract class BiomeSelector{ - /** @var Simplex */ - private $temperature; - /** @var Simplex */ - private $rainfall; + private Simplex $temperature; + private Simplex $rainfall; /** * @var Biome[]|\SplFixedArray * @phpstan-var \SplFixedArray */ - private $map = null; + private \SplFixedArray $map = null; public function __construct(Random $random){ $this->temperature = new Simplex($random, 2, 1 / 16, 1 / 512); From 6d7bf1c5d8e4b515cf7d36060d3afe8e5ccc3a78 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 14:52:21 +0100 Subject: [PATCH 19/29] Utils: fixed missing property initializer --- src/utils/Utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/Utils.php b/src/utils/Utils.php index b44eb9bff..4654b7c87 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -105,7 +105,7 @@ final class Utils{ public const OS_BSD = "bsd"; public const OS_UNKNOWN = "other"; - private static ?string $os; + private static ?string $os = null; private static ?UuidInterface $serverUniqueId = null; /** From cb76c149e11f178fef5d6f46a9e95c53ff162fdb Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 14:55:53 +0100 Subject: [PATCH 20/29] Modernize property declarations in src/world/particle --- src/world/particle/BlockBreakParticle.php | 11 +++-------- src/world/particle/BlockForceFieldParticle.php | 9 ++------- src/world/particle/BlockPunchParticle.php | 14 ++++---------- src/world/particle/CriticalParticle.php | 7 +------ src/world/particle/DragonEggTeleportParticle.php | 9 +++------ src/world/particle/DustParticle.php | 7 +------ src/world/particle/EnchantParticle.php | 8 +------- src/world/particle/HeartParticle.php | 7 +------ src/world/particle/InkParticle.php | 7 +------ src/world/particle/InstantEnchantParticle.php | 7 +------ src/world/particle/ItemBreakParticle.php | 7 +------ src/world/particle/PotionSplashParticle.php | 8 +------- src/world/particle/RedstoneParticle.php | 7 +------ src/world/particle/SmokeParticle.php | 7 +------ src/world/particle/TerrainParticle.php | 9 ++------- 15 files changed, 24 insertions(+), 100 deletions(-) diff --git a/src/world/particle/BlockBreakParticle.php b/src/world/particle/BlockBreakParticle.php index 40e8d8bea..d45f0f631 100644 --- a/src/world/particle/BlockBreakParticle.php +++ b/src/world/particle/BlockBreakParticle.php @@ -30,15 +30,10 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\LevelEvent; class BlockBreakParticle implements Particle{ - - /** @var Block */ - private $block; - - public function __construct(Block $b){ - $this->block = $b; - } + //TODO: rename this parameter when we can break BC + public function __construct(private Block $b){} public function encode(Vector3 $pos) : array{ - return [LevelEventPacket::create(LevelEvent::PARTICLE_DESTROY, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()), $pos)]; + return [LevelEventPacket::create(LevelEvent::PARTICLE_DESTROY, RuntimeBlockMapping::getInstance()->toRuntimeId($this->b->getFullId()), $pos)]; } } diff --git a/src/world/particle/BlockForceFieldParticle.php b/src/world/particle/BlockForceFieldParticle.php index cfd2d0b2a..282563305 100644 --- a/src/world/particle/BlockForceFieldParticle.php +++ b/src/world/particle/BlockForceFieldParticle.php @@ -28,13 +28,8 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\ParticleIds; class BlockForceFieldParticle implements Particle{ - - /** @var int */ - private $data; - - public function __construct(int $data = 0){ - $this->data = $data; //TODO: proper encode/decode of data - } + //TODO: proper encode/decode of data + public function __construct(private int $data = 0){} public function encode(Vector3 $pos) : array{ return [LevelEventPacket::standardParticle(ParticleIds::BLOCK_FORCE_FIELD, $this->data, $pos)]; diff --git a/src/world/particle/BlockPunchParticle.php b/src/world/particle/BlockPunchParticle.php index 5ee0c3352..2b00e1a26 100644 --- a/src/world/particle/BlockPunchParticle.php +++ b/src/world/particle/BlockPunchParticle.php @@ -33,16 +33,10 @@ use pocketmine\network\mcpe\protocol\types\LevelEvent; * This particle appears when a player is attacking a block face in survival mode attempting to break it. */ class BlockPunchParticle implements Particle{ - - /** @var Block */ - private $block; - /** @var int */ - private $face; - - public function __construct(Block $block, int $face){ - $this->block = $block; - $this->face = $face; - } + public function __construct( + private Block $block, + private int $face + ){} public function encode(Vector3 $pos) : array{ return [LevelEventPacket::create(LevelEvent::PARTICLE_PUNCH_BLOCK, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()) | ($this->face << 24), $pos)]; diff --git a/src/world/particle/CriticalParticle.php b/src/world/particle/CriticalParticle.php index 477d1c7e5..4d26b9709 100644 --- a/src/world/particle/CriticalParticle.php +++ b/src/world/particle/CriticalParticle.php @@ -28,12 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\ParticleIds; class CriticalParticle implements Particle{ - /** @var int */ - private $scale; - - public function __construct(int $scale = 2){ - $this->scale = $scale; - } + public function __construct(private int $scale = 2){} public function encode(Vector3 $pos) : array{ return [LevelEventPacket::standardParticle(ParticleIds::CRITICAL, $this->scale, $pos)]; diff --git a/src/world/particle/DragonEggTeleportParticle.php b/src/world/particle/DragonEggTeleportParticle.php index 924fba112..bfa45249c 100644 --- a/src/world/particle/DragonEggTeleportParticle.php +++ b/src/world/particle/DragonEggTeleportParticle.php @@ -30,12 +30,9 @@ use function abs; class DragonEggTeleportParticle implements Particle{ - /** @var int */ - private $xDiff; - /** @var int */ - private $yDiff; - /** @var int */ - private $zDiff; + private int $xDiff; + private int $yDiff; + private int $zDiff; public function __construct(int $xDiff, int $yDiff, int $zDiff){ $this->xDiff = self::boundOrThrow($xDiff); diff --git a/src/world/particle/DustParticle.php b/src/world/particle/DustParticle.php index 4e0564910..c28b9655d 100644 --- a/src/world/particle/DustParticle.php +++ b/src/world/particle/DustParticle.php @@ -29,12 +29,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\ParticleIds; class DustParticle implements Particle{ - /** @var Color */ - private $color; - - public function __construct(Color $color){ - $this->color = $color; - } + public function __construct(private Color $color){} public function encode(Vector3 $pos) : array{ return [LevelEventPacket::standardParticle(ParticleIds::DUST, $this->color->toARGB(), $pos)]; diff --git a/src/world/particle/EnchantParticle.php b/src/world/particle/EnchantParticle.php index 48f223ae9..a8f7a3d1f 100644 --- a/src/world/particle/EnchantParticle.php +++ b/src/world/particle/EnchantParticle.php @@ -29,13 +29,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\ParticleIds; class EnchantParticle implements Particle{ - - /** @var Color */ - private $color; - - public function __construct(Color $color){ - $this->color = $color; - } + public function __construct(private Color $color){} public function encode(Vector3 $pos) : array{ return [LevelEventPacket::standardParticle(ParticleIds::MOB_SPELL, $this->color->toARGB(), $pos)]; diff --git a/src/world/particle/HeartParticle.php b/src/world/particle/HeartParticle.php index 4d2dddbfe..2552baa6a 100644 --- a/src/world/particle/HeartParticle.php +++ b/src/world/particle/HeartParticle.php @@ -28,12 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\ParticleIds; class HeartParticle implements Particle{ - /** @var int */ - private $scale; - - public function __construct(int $scale = 0){ - $this->scale = $scale; - } + public function __construct(private int $scale = 0){} public function encode(Vector3 $pos) : array{ return [LevelEventPacket::standardParticle(ParticleIds::HEART, $this->scale, $pos)]; diff --git a/src/world/particle/InkParticle.php b/src/world/particle/InkParticle.php index dfe6a5fd7..7eb072211 100644 --- a/src/world/particle/InkParticle.php +++ b/src/world/particle/InkParticle.php @@ -28,12 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\ParticleIds; class InkParticle implements Particle{ - /** @var int */ - private $scale; - - public function __construct(int $scale = 0){ - $this->scale = $scale; - } + public function __construct(private int $scale = 0){} public function encode(Vector3 $pos) : array{ return [LevelEventPacket::standardParticle(ParticleIds::INK, $this->scale, $pos)]; diff --git a/src/world/particle/InstantEnchantParticle.php b/src/world/particle/InstantEnchantParticle.php index 695a4780a..1a4e71abf 100644 --- a/src/world/particle/InstantEnchantParticle.php +++ b/src/world/particle/InstantEnchantParticle.php @@ -29,12 +29,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\ParticleIds; class InstantEnchantParticle implements Particle{ - /** @var Color */ - private $color; - - public function __construct(Color $color){ - $this->color = $color; - } + public function __construct(private Color $color){} public function encode(Vector3 $pos) : array{ return [LevelEventPacket::standardParticle(ParticleIds::MOB_SPELL_INSTANTANEOUS, $this->color->toARGB(), $pos)]; diff --git a/src/world/particle/ItemBreakParticle.php b/src/world/particle/ItemBreakParticle.php index 1a4865a6a..52cde332a 100644 --- a/src/world/particle/ItemBreakParticle.php +++ b/src/world/particle/ItemBreakParticle.php @@ -29,12 +29,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\ParticleIds; class ItemBreakParticle implements Particle{ - /** @var Item */ - private $item; - - public function __construct(Item $item){ - $this->item = $item; - } + public function __construct(private Item $item){} public function encode(Vector3 $pos) : array{ return [LevelEventPacket::standardParticle(ParticleIds::ITEM_BREAK, ($this->item->getId() << 16) | $this->item->getMeta(), $pos)]; diff --git a/src/world/particle/PotionSplashParticle.php b/src/world/particle/PotionSplashParticle.php index 1175e9518..6c7ce1c90 100644 --- a/src/world/particle/PotionSplashParticle.php +++ b/src/world/particle/PotionSplashParticle.php @@ -29,13 +29,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\LevelEvent; class PotionSplashParticle implements Particle{ - - /** @var Color */ - private $color; - - public function __construct(Color $color){ - $this->color = $color; - } + public function __construct(private Color $color){} /** * Returns the default water-bottle splash colour. diff --git a/src/world/particle/RedstoneParticle.php b/src/world/particle/RedstoneParticle.php index f969bcaab..d3fdef581 100644 --- a/src/world/particle/RedstoneParticle.php +++ b/src/world/particle/RedstoneParticle.php @@ -28,12 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\ParticleIds; class RedstoneParticle implements Particle{ - /** @var int */ - private $lifetime; - - public function __construct(int $lifetime = 1){ - $this->lifetime = $lifetime; - } + public function __construct(private int $lifetime = 1){} public function encode(Vector3 $pos) : array{ return [LevelEventPacket::standardParticle(ParticleIds::REDSTONE, $this->lifetime, $pos)]; diff --git a/src/world/particle/SmokeParticle.php b/src/world/particle/SmokeParticle.php index 999f7ffd2..f91f4a1ad 100644 --- a/src/world/particle/SmokeParticle.php +++ b/src/world/particle/SmokeParticle.php @@ -28,12 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\ParticleIds; class SmokeParticle implements Particle{ - /** @var int */ - private $scale; - - public function __construct(int $scale = 0){ - $this->scale = $scale; - } + public function __construct(private int $scale = 0){} public function encode(Vector3 $pos) : array{ return [LevelEventPacket::standardParticle(ParticleIds::SMOKE, $this->scale, $pos)]; diff --git a/src/world/particle/TerrainParticle.php b/src/world/particle/TerrainParticle.php index 5805662e9..829b03adf 100644 --- a/src/world/particle/TerrainParticle.php +++ b/src/world/particle/TerrainParticle.php @@ -30,14 +30,9 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\ParticleIds; class TerrainParticle implements Particle{ - /** @var Block */ - private $block; - - public function __construct(Block $b){ - $this->block = $b; - } + public function __construct(private Block $b){} public function encode(Vector3 $pos) : array{ - return [LevelEventPacket::standardParticle(ParticleIds::TERRAIN, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()), $pos)]; + return [LevelEventPacket::standardParticle(ParticleIds::TERRAIN, RuntimeBlockMapping::getInstance()->toRuntimeId($this->b->getFullId()), $pos)]; } } From 2f03af51ddf2e08271e8de0345c69548b9f7cc64 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 14:57:01 +0100 Subject: [PATCH 21/29] Modernize property declarations in src/world/sound --- src/world/sound/BlockBreakSound.php | 8 +------- src/world/sound/BlockPlaceSound.php | 8 +------- src/world/sound/BlockPunchSound.php | 8 +------- src/world/sound/ClickSound.php | 8 +------- src/world/sound/DoorSound.php | 8 +------- src/world/sound/EntityLandSound.php | 14 ++++---------- src/world/sound/EntityLongFallSound.php | 8 +------- src/world/sound/EntityShortFallSound.php | 8 +------- src/world/sound/FizzSound.php | 8 +------- src/world/sound/LaunchSound.php | 8 +------- src/world/sound/NoteInstrument.php | 9 ++++----- src/world/sound/NoteSound.php | 15 +++++---------- src/world/sound/PopSound.php | 8 +------- src/world/sound/RecordSound.php | 8 +------- src/world/sound/XpLevelUpSound.php | 8 +------- 15 files changed, 25 insertions(+), 109 deletions(-) diff --git a/src/world/sound/BlockBreakSound.php b/src/world/sound/BlockBreakSound.php index 39323259d..ccebeb126 100644 --- a/src/world/sound/BlockBreakSound.php +++ b/src/world/sound/BlockBreakSound.php @@ -30,13 +30,7 @@ use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\types\LevelSoundEvent; class BlockBreakSound implements Sound{ - - /** @var Block */ - private $block; - - public function __construct(Block $block){ - $this->block = $block; - } + public function __construct(private Block $block){} public function encode(Vector3 $pos) : array{ return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::BREAK, $pos, false, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()))]; diff --git a/src/world/sound/BlockPlaceSound.php b/src/world/sound/BlockPlaceSound.php index 831c879a1..20c02a44e 100644 --- a/src/world/sound/BlockPlaceSound.php +++ b/src/world/sound/BlockPlaceSound.php @@ -30,13 +30,7 @@ use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\types\LevelSoundEvent; class BlockPlaceSound implements Sound{ - - /** @var Block */ - private $block; - - public function __construct(Block $block){ - $this->block = $block; - } + public function __construct(private Block $block){} public function encode(Vector3 $pos) : array{ return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::PLACE, $pos, false, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()))]; diff --git a/src/world/sound/BlockPunchSound.php b/src/world/sound/BlockPunchSound.php index 03d3ded64..0c28ccfb8 100644 --- a/src/world/sound/BlockPunchSound.php +++ b/src/world/sound/BlockPunchSound.php @@ -33,13 +33,7 @@ use pocketmine\network\mcpe\protocol\types\LevelSoundEvent; * Played when a player attacks a block in survival, attempting to break it. */ class BlockPunchSound implements Sound{ - - /** @var Block */ - private $block; - - public function __construct(Block $block){ - $this->block = $block; - } + public function __construct(private Block $block){} public function encode(Vector3 $pos) : array{ return [LevelSoundEventPacket::nonActorSound( diff --git a/src/world/sound/ClickSound.php b/src/world/sound/ClickSound.php index c02471f87..1ac8e18c9 100644 --- a/src/world/sound/ClickSound.php +++ b/src/world/sound/ClickSound.php @@ -28,13 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\LevelEvent; class ClickSound implements Sound{ - - /** @var float */ - private $pitch; - - public function __construct(float $pitch = 0){ - $this->pitch = $pitch; - } + public function __construct(private float $pitch = 0){} public function getPitch() : float{ return $this->pitch; diff --git a/src/world/sound/DoorSound.php b/src/world/sound/DoorSound.php index 368136c91..598d44d45 100644 --- a/src/world/sound/DoorSound.php +++ b/src/world/sound/DoorSound.php @@ -28,13 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\LevelEvent; class DoorSound implements Sound{ - - /** @var float */ - private $pitch; - - public function __construct(float $pitch = 0){ - $this->pitch = $pitch; - } + public function __construct(private float $pitch = 0){} public function getPitch() : float{ return $this->pitch; diff --git a/src/world/sound/EntityLandSound.php b/src/world/sound/EntityLandSound.php index a973e3ba5..5610cbfd2 100644 --- a/src/world/sound/EntityLandSound.php +++ b/src/world/sound/EntityLandSound.php @@ -34,16 +34,10 @@ use pocketmine\network\mcpe\protocol\types\LevelSoundEvent; * Played when an entity hits the ground after falling a distance that doesn't cause damage, e.g. due to jumping. */ class EntityLandSound implements Sound{ - - /** @var Entity */ - private $entity; - /** @var Block */ - private $blockLandedOn; - - public function __construct(Entity $entity, Block $blockLandedOn){ - $this->entity = $entity; - $this->blockLandedOn = $blockLandedOn; - } + public function __construct( + private Entity $entity, + private Block $blockLandedOn + ){} public function encode(Vector3 $pos) : array{ return [LevelSoundEventPacket::create( diff --git a/src/world/sound/EntityLongFallSound.php b/src/world/sound/EntityLongFallSound.php index c6cd2a33a..1ad842dfa 100644 --- a/src/world/sound/EntityLongFallSound.php +++ b/src/world/sound/EntityLongFallSound.php @@ -33,13 +33,7 @@ use pocketmine\network\mcpe\protocol\types\LevelSoundEvent; * This is the bone-breaker "crunch" sound. */ class EntityLongFallSound implements Sound{ - - /** @var Entity */ - private $entity; - - public function __construct(Entity $entity){ - $this->entity = $entity; - } + public function __construct(private Entity $entity){} public function encode(Vector3 $pos) : array{ return [LevelSoundEventPacket::create( diff --git a/src/world/sound/EntityShortFallSound.php b/src/world/sound/EntityShortFallSound.php index 722a3c1a3..86d873940 100644 --- a/src/world/sound/EntityShortFallSound.php +++ b/src/world/sound/EntityShortFallSound.php @@ -32,13 +32,7 @@ use pocketmine\network\mcpe\protocol\types\LevelSoundEvent; * Played when an entity hits the ground after falling a short distance. */ class EntityShortFallSound implements Sound{ - - /** @var Entity */ - private $entity; - - public function __construct(Entity $entity){ - $this->entity = $entity; - } + public function __construct(private Entity $entity){} public function encode(Vector3 $pos) : array{ return [LevelSoundEventPacket::create( diff --git a/src/world/sound/FizzSound.php b/src/world/sound/FizzSound.php index 62b54ee16..035d51280 100644 --- a/src/world/sound/FizzSound.php +++ b/src/world/sound/FizzSound.php @@ -28,13 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\LevelEvent; class FizzSound implements Sound{ - - /** @var float */ - private $pitch; - - public function __construct(float $pitch = 0){ - $this->pitch = $pitch; - } + public function __construct(private float $pitch = 0){} public function getPitch() : float{ return $this->pitch; diff --git a/src/world/sound/LaunchSound.php b/src/world/sound/LaunchSound.php index 11ef5ad1d..e50c27cf9 100644 --- a/src/world/sound/LaunchSound.php +++ b/src/world/sound/LaunchSound.php @@ -28,13 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\LevelEvent; class LaunchSound implements Sound{ - - /** @var float */ - private $pitch; - - public function __construct(float $pitch = 0){ - $this->pitch = $pitch; - } + public function __construct(private float $pitch = 0){} public function getPitch() : float{ return $this->pitch; diff --git a/src/world/sound/NoteInstrument.php b/src/world/sound/NoteInstrument.php index b22bc2149..d4077d31d 100644 --- a/src/world/sound/NoteInstrument.php +++ b/src/world/sound/NoteInstrument.php @@ -52,12 +52,11 @@ final class NoteInstrument{ ); } - /** @var int */ - private $magicNumber; - - private function __construct(string $name, int $magicNumber){ + private function __construct( + string $name, + private int $magicNumber + ){ $this->Enum___construct($name); - $this->magicNumber = $magicNumber; } public function getMagicNumber() : int{ diff --git a/src/world/sound/NoteSound.php b/src/world/sound/NoteSound.php index c8822a1a9..a3a788a57 100644 --- a/src/world/sound/NoteSound.php +++ b/src/world/sound/NoteSound.php @@ -28,18 +28,13 @@ use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\types\LevelSoundEvent; class NoteSound implements Sound{ - - /** @var NoteInstrument */ - private $instrument; - /** @var int */ - private $note; - - public function __construct(NoteInstrument $instrument, int $note){ - if($note < 0 || $note > 255){ + public function __construct( + private NoteInstrument $instrument, + private int $note + ){ + if($this->note < 0 || $this->note > 255){ throw new \InvalidArgumentException("Note $note is outside accepted range"); } - $this->instrument = $instrument; - $this->note = $note; } public function encode(Vector3 $pos) : array{ diff --git a/src/world/sound/PopSound.php b/src/world/sound/PopSound.php index a706e6d03..a3fd57ae2 100644 --- a/src/world/sound/PopSound.php +++ b/src/world/sound/PopSound.php @@ -28,13 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\types\LevelEvent; class PopSound implements Sound{ - - /** @var float */ - private $pitch; - - public function __construct(float $pitch = 0){ - $this->pitch = $pitch; - } + public function __construct(private float $pitch = 0){} public function getPitch() : float{ return $this->pitch; diff --git a/src/world/sound/RecordSound.php b/src/world/sound/RecordSound.php index 57051d5b6..97232725f 100644 --- a/src/world/sound/RecordSound.php +++ b/src/world/sound/RecordSound.php @@ -28,13 +28,7 @@ use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; class RecordSound implements Sound{ - - /** @var RecordType */ - private $recordType; - - public function __construct(RecordType $recordType){ - $this->recordType = $recordType; - } + public function __construct(private RecordType $recordType){} public function encode(Vector3 $pos) : array{ return [LevelSoundEventPacket::nonActorSound($this->recordType->getSoundId(), $pos, false)]; diff --git a/src/world/sound/XpLevelUpSound.php b/src/world/sound/XpLevelUpSound.php index b9e2737b2..4e20a067c 100644 --- a/src/world/sound/XpLevelUpSound.php +++ b/src/world/sound/XpLevelUpSound.php @@ -30,13 +30,7 @@ use function intdiv; use function min; class XpLevelUpSound implements Sound{ - - /** @var int */ - private $xpLevel; - - public function __construct(int $xpLevel){ - $this->xpLevel = $xpLevel; - } + public function __construct(private int $xpLevel){} public function getXpLevel() : int{ return $this->xpLevel; From 159392e738a29e134c95e39f9abc2d905e002e49 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 14:57:57 +0100 Subject: [PATCH 22/29] wtf is this shitbox code --- src/world/generator/biome/BiomeSelector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/world/generator/biome/BiomeSelector.php b/src/world/generator/biome/BiomeSelector.php index 7daf9ee20..9b39a339e 100644 --- a/src/world/generator/biome/BiomeSelector.php +++ b/src/world/generator/biome/BiomeSelector.php @@ -37,7 +37,7 @@ abstract class BiomeSelector{ * @var Biome[]|\SplFixedArray * @phpstan-var \SplFixedArray */ - private \SplFixedArray $map = null; + private \SplFixedArray $map; public function __construct(Random $random){ $this->temperature = new Simplex($random, 2, 1 / 16, 1 / 512); From b88a47929fc355df7d82ec647263d6b77a472a11 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 15:06:17 +0100 Subject: [PATCH 23/29] Modernize property declarations in src/world/* --- src/world/BlockTransaction.php | 10 +- src/world/Explosion.php | 15 +- src/world/SimpleChunkManager.php | 13 +- src/world/World.php | 148 ++++++++------------ src/world/WorldManager.php | 34 ++--- src/world/biome/Biome.php | 16 +-- src/world/biome/BiomeRegistry.php | 2 +- src/world/biome/ForestBiome.php | 4 +- src/world/generator/hell/Nether.php | 21 ++- src/world/generator/normal/Normal.php | 19 +-- src/world/generator/object/Ore.php | 3 +- src/world/generator/populator/Ore.php | 2 +- src/world/generator/populator/TallGrass.php | 6 +- src/world/generator/populator/Tree.php | 10 +- src/world/light/BlockLightUpdate.php | 14 +- src/world/light/SkyLightUpdate.php | 14 +- 16 files changed, 116 insertions(+), 215 deletions(-) diff --git a/src/world/BlockTransaction.php b/src/world/BlockTransaction.php index 80bf8445f..b685d2443 100644 --- a/src/world/BlockTransaction.php +++ b/src/world/BlockTransaction.php @@ -28,20 +28,16 @@ use pocketmine\math\Vector3; use pocketmine\utils\Utils; class BlockTransaction{ - /** @var ChunkManager */ - private $world; - /** @var Block[][][] */ - private $blocks = []; + private array $blocks = []; /** * @var \Closure[] * @phpstan-var (\Closure(ChunkManager $world, int $x, int $y, int $z) : bool)[] */ - private $validators = []; + private array $validators = []; - public function __construct(ChunkManager $world){ - $this->world = $world; + public function __construct(private ChunkManager $world){ $this->addValidator(static function(ChunkManager $world, int $x, int $y, int $z) : bool{ return $world->isInWorld($x, $y, $z); }); diff --git a/src/world/Explosion.php b/src/world/Explosion.php index f67d9034f..bad73a4aa 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -46,8 +46,7 @@ use function mt_rand; use function sqrt; class Explosion{ - /** @var int */ - private $rays = 16; + private int $rays = 16; /** @var World */ public $world; /** @var Position */ @@ -59,16 +58,12 @@ class Explosion{ public $affectedBlocks = []; /** @var float */ public $stepLen = 0.3; - /** @var Entity|Block|null */ - private $what; - /** @var SubChunkExplorer */ - private $subChunkExplorer; + private Entity|Block|null $what; - /** - * @param Entity|Block|null $what - */ - public function __construct(Position $center, float $size, $what = null){ + private SubChunkExplorer $subChunkExplorer; + + public function __construct(Position $center, float $size, Entity|Block|null $what = null){ if(!$center->isValid()){ throw new \InvalidArgumentException("Position does not have a valid world"); } diff --git a/src/world/SimpleChunkManager.php b/src/world/SimpleChunkManager.php index 1b2605f33..a56095a17 100644 --- a/src/world/SimpleChunkManager.php +++ b/src/world/SimpleChunkManager.php @@ -34,15 +34,10 @@ class SimpleChunkManager implements ChunkManager{ /** @var Chunk[] */ protected $chunks = []; - /** @var int */ - private $minY; - /** @var int */ - private $maxY; - - public function __construct(int $minY, int $maxY){ - $this->minY = $minY; - $this->maxY = $maxY; - } + public function __construct( + private int $minY, + private int $maxY + ){} public function getBlockAt(int $x, int $y, int $z) : Block{ if($this->isInWorld($x, $y, $z) && ($chunk = $this->getChunk($x >> Chunk::COORD_BIT_SIZE, $z >> Chunk::COORD_BIT_SIZE)) !== null){ diff --git a/src/world/World.php b/src/world/World.php index 6c2a6a9e5..089b24bf4 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -131,8 +131,7 @@ use const PHP_INT_MIN; class World implements ChunkManager{ - /** @var int */ - private static $worldIdCounter = 1; + private static int $worldIdCounter = 1; public const Y_MAX = 256; public const Y_MIN = 0; @@ -154,15 +153,15 @@ class World implements ChunkManager{ public const DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK = 3; /** @var Player[] */ - private $players = []; + private array $players = []; /** @var Entity[] */ - private $entities = []; + private array $entities = []; /** * @var Vector3[] * @phpstan-var array */ - private $entityLastKnownPositions = []; + private array $entityLastKnownPositions = []; /** * @var Entity[][] @@ -173,88 +172,66 @@ class World implements ChunkManager{ /** @var Entity[] */ public $updateEntities = []; /** @var Block[][] */ - private $blockCache = []; + private array $blockCache = []; - /** @var int */ - private $sendTimeTicker = 0; + private int $sendTimeTicker = 0; - /** @var Server */ - private $server; + private int $worldId; - /** @var int */ - private $worldId; + private int $providerGarbageCollectionTicker = 0; - /** @var WritableWorldProvider */ - private $provider; - /** @var int */ - private $providerGarbageCollectionTicker = 0; - - /** @var int */ - private $minY; - /** @var int */ - private $maxY; + private int $minY; + private int $maxY; /** @var TickingChunkLoader[] */ - private $tickingLoaders = []; + private array $tickingLoaders = []; /** @var int[] */ - private $tickingLoaderCounter = []; + private array $tickingLoaderCounter = []; /** @var ChunkLoader[][] */ - private $chunkLoaders = []; + private array $chunkLoaders = []; /** @var ChunkListener[][] */ - private $chunkListeners = []; + private array $chunkListeners = []; /** @var Player[][] */ - private $playerChunkListeners = []; + private array $playerChunkListeners = []; /** @var ClientboundPacket[][] */ - private $packetBuffersByChunk = []; + private array $packetBuffersByChunk = []; /** @var float[] */ - private $unloadQueue = []; + private array $unloadQueue = []; - /** @var int */ - private $time; + private int $time; /** @var bool */ public $stopTime = false; - /** @var float */ - private $sunAnglePercentage = 0.0; - /** @var int */ - private $skyLightReduction = 0; + private float $sunAnglePercentage = 0.0; + private int $skyLightReduction = 0; - /** @var string */ - private $folderName; - /** @var string */ - private $displayName; + private string $folderName; + private string $displayName; /** @var Chunk[] */ - private $chunks = []; + private array $chunks = []; /** @var Vector3[][] */ - private $changedBlocks = []; + private array $changedBlocks = []; - /** - * @var ReversePriorityQueue - * @phpstan-var ReversePriorityQueue - */ - private $scheduledBlockUpdateQueue; + /** @phpstan-var ReversePriorityQueue */ + private ReversePriorityQueue $scheduledBlockUpdateQueue; /** @var int[] */ - private $scheduledBlockUpdateQueueIndex = []; + private array $scheduledBlockUpdateQueueIndex = []; - /** - * @var \SplQueue - * @phpstan-var \SplQueue - */ - private $neighbourBlockUpdateQueue; + /** @phpstan-var \SplQueue */ + private \SplQueue $neighbourBlockUpdateQueue; /** @var bool[] blockhash => dummy */ - private $neighbourBlockUpdateQueueIndex = []; + private array $neighbourBlockUpdateQueueIndex = []; /** @var bool[] */ - private $activeChunkPopulationTasks = []; + private array $activeChunkPopulationTasks = []; /** @var ChunkLockId[] */ - private $chunkLock = []; - /** @var int */ - private $maxConcurrentChunkPopulationTasks = 2; + private array $chunkLock = []; + private int $maxConcurrentChunkPopulationTasks = 2; /** * @var PromiseResolver[] chunkHash => promise * @phpstan-var array> @@ -272,22 +249,17 @@ class World implements ChunkManager{ private array $chunkPopulationRequestQueueIndex = []; /** @var bool[] */ - private $generatorRegisteredWorkers = []; + private array $generatorRegisteredWorkers = []; - /** @var bool */ - private $autoSave = true; + private bool $autoSave = true; - /** @var int */ - private $sleepTicks = 0; + private int $sleepTicks = 0; - /** @var int */ - private $chunkTickRadius; - /** @var int */ - private $chunksPerTick; - /** @var int */ - private $tickedBlocksPerSubchunkPerTick = self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK; + private int $chunkTickRadius; + private int $chunksPerTick; + private int $tickedBlocksPerSubchunkPerTick = self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK; /** @var bool[] */ - private $randomTickBlocks = []; + private array $randomTickBlocks = []; /** @var WorldTimings */ public $timings; @@ -295,33 +267,22 @@ class World implements ChunkManager{ /** @var float */ public $tickRateTime = 0; - /** @var bool */ - private $doingTick = false; + private bool $doingTick = false; - /** - * @var string - * @phpstan-var class-string<\pocketmine\world\generator\Generator> - */ - private $generator; + /** @phpstan-var class-string<\pocketmine\world\generator\Generator> */ + private string $generator; - /** @var bool */ - private $unloaded = false; + private bool $unloaded = false; /** * @var \Closure[] * @phpstan-var array */ - private $unloadCallbacks = []; + private array $unloadCallbacks = []; - /** @var BlockLightUpdate|null */ - private $blockLightUpdate = null; - /** @var SkyLightUpdate|null */ - private $skyLightUpdate = null; + private ?BlockLightUpdate $blockLightUpdate = null; + private ?SkyLightUpdate $skyLightUpdate = null; - /** @var \Logger */ - private $logger; - - /** @var AsyncPool */ - private $workerPool; + private \Logger $logger; public static function chunkHash(int $x, int $z) : int{ return morton2d_encode($x, $z); @@ -407,12 +368,14 @@ class World implements ChunkManager{ /** * Init the default world data */ - public function __construct(Server $server, string $name, WritableWorldProvider $provider, AsyncPool $workerPool){ + public function __construct( + private Server $server, + string $name, //TODO: this should be folderName (named arguments BC break) + private WritableWorldProvider $provider, + private AsyncPool $workerPool + ){ + $this->folderName = $name; $this->worldId = self::$worldIdCounter++; - $this->server = $server; - - $this->provider = $provider; - $this->workerPool = $workerPool; $this->displayName = $this->provider->getWorldData()->getName(); $this->logger = new \PrefixedLogger($server->getLogger(), "World: $this->displayName"); @@ -440,7 +403,6 @@ class World implements ChunkManager{ } }); - $this->folderName = $name; $this->scheduledBlockUpdateQueue = new ReversePriorityQueue(); $this->scheduledBlockUpdateQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH); diff --git a/src/world/WorldManager.php b/src/world/WorldManager.php index fda2bdcb6..3cc01d8ff 100644 --- a/src/world/WorldManager.php +++ b/src/world/WorldManager.php @@ -55,33 +55,19 @@ use function strval; use function trim; class WorldManager{ - /** @var string */ - private $dataPath; - - /** @var WorldProviderManager */ - private $providerManager; - /** @var World[] */ - private $worlds = []; - /** @var World|null */ - private $defaultWorld; + private array $worlds = []; + private ?World $defaultWorld; - /** @var Server */ - private $server; + private bool $autoSave = true; + private int $autoSaveTicks = 6000; + private int $autoSaveTicker = 0; - /** @var bool */ - private $autoSave = true; - /** @var int */ - private $autoSaveTicks = 6000; - - /** @var int */ - private $autoSaveTicker = 0; - - public function __construct(Server $server, string $dataPath, WorldProviderManager $providerManager){ - $this->server = $server; - $this->dataPath = $dataPath; - $this->providerManager = $providerManager; - } + public function __construct( + private Server $server, + private string $dataPath, + private WorldProviderManager $providerManager + ){} public function getProviderManager() : WorldProviderManager{ return $this->providerManager; diff --git a/src/world/biome/Biome.php b/src/world/biome/Biome.php index ea79a048e..6115beabe 100644 --- a/src/world/biome/Biome.php +++ b/src/world/biome/Biome.php @@ -32,21 +32,17 @@ abstract class Biome{ public const MAX_BIOMES = 256; - /** @var int */ - private $id; - /** @var bool */ - private $registered = false; + private int $id; + private bool $registered = false; /** @var Populator[] */ - private $populators = []; + private array $populators = []; - /** @var int */ - private $minElevation; - /** @var int */ - private $maxElevation; + private int $minElevation; + private int $maxElevation; /** @var Block[] */ - private $groundCover = []; + private array $groundCover = []; /** @var float */ protected $rainfall = 0.5; diff --git a/src/world/biome/BiomeRegistry.php b/src/world/biome/BiomeRegistry.php index 9e7f3077b..809cd4b89 100644 --- a/src/world/biome/BiomeRegistry.php +++ b/src/world/biome/BiomeRegistry.php @@ -34,7 +34,7 @@ final class BiomeRegistry{ * @var Biome[]|\SplFixedArray * @phpstan-var \SplFixedArray */ - private $biomes; + private \SplFixedArray $biomes; public function __construct(){ $this->biomes = new \SplFixedArray(Biome::MAX_BIOMES); diff --git a/src/world/biome/ForestBiome.php b/src/world/biome/ForestBiome.php index b791416a5..d5a4dfba4 100644 --- a/src/world/biome/ForestBiome.php +++ b/src/world/biome/ForestBiome.php @@ -28,9 +28,7 @@ use pocketmine\world\generator\populator\TallGrass; use pocketmine\world\generator\populator\Tree; class ForestBiome extends GrassyBiome{ - - /** @var TreeType */ - private $type; + private TreeType $type; public function __construct(?TreeType $type = null){ parent::__construct(); diff --git a/src/world/generator/hell/Nether.php b/src/world/generator/hell/Nether.php index 5440c6d04..bffdc1389 100644 --- a/src/world/generator/hell/Nether.php +++ b/src/world/generator/hell/Nether.php @@ -38,21 +38,16 @@ use function abs; class Nether extends Generator{ - /** @var Populator[] */ - private $populators = []; - /** @var int */ - private $waterHeight = 32; - /** @var int */ - private $emptyHeight = 64; - /** @var int */ - private $emptyAmplitude = 1; - /** @var float */ - private $density = 0.5; + private int $waterHeight = 32; + private int $emptyHeight = 64; + private int $emptyAmplitude = 1; + private float $density = 0.5; /** @var Populator[] */ - private $generationPopulators = []; - /** @var Simplex */ - private $noiseBase; + private array $populators = []; + /** @var Populator[] */ + private array $generationPopulators = []; + private Simplex $noiseBase; /** * @throws InvalidGeneratorOptionsException diff --git a/src/world/generator/normal/Normal.php b/src/world/generator/normal/Normal.php index a1aebfc1b..607bec4c4 100644 --- a/src/world/generator/normal/Normal.php +++ b/src/world/generator/normal/Normal.php @@ -42,21 +42,14 @@ use pocketmine\world\World; class Normal extends Generator{ + private int $waterHeight = 62; /** @var Populator[] */ - private $populators = []; - /** @var int */ - private $waterHeight = 62; - + private array $populators = []; /** @var Populator[] */ - private $generationPopulators = []; - /** @var Simplex */ - private $noiseBase; - - /** @var BiomeSelector */ - private $selector; - - /** @var Gaussian */ - private $gaussian; + private array $generationPopulators = []; + private Simplex $noiseBase; + private BiomeSelector $selector; + private Gaussian $gaussian; /** * @throws InvalidGeneratorOptionsException diff --git a/src/world/generator/object/Ore.php b/src/world/generator/object/Ore.php index 5a3066030..e534545c0 100644 --- a/src/world/generator/object/Ore.php +++ b/src/world/generator/object/Ore.php @@ -30,8 +30,7 @@ use function sin; use const M_PI; class Ore{ - /** @var Random */ - private $random; + private Random $random; /** @var OreType */ public $type; diff --git a/src/world/generator/populator/Ore.php b/src/world/generator/populator/Ore.php index 7a0d6aff9..ab487db04 100644 --- a/src/world/generator/populator/Ore.php +++ b/src/world/generator/populator/Ore.php @@ -31,7 +31,7 @@ use pocketmine\world\generator\object\OreType; class Ore implements Populator{ /** @var OreType[] */ - private $oreTypes = []; + private array $oreTypes = []; public function populate(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void{ foreach($this->oreTypes as $type){ diff --git a/src/world/generator/populator/TallGrass.php b/src/world/generator/populator/TallGrass.php index 10e3d53c5..de8d0b675 100644 --- a/src/world/generator/populator/TallGrass.php +++ b/src/world/generator/populator/TallGrass.php @@ -30,10 +30,8 @@ use pocketmine\world\ChunkManager; use pocketmine\world\format\Chunk; class TallGrass implements Populator{ - /** @var int */ - private $randomAmount = 1; - /** @var int */ - private $baseAmount = 0; + private int $randomAmount = 1; + private int $baseAmount = 0; public function setRandomAmount(int $amount) : void{ $this->randomAmount = $amount; diff --git a/src/world/generator/populator/Tree.php b/src/world/generator/populator/Tree.php index ba4e7d0ae..b0a2214b8 100644 --- a/src/world/generator/populator/Tree.php +++ b/src/world/generator/populator/Tree.php @@ -31,13 +31,9 @@ use pocketmine\world\format\Chunk; use pocketmine\world\generator\object\TreeFactory; class Tree implements Populator{ - /** @var int */ - private $randomAmount = 1; - /** @var int */ - private $baseAmount = 0; - - /** @var TreeType */ - private $type; + private int $randomAmount = 1; + private int $baseAmount = 0; + private TreeType $type; /** * @param TreeType|null $type default oak diff --git a/src/world/light/BlockLightUpdate.php b/src/world/light/BlockLightUpdate.php index 5036400d8..5f6d21faa 100644 --- a/src/world/light/BlockLightUpdate.php +++ b/src/world/light/BlockLightUpdate.php @@ -30,22 +30,18 @@ use pocketmine\world\utils\SubChunkExplorerStatus; use function max; class BlockLightUpdate extends LightUpdate{ - - /** - * @var \SplFixedArray|int[] - * @phpstan-var \SplFixedArray - */ - private $lightEmitters; - /** * @param \SplFixedArray|int[] $lightFilters * @param \SplFixedArray|int[] $lightEmitters * @phpstan-param \SplFixedArray $lightFilters * @phpstan-param \SplFixedArray $lightEmitters */ - public function __construct(SubChunkExplorer $subChunkExplorer, \SplFixedArray $lightFilters, \SplFixedArray $lightEmitters){ + public function __construct( + SubChunkExplorer $subChunkExplorer, + \SplFixedArray $lightFilters, + private \SplFixedArray $lightEmitters + ){ parent::__construct($subChunkExplorer, $lightFilters); - $this->lightEmitters = $lightEmitters; } protected function getCurrentLightArray() : LightArray{ diff --git a/src/world/light/SkyLightUpdate.php b/src/world/light/SkyLightUpdate.php index a505fde02..faf8d1a6c 100644 --- a/src/world/light/SkyLightUpdate.php +++ b/src/world/light/SkyLightUpdate.php @@ -33,22 +33,18 @@ use pocketmine\world\World; use function max; class SkyLightUpdate extends LightUpdate{ - - /** - * @var \SplFixedArray|bool[] - * @phpstan-var \SplFixedArray - */ - private $directSkyLightBlockers; - /** * @param \SplFixedArray|int[] $lightFilters * @param \SplFixedArray|bool[] $directSkyLightBlockers * @phpstan-param \SplFixedArray $lightFilters * @phpstan-param \SplFixedArray $directSkyLightBlockers */ - public function __construct(SubChunkExplorer $subChunkExplorer, \SplFixedArray $lightFilters, \SplFixedArray $directSkyLightBlockers){ + public function __construct( + SubChunkExplorer $subChunkExplorer, + \SplFixedArray $lightFilters, + private \SplFixedArray $directSkyLightBlockers + ){ parent::__construct($subChunkExplorer, $lightFilters); - $this->directSkyLightBlockers = $directSkyLightBlockers; } protected function getCurrentLightArray() : LightArray{ From 20ff5d5a3d0479dc701af53f9660e1583085123f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 15:33:13 +0100 Subject: [PATCH 24/29] Modernize property declarations in src/entity/animation --- src/entity/animation/ArmSwingAnimation.php | 8 ++------ src/entity/animation/ArrowShakeAnimation.php | 13 ++++--------- src/entity/animation/ConsumingItemAnimation.php | 14 ++++---------- src/entity/animation/CriticalHitAnimation.php | 7 +------ src/entity/animation/DeathAnimation.php | 7 +------ src/entity/animation/HurtAnimation.php | 7 +------ src/entity/animation/RespawnAnimation.php | 7 +------ src/entity/animation/SquidInkCloudAnimation.php | 7 +------ src/entity/animation/TotemUseAnimation.php | 9 ++------- 9 files changed, 17 insertions(+), 62 deletions(-) diff --git a/src/entity/animation/ArmSwingAnimation.php b/src/entity/animation/ArmSwingAnimation.php index 8871415a2..d35b5cd4d 100644 --- a/src/entity/animation/ArmSwingAnimation.php +++ b/src/entity/animation/ArmSwingAnimation.php @@ -29,12 +29,8 @@ use pocketmine\network\mcpe\protocol\types\ActorEvent; final class ArmSwingAnimation implements Animation{ - /** @var Living */ - private $entity; //TODO: not sure if this should be constrained to humanoids, but we don't have any concept of that right now - - public function __construct(Living $entity){ - $this->entity = $entity; - } + //TODO: not sure if this should be constrained to humanoids, but we don't have any concept of that right now + public function __construct(private Living $entity){} public function encode() : array{ return [ diff --git a/src/entity/animation/ArrowShakeAnimation.php b/src/entity/animation/ArrowShakeAnimation.php index 256c6142b..3c9481ae1 100644 --- a/src/entity/animation/ArrowShakeAnimation.php +++ b/src/entity/animation/ArrowShakeAnimation.php @@ -29,15 +29,10 @@ use pocketmine\network\mcpe\protocol\types\ActorEvent; class ArrowShakeAnimation implements Animation{ - /** @var Arrow */ - private $arrow; - /** @var int */ - private $durationInTicks; - - public function __construct(Arrow $arrow, int $durationInTicks){ - $this->arrow = $arrow; - $this->durationInTicks = $durationInTicks; - } + public function __construct( + private Arrow $arrow, + private int $durationInTicks + ){} public function encode() : array{ return [ diff --git a/src/entity/animation/ConsumingItemAnimation.php b/src/entity/animation/ConsumingItemAnimation.php index b32f118bb..83ff1d5e7 100644 --- a/src/entity/animation/ConsumingItemAnimation.php +++ b/src/entity/animation/ConsumingItemAnimation.php @@ -31,16 +31,10 @@ use pocketmine\network\mcpe\protocol\types\ActorEvent; final class ConsumingItemAnimation implements Animation{ - /** @var Human */ - private $human; - /** @var Item */ - private $item; - - public function __construct(Human $human, Item $item){ - //TODO: maybe this can be expanded to more than just player entities? - $this->human = $human; - $this->item = $item; - } + public function __construct( + private Human $human, //TODO: maybe this can be expanded to more than just player entities? + private Item $item + ){} public function encode() : array{ [$netId, $netData] = ItemTranslator::getInstance()->toNetworkId($this->item->getId(), $this->item->getMeta()); diff --git a/src/entity/animation/CriticalHitAnimation.php b/src/entity/animation/CriticalHitAnimation.php index f3a588b79..23a114093 100644 --- a/src/entity/animation/CriticalHitAnimation.php +++ b/src/entity/animation/CriticalHitAnimation.php @@ -28,12 +28,7 @@ use pocketmine\network\mcpe\protocol\AnimatePacket; final class CriticalHitAnimation implements Animation{ - /** @var Living */ - private $entity; - - public function __construct(Living $entity){ - $this->entity = $entity; - } + public function __construct(private Living $entity){} public function encode() : array{ return [ diff --git a/src/entity/animation/DeathAnimation.php b/src/entity/animation/DeathAnimation.php index a3a924413..2ef72634b 100644 --- a/src/entity/animation/DeathAnimation.php +++ b/src/entity/animation/DeathAnimation.php @@ -29,12 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ActorEvent; final class DeathAnimation implements Animation{ - /** @var Living */ - private $entity; - - public function __construct(Living $entity){ - $this->entity = $entity; - } + public function __construct(private Living $entity){} public function encode() : array{ return [ diff --git a/src/entity/animation/HurtAnimation.php b/src/entity/animation/HurtAnimation.php index 355b49d47..d179f2f96 100644 --- a/src/entity/animation/HurtAnimation.php +++ b/src/entity/animation/HurtAnimation.php @@ -29,12 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ActorEvent; final class HurtAnimation implements Animation{ - /** @var Living */ - private $entity; - - public function __construct(Living $entity){ - $this->entity = $entity; - } + public function __construct(private Living $entity){} public function encode() : array{ return [ diff --git a/src/entity/animation/RespawnAnimation.php b/src/entity/animation/RespawnAnimation.php index e8466e26e..89bd590e4 100644 --- a/src/entity/animation/RespawnAnimation.php +++ b/src/entity/animation/RespawnAnimation.php @@ -29,12 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ActorEvent; final class RespawnAnimation implements Animation{ - /** @var Living */ - private $entity; - - public function __construct(Living $entity){ - $this->entity = $entity; - } + public function __construct(private Living $entity){} public function encode() : array{ return [ diff --git a/src/entity/animation/SquidInkCloudAnimation.php b/src/entity/animation/SquidInkCloudAnimation.php index 6ae728a79..540875f38 100644 --- a/src/entity/animation/SquidInkCloudAnimation.php +++ b/src/entity/animation/SquidInkCloudAnimation.php @@ -29,12 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ActorEvent; final class SquidInkCloudAnimation implements Animation{ - /** @var Squid */ - private $squid; - - public function __construct(Squid $squid){ - $this->squid = $squid; - } + public function __construct(private Squid $squid){} public function encode() : array{ return [ diff --git a/src/entity/animation/TotemUseAnimation.php b/src/entity/animation/TotemUseAnimation.php index ec0d3b12c..d416e186d 100644 --- a/src/entity/animation/TotemUseAnimation.php +++ b/src/entity/animation/TotemUseAnimation.php @@ -29,13 +29,8 @@ use pocketmine\network\mcpe\protocol\types\ActorEvent; final class TotemUseAnimation implements Animation{ - /** @var Human */ - private $human; - - public function __construct(Human $human){ - //TODO: check if this can be expanded to more than just humans - $this->human = $human; - } + //TODO: check if this can be expanded to more than just humans + public function __construct(private Human $human){} public function encode() : array{ return [ From 5cf572892fb95704dc65c3c70801ad51e7d31172 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 15:38:20 +0100 Subject: [PATCH 25/29] WorldManager: fixed missing initializer for $defaultWorld --- src/world/WorldManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/world/WorldManager.php b/src/world/WorldManager.php index 3cc01d8ff..f4a6e8b08 100644 --- a/src/world/WorldManager.php +++ b/src/world/WorldManager.php @@ -57,7 +57,7 @@ use function trim; class WorldManager{ /** @var World[] */ private array $worlds = []; - private ?World $defaultWorld; + private ?World $defaultWorld = null; private bool $autoSave = true; private int $autoSaveTicks = 6000; From 3752225ed559b8f3570ae8cbb71fec4353e5e7b8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 16:00:34 +0100 Subject: [PATCH 26/29] World: fix CS --- src/world/World.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/world/World.php b/src/world/World.php index 089b24bf4..0c4c676d9 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -403,7 +403,6 @@ class World implements ChunkManager{ } }); - $this->scheduledBlockUpdateQueue = new ReversePriorityQueue(); $this->scheduledBlockUpdateQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH); From 33cf0856920ea4744727150fdc41399b64e233c0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 16:06:20 +0100 Subject: [PATCH 27/29] PHPStan 1.6.3 --- composer.json | 4 ++-- composer.lock | 33 +++++++++++++++------------------ src/network/upnp/UPnP.php | 2 +- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/composer.json b/composer.json index 8ed24acf7..e1389abbc 100644 --- a/composer.json +++ b/composer.json @@ -53,9 +53,9 @@ "webmozart/path-util": "^2.3" }, "require-dev": { - "phpstan/phpstan": "1.5.7", + "phpstan/phpstan": "1.6.3", "phpstan/phpstan-phpunit": "^1.1.0", - "phpstan/phpstan-strict-rules": "^1.0.0", + "phpstan/phpstan-strict-rules": "^1.2.0", "phpunit/phpunit": "^9.2" }, "autoload": { diff --git a/composer.lock b/composer.lock index 7f353a9bf..d04fc2d54 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fa508967e1ffdb63b73de2c40c5b8f11", + "content-hash": "d5463f8f42873bcbbd373123eaa1f659", "packages": [ { "name": "adhocore/json-comment", @@ -1819,16 +1819,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.5.7", + "version": "1.6.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "7fb7e2e1e9f3d59a26a413b2d3d5e47f0edb75ac" + "reference": "6128620b98292e0b69ea6d799871d77163681c8e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7fb7e2e1e9f3d59a26a413b2d3d5e47f0edb75ac", - "reference": "7fb7e2e1e9f3d59a26a413b2d3d5e47f0edb75ac", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/6128620b98292e0b69ea6d799871d77163681c8e", + "reference": "6128620b98292e0b69ea6d799871d77163681c8e", "shasum": "" }, "require": { @@ -1854,7 +1854,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.5.7" + "source": "https://github.com/phpstan/phpstan/tree/1.6.3" }, "funding": [ { @@ -1874,7 +1874,7 @@ "type": "tidelift" } ], - "time": "2022-04-20T12:20:27+00:00" + "time": "2022-04-28T11:27:53+00:00" }, { "name": "phpstan/phpstan-phpunit", @@ -1930,21 +1930,21 @@ }, { "name": "phpstan/phpstan-strict-rules", - "version": "1.1.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-strict-rules.git", - "reference": "e12d55f74a8cca18c6e684c6450767e055ba7717" + "reference": "f3ca6464eae640a556c69a02b3b77a2507475d2f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/e12d55f74a8cca18c6e684c6450767e055ba7717", - "reference": "e12d55f74a8cca18c6e684c6450767e055ba7717", + "url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/f3ca6464eae640a556c69a02b3b77a2507475d2f", + "reference": "f3ca6464eae640a556c69a02b3b77a2507475d2f", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0", - "phpstan/phpstan": "^1.2.0" + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.6.3" }, "require-dev": { "nikic/php-parser": "^4.13.0", @@ -1954,9 +1954,6 @@ }, "type": "phpstan-extension", "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - }, "phpstan": { "includes": [ "rules.neon" @@ -1975,9 +1972,9 @@ "description": "Extra strict and opinionated rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-strict-rules/issues", - "source": "https://github.com/phpstan/phpstan-strict-rules/tree/1.1.0" + "source": "https://github.com/phpstan/phpstan-strict-rules/tree/1.2.1" }, - "time": "2021-11-18T09:30:29+00:00" + "time": "2022-04-28T07:20:18+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/src/network/upnp/UPnP.php b/src/network/upnp/UPnP.php index 1c14cead8..f00b70ef6 100644 --- a/src/network/upnp/UPnP.php +++ b/src/network/upnp/UPnP.php @@ -174,7 +174,7 @@ class UPnP{ '/upnp:controlURL' ), "xpath query is borked"); - if(count($xpathResult) === 0){ + if($xpathResult === null || count($xpathResult) === 0){ throw new UPnPException("Your router does not support portforwarding"); } $controlURL = (string) $xpathResult[0]; From cf15a0913ddaaa276005db3c9bd4fff7d88f7662 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 20:23:23 +0100 Subject: [PATCH 28/29] World: fixed a corner case assertion failure in generation system This required the following: - A generation task (taskA) to already be running for any chunk (chunkA) - A chunk (chunkB) is requested for generation, and the task (taskB) to do the generation is commenced immediately - chunkB generation promise is aborted (e.g. due to chunk unload) and taskB is orphaned - chunkB is subsequently re-requested, but ends up in the generation queue because taskB is still running - taskA completes and drains the generation queue - chunkB attempts to be populated a second time, but taskB has not yet been collected, resulting in an assertion failure. This bug has been appearing intermittently ever since PM 4.0 release. For most users there is no obvious effect since production servers don't have assertions enabled; however, it's unclear what kind of weird side effects this bug may have had. --- src/world/World.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/world/World.php b/src/world/World.php index 6c2a6a9e5..9be1d06e4 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -2653,8 +2653,13 @@ class World implements ChunkManager{ unset($this->changedBlocks[$chunkHash]); if(array_key_exists($chunkHash, $this->chunkPopulationRequestMap)){ + $this->logger->debug("Rejecting population promise for chunk $x $z"); $this->chunkPopulationRequestMap[$chunkHash]->reject(); unset($this->chunkPopulationRequestMap[$chunkHash]); + if(isset($this->activeChunkPopulationTasks[$chunkHash])){ + $this->logger->debug("Marking population task for chunk $x $z as orphaned"); + $this->activeChunkPopulationTasks[$chunkHash] = false; + } } $this->timings->doChunkUnload->stopTiming(); @@ -2830,7 +2835,7 @@ class World implements ChunkManager{ unset($this->chunkPopulationRequestQueueIndex[$nextChunkHash]); World::getXZ($nextChunkHash, $nextChunkX, $nextChunkZ); if(isset($this->chunkPopulationRequestMap[$nextChunkHash])){ - assert(!isset($this->activeChunkPopulationTasks[$nextChunkHash]), "Population for chunk $nextChunkX $nextChunkZ already running"); + assert(!($this->activeChunkPopulationTasks[$nextChunkHash] ?? false), "Population for chunk $nextChunkX $nextChunkZ already running"); if( !$this->orderChunkPopulation($nextChunkX, $nextChunkZ, null)->isResolved() && !isset($this->activeChunkPopulationTasks[$nextChunkHash]) @@ -2999,10 +3004,13 @@ class World implements ChunkManager{ } $index = World::chunkHash($x, $z); - if(!isset($this->chunkPopulationRequestMap[$index])){ - $this->logger->debug("Discarding population result for chunk x=$x,z=$z - promise was already broken"); + if(!isset($this->activeChunkPopulationTasks[$index])){ + throw new AssumptionFailedError("This should always be set, regardless of whether the task was orphaned or not"); + } + if(!$this->activeChunkPopulationTasks[$index]){ + $this->logger->debug("Discarding orphaned population result for chunk x=$x,z=$z"); unset($this->activeChunkPopulationTasks[$index]); - }elseif(isset($this->activeChunkPopulationTasks[$index])){ + }else{ if($dirtyChunks === 0){ $oldChunk = $this->loadChunk($x, $z); $this->setChunk($x, $z, $chunk); From 5d39d7a1c8b350288cfde26b465026dd5b157630 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 28 Apr 2022 21:00:49 +0100 Subject: [PATCH 29/29] Version bump to 4.4 --- src/VersionInfo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VersionInfo.php b/src/VersionInfo.php index e416314bf..7eec0a987 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -31,7 +31,7 @@ use function str_repeat; final class VersionInfo{ public const NAME = "PocketMine-MP"; - public const BASE_VERSION = "4.3.0"; + public const BASE_VERSION = "4.4.0"; public const IS_DEVELOPMENT_BUILD = true; public const BUILD_CHANNEL = "beta";