event: modernize property declarations where possible

only private fields are modified; protected ones can't be changed in case someone extended the classes
This commit is contained in:
Dylan K. Taylor
2022-04-25 00:06:26 +01:00
parent ded7e24f67
commit c8a7a53d70
58 changed files with 258 additions and 444 deletions

View File

@ -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{

View File

@ -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);
}

View File

@ -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

View File

@ -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);
}

View File

@ -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{

View File

@ -31,18 +31,16 @@ use pocketmine\utils\Utils;
* @phpstan-extends EntityEvent<Living>
*/
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;
}
/**

View File

@ -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;
}
/**

View File

@ -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{

View File

@ -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{

View File

@ -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;
}
}

View File

@ -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;
}
/**

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -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;
}
/**

View File

@ -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;
}
/**

View File

@ -31,12 +31,11 @@ use pocketmine\math\RayTraceResult;
* @phpstan-extends EntityEvent<Projectile>
*/
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;
}
/**