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;