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
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
58 changed files with 258 additions and 444 deletions

View File

@ -33,11 +33,11 @@ use pocketmine\event\CancellableTrait;
abstract class BaseBlockChangeEvent extends BlockEvent implements Cancellable{ abstract class BaseBlockChangeEvent extends BlockEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
private Block $newState; public function __construct(
Block $block,
public function __construct(Block $block, Block $newState){ private Block $newState
){
parent::__construct($block); parent::__construct($block);
$this->newState = $newState;
} }
public function getNewState() : Block{ public function getNewState() : Block{

View File

@ -33,12 +33,11 @@ use pocketmine\event\CancellableTrait;
class BlockBurnEvent extends BlockEvent implements Cancellable{ class BlockBurnEvent extends BlockEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Block */ public function __construct(
private $causingBlock; Block $block,
private Block $causingBlock
public function __construct(Block $block, Block $causingBlock){ ){
parent::__construct($block); parent::__construct($block);
$this->causingBlock = $causingBlock;
} }
/** /**

View File

@ -29,12 +29,13 @@ use pocketmine\block\Block;
* Called when a block spreads to another block, such as grass spreading to nearby dirt blocks. * Called when a block spreads to another block, such as grass spreading to nearby dirt blocks.
*/ */
class BlockSpreadEvent extends BaseBlockChangeEvent{ 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); parent::__construct($block, $newState);
$this->source = $source;
} }
public function getSource() : Block{ public function getSource() : Block{

View File

@ -32,12 +32,11 @@ use pocketmine\utils\Utils;
class BlockTeleportEvent extends BlockEvent implements Cancellable{ class BlockTeleportEvent extends BlockEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Vector3 */ public function __construct(
private $to; Block $block,
private Vector3 $to
public function __construct(Block $block, Vector3 $to){ ){
parent::__construct($block); parent::__construct($block);
$this->to = $to;
} }
public function getTo() : Vector3{ public function getTo() : Vector3{

View File

@ -35,20 +35,12 @@ use pocketmine\player\Player;
class SignChangeEvent extends BlockEvent implements Cancellable{ class SignChangeEvent extends BlockEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var BaseSign */ public function __construct(
private $sign; private BaseSign $sign,
private Player $player,
/** @var Player */ private SignText $text
private $player; ){
/** @var SignText */
private $text;
public function __construct(BaseSign $sign, Player $player, SignText $text){
parent::__construct($sign); parent::__construct($sign);
$this->sign = $sign;
$this->player = $player;
$this->text = $text;
} }
public function getSign() : BaseSign{ public function getSign() : BaseSign{

View File

@ -17,13 +17,12 @@ use pocketmine\world\BlockTransaction;
class StructureGrowEvent extends BlockEvent implements Cancellable{ class StructureGrowEvent extends BlockEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
private BlockTransaction $transaction; public function __construct(
private ?Player $player; Block $block,
private BlockTransaction $transaction,
public function __construct(Block $block, BlockTransaction $transaction, ?Player $player){ private ?Player $player
){
parent::__construct($block); parent::__construct($block);
$this->transaction = $transaction;
$this->player = $player;
} }
public function getTransaction() : BlockTransaction{ public function getTransaction() : BlockTransaction{

View File

@ -35,15 +35,12 @@ use pocketmine\event\CancellableTrait;
class EntityBlockChangeEvent extends EntityEvent implements Cancellable{ class EntityBlockChangeEvent extends EntityEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Block */ public function __construct(
private $from; Entity $entity,
/** @var Block */ private Block $from,
private $to; private Block $to
){
public function __construct(Entity $entity, Block $from, Block $to){
$this->entity = $entity; $this->entity = $entity;
$this->from = $from;
$this->to = $to;
} }
public function getBlock() : Block{ public function getBlock() : Block{

View File

@ -30,14 +30,11 @@ use pocketmine\entity\Entity;
* Called when an entity takes damage from a block. * Called when an entity takes damage from a block.
*/ */
class EntityDamageByBlockEvent extends EntityDamageEvent{ class EntityDamageByBlockEvent extends EntityDamageEvent{
/** @var Block */
private $damager;
/** /**
* @param float[] $modifiers * @param float[] $modifiers
*/ */
public function __construct(Block $damager, Entity $entity, int $cause, float $damage, array $modifiers = []){ public function __construct(private Block $damager, Entity $entity, int $cause, float $damage, array $modifiers = []){
$this->damager = $damager;
parent::__construct($entity, $cause, $damage, $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. * 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{ class EntityDamageByChildEntityEvent extends EntityDamageByEntityEvent{
/** @var int */ private int $childEntityEid;
private $childEntityEid;
/** /**
* @param float[] $modifiers * @param float[] $modifiers

View File

@ -31,17 +31,13 @@ use pocketmine\entity\Living;
* Called when an entity takes damage from another entity. * Called when an entity takes damage from another entity.
*/ */
class EntityDamageByEntityEvent extends EntityDamageEvent{ class EntityDamageByEntityEvent extends EntityDamageEvent{
/** @var int */ private int $damagerEntityId;
private $damagerEntityId;
/** @var float */
private $knockBack;
/** /**
* @param float[] $modifiers * @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->damagerEntityId = $damager->getId();
$this->knockBack = $knockBack;
parent::__construct($entity, $cause, $damage, $modifiers); parent::__construct($entity, $cause, $damage, $modifiers);
$this->addAttackerModifiers($damager); $this->addAttackerModifiers($damager);
} }

View File

@ -64,31 +64,25 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{
public const CAUSE_CUSTOM = 14; public const CAUSE_CUSTOM = 14;
public const CAUSE_STARVATION = 15; public const CAUSE_STARVATION = 15;
/** @var int */ private float $baseDamage;
private $cause; private float $originalBase;
/** @var float */
private $baseDamage;
/** @var float */
private $originalBase;
/** @var float[] */ /** @var float[] */
private $modifiers; private array $originals;
/** @var float[] */ private int $attackCooldown = 10;
private $originals;
/** @var int */
private $attackCooldown = 10;
/** /**
* @param float[] $modifiers * @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->entity = $entity;
$this->cause = $cause;
$this->baseDamage = $this->originalBase = $damage; $this->baseDamage = $this->originalBase = $damage;
$this->originals = $modifiers;
$this->modifiers = $modifiers;
$this->originals = $this->modifiers;
} }
public function getCause() : int{ public function getCause() : int{

View File

@ -31,18 +31,16 @@ use pocketmine\utils\Utils;
* @phpstan-extends EntityEvent<Living> * @phpstan-extends EntityEvent<Living>
*/ */
class EntityDeathEvent extends EntityEvent{ class EntityDeathEvent extends EntityEvent{
/** @var Item[] */
private $drops = [];
/** @var int */
private $xp;
/** /**
* @param Item[] $drops * @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->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. * Called when an effect is added to an Entity.
*/ */
class EntityEffectAddEvent extends EntityEffectEvent{ class EntityEffectAddEvent extends EntityEffectEvent{
/** @var EffectInstance|null */ public function __construct(Entity $entity, EffectInstance $effect, private ?EffectInstance $oldEffect = null){
private $oldEffect;
public function __construct(Entity $entity, EffectInstance $effect, ?EffectInstance $oldEffect = null){
parent::__construct($entity, $effect); parent::__construct($entity, $effect);
$this->oldEffect = $oldEffect;
} }
/** /**

View File

@ -34,12 +34,11 @@ use pocketmine\event\CancellableTrait;
class EntityEffectEvent extends EntityEvent implements Cancellable{ class EntityEffectEvent extends EntityEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var EffectInstance */ public function __construct(
private $effect; Entity $entity,
private EffectInstance $effect
public function __construct(Entity $entity, EffectInstance $effect){ ){
$this->entity = $entity; $this->entity = $entity;
$this->effect = $effect;
} }
public function getEffect() : EffectInstance{ public function getEffect() : EffectInstance{

View File

@ -34,12 +34,11 @@ use pocketmine\math\Vector3;
class EntityMotionEvent extends EntityEvent implements Cancellable{ class EntityMotionEvent extends EntityEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Vector3 */ public function __construct(
private $mot; Entity $entity,
private Vector3 $mot
public function __construct(Entity $entity, Vector3 $mot){ ){
$this->entity = $entity; $this->entity = $entity;
$this->mot = $mot;
} }
public function getVector() : Vector3{ public function getVector() : Vector3{

View File

@ -39,15 +39,12 @@ class EntityRegainHealthEvent extends EntityEvent implements Cancellable{
public const CAUSE_CUSTOM = 3; public const CAUSE_CUSTOM = 3;
public const CAUSE_SATURATION = 4; public const CAUSE_SATURATION = 4;
/** @var float */ public function __construct(
private $amount; Entity $entity,
/** @var int */ private float $amount,
private $reason; private int $regainReason
){
public function __construct(Entity $entity, float $amount, int $regainReason){
$this->entity = $entity; $this->entity = $entity;
$this->amount = $amount;
$this->reason = $regainReason;
} }
public function getAmount() : float{ 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. * Returns one of the CAUSE_* constants to indicate why this regeneration occurred.
*/ */
public function getRegainReason() : int{ 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{ class EntityShootBowEvent extends EntityEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Item */ private Entity $projectile;
private $bow;
/** @var Entity */
private $projectile;
/** @var float */
private $force;
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->entity = $shooter;
$this->bow = $bow;
$this->projectile = $projectile; $this->projectile = $projectile;
$this->force = $force;
} }
/** /**

View File

@ -35,15 +35,12 @@ use pocketmine\world\Position;
class EntityTeleportEvent extends EntityEvent implements Cancellable{ class EntityTeleportEvent extends EntityEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Position */ public function __construct(
private $from; Entity $entity,
/** @var Position */ private Position $from,
private $to; private Position $to
){
public function __construct(Entity $entity, Position $from, Position $to){
$this->entity = $entity; $this->entity = $entity;
$this->from = $from;
$this->to = $to;
} }
public function getFrom() : Position{ public function getFrom() : Position{

View File

@ -34,12 +34,11 @@ use pocketmine\event\CancellableTrait;
class EntityTrampleFarmlandEvent extends EntityEvent implements Cancellable{ class EntityTrampleFarmlandEvent extends EntityEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Block */ public function __construct(
private $block; Living $entity,
private Block $block
public function __construct(Living $entity, Block $block){ ){
$this->entity = $entity; $this->entity = $entity;
$this->block = $block;
} }
public function getBlock() : Block{ public function getBlock() : Block{

View File

@ -36,13 +36,11 @@ class ExplosionPrimeEvent extends EntityEvent implements Cancellable{
/** @var float */ /** @var float */
protected $force; protected $force;
/** @var bool */ private bool $blockBreaking = true;
private $blockBreaking;
public function __construct(Entity $entity, float $force){ public function __construct(Entity $entity, float $force){
$this->entity = $entity; $this->entity = $entity;
$this->force = $force; $this->force = $force;
$this->blockBreaking = true;
} }
public function getForce() : float{ public function getForce() : float{

View File

@ -28,12 +28,12 @@ use pocketmine\entity\projectile\Projectile;
use pocketmine\math\RayTraceResult; use pocketmine\math\RayTraceResult;
class ProjectileHitBlockEvent extends ProjectileHitEvent{ class ProjectileHitBlockEvent extends ProjectileHitEvent{
/** @var Block */ public function __construct(
private $blockHit; Projectile $entity,
RayTraceResult $rayTraceResult,
public function __construct(Projectile $entity, RayTraceResult $rayTraceResult, Block $blockHit){ private Block $blockHit
){
parent::__construct($entity, $rayTraceResult); parent::__construct($entity, $rayTraceResult);
$this->blockHit = $blockHit;
} }
/** /**

View File

@ -28,12 +28,12 @@ use pocketmine\entity\projectile\Projectile;
use pocketmine\math\RayTraceResult; use pocketmine\math\RayTraceResult;
class ProjectileHitEntityEvent extends ProjectileHitEvent{ class ProjectileHitEntityEvent extends ProjectileHitEvent{
/** @var Entity */ public function __construct(
private $entityHit; Projectile $entity,
RayTraceResult $rayTraceResult,
public function __construct(Projectile $entity, RayTraceResult $rayTraceResult, Entity $entityHit){ private Entity $entityHit
){
parent::__construct($entity, $rayTraceResult); parent::__construct($entity, $rayTraceResult);
$this->entityHit = $entityHit;
} }
/** /**

View File

@ -31,12 +31,11 @@ use pocketmine\math\RayTraceResult;
* @phpstan-extends EntityEvent<Projectile> * @phpstan-extends EntityEvent<Projectile>
*/ */
abstract class ProjectileHitEvent extends EntityEvent{ abstract class ProjectileHitEvent extends EntityEvent{
/** @var RayTraceResult */ public function __construct(
private $rayTraceResult; Projectile $entity,
private RayTraceResult $rayTraceResult
public function __construct(Projectile $entity, RayTraceResult $rayTraceResult){ ){
$this->entity = $entity; $this->entity = $entity;
$this->rayTraceResult = $rayTraceResult;
} }
/** /**

View File

@ -34,28 +34,17 @@ use pocketmine\player\Player;
class CraftItemEvent extends Event implements Cancellable{ class CraftItemEvent extends Event implements Cancellable{
use CancellableTrait; 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[] $inputs
* @param Item[] $outputs * @param Item[] $outputs
*/ */
public function __construct(CraftingTransaction $transaction, CraftingRecipe $recipe, int $repetitions, array $inputs, array $outputs){ public function __construct(
$this->transaction = $transaction; private CraftingTransaction $transaction,
$this->recipe = $recipe; private CraftingRecipe $recipe,
$this->repetitions = $repetitions; private int $repetitions,
$this->inputs = $inputs; private array $inputs,
$this->outputs = $outputs; private array $outputs
} ){}
/** /**
* Returns the inventory transaction involved in this crafting event. * Returns the inventory transaction involved in this crafting event.

View File

@ -35,20 +35,14 @@ use pocketmine\item\Item;
class FurnaceBurnEvent extends BlockEvent implements Cancellable{ class FurnaceBurnEvent extends BlockEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Furnace */ private bool $burning = true;
private $furnace;
/** @var Item */
private $fuel;
/** @var int */
private $burnTime;
/** @var bool */
private $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()); parent::__construct($furnace->getBlock());
$this->fuel = $fuel;
$this->burnTime = $burnTime;
$this->furnace = $furnace;
} }
public function getFurnace() : Furnace{ public function getFurnace() : Furnace{

View File

@ -32,19 +32,14 @@ use pocketmine\item\Item;
class FurnaceSmeltEvent extends BlockEvent implements Cancellable{ class FurnaceSmeltEvent extends BlockEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Furnace */ public function __construct(
private $furnace; private Furnace $furnace,
/** @var Item */ private Item $source,
private $source; private Item $result
/** @var Item */ ){
private $result;
public function __construct(Furnace $furnace, Item $source, Item $result){
parent::__construct($furnace->getBlock()); parent::__construct($furnace->getBlock());
$this->source = clone $source; $this->source = clone $source;
$this->source->setCount(1); $this->source->setCount(1);
$this->result = $result;
$this->furnace = $furnace;
} }
public function getFurnace() : Furnace{ public function getFurnace() : Furnace{

View File

@ -27,11 +27,10 @@ use pocketmine\inventory\Inventory;
use pocketmine\player\Player; use pocketmine\player\Player;
class InventoryCloseEvent extends InventoryEvent{ class InventoryCloseEvent extends InventoryEvent{
/** @var Player */ public function __construct(
private $who; Inventory $inventory,
private Player $who
public function __construct(Inventory $inventory, Player $who){ ){
$this->who = $who;
parent::__construct($inventory); parent::__construct($inventory);
} }

View File

@ -31,11 +31,10 @@ use pocketmine\player\Player;
class InventoryOpenEvent extends InventoryEvent implements Cancellable{ class InventoryOpenEvent extends InventoryEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Player */ public function __construct(
private $who; Inventory $inventory,
private Player $who
public function __construct(Inventory $inventory, Player $who){ ){
$this->who = $who;
parent::__construct($inventory); parent::__construct($inventory);
} }

View File

@ -35,12 +35,7 @@ use pocketmine\inventory\transaction\InventoryTransaction;
class InventoryTransactionEvent extends Event implements Cancellable{ class InventoryTransactionEvent extends Event implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var InventoryTransaction */ public function __construct(private InventoryTransaction $transaction){}
private $transaction;
public function __construct(InventoryTransaction $transaction){
$this->transaction = $transaction;
}
public function getTransaction() : InventoryTransaction{ public function getTransaction() : InventoryTransaction{
return $this->transaction; return $this->transaction;

View File

@ -31,12 +31,11 @@ use pocketmine\player\Player;
class PlayerBedEnterEvent extends PlayerEvent implements Cancellable{ class PlayerBedEnterEvent extends PlayerEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Block */ public function __construct(
private $bed; Player $player,
private Block $bed
public function __construct(Player $player, Block $bed){ ){
$this->player = $player; $this->player = $player;
$this->bed = $bed;
} }
public function getBed() : Block{ public function getBed() : Block{

View File

@ -27,12 +27,11 @@ use pocketmine\block\Block;
use pocketmine\player\Player; use pocketmine\player\Player;
class PlayerBedLeaveEvent extends PlayerEvent{ class PlayerBedLeaveEvent extends PlayerEvent{
/** @var Block */ public function __construct(
private $bed; Player $player,
private Block $bed
public function __construct(Player $player, Block $bed){ ){
$this->player = $player; $this->player = $player;
$this->bed = $bed;
} }
public function getBed() : Block{ public function getBed() : Block{

View File

@ -35,15 +35,12 @@ use pocketmine\player\Player;
class PlayerBlockPickEvent extends PlayerEvent implements Cancellable{ class PlayerBlockPickEvent extends PlayerEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Block */ public function __construct(
private $blockClicked; Player $player,
/** @var Item */ private Block $blockClicked,
private $resultItem; private Item $resultItem
){
public function __construct(Player $player, Block $blockClicked, Item $resultItem){
$this->player = $player; $this->player = $player;
$this->blockClicked = $blockClicked;
$this->resultItem = $resultItem;
} }
public function getBlock() : Block{ public function getBlock() : Block{

View File

@ -35,21 +35,14 @@ use pocketmine\player\Player;
abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable{ abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Block */ public function __construct(
private $blockClicked; Player $who,
/** @var int */ private Block $blockClicked,
private $blockFace; private int $blockFace,
/** @var Item */ private Item $bucket,
private $bucket; private Item $itemInHand
/** @var Item */ ){
private $item;
public function __construct(Player $who, Block $blockClicked, int $blockFace, Item $bucket, Item $itemInHand){
$this->player = $who; $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 * Returns the item in hand after the event
*/ */
public function getItem() : Item{ public function getItem() : Item{
return $this->item; return $this->itemInHand;
} }
public function setItem(Item $item) : void{ public function setItem(Item $item) : void{
$this->item = $item; $this->itemInHand = $item;
} }
public function getBlockClicked() : Block{ public function getBlockClicked() : Block{

View File

@ -34,15 +34,12 @@ use pocketmine\player\Player;
class PlayerChangeSkinEvent extends PlayerEvent implements Cancellable{ class PlayerChangeSkinEvent extends PlayerEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Skin */ public function __construct(
private $oldSkin; Player $player,
/** @var Skin */ private Skin $oldSkin,
private $newSkin; private Skin $newSkin
){
public function __construct(Player $player, Skin $oldSkin, Skin $newSkin){
$this->player = $player; $this->player = $player;
$this->oldSkin = $oldSkin;
$this->newSkin = $newSkin;
} }
public function getOldSkin() : Skin{ public function getOldSkin() : Skin{

View File

@ -34,23 +34,12 @@ use function is_a;
*/ */
class PlayerCreationEvent extends Event{ class PlayerCreationEvent extends Event{
/** @var NetworkSession */ /** @phpstan-var class-string<Player> */
private $session; private string $baseClass = Player::class;
/** @phpstan-var class-string<Player> */
private string $playerClass = Player::class;
/** public function __construct(private NetworkSession $session){}
* @var string
* @phpstan-var class-string<Player>
*/
private $baseClass = Player::class;
/**
* @var string
* @phpstan-var class-string<Player>
*/
private $playerClass = Player::class;
public function __construct(NetworkSession $session){
$this->session = $session;
}
public function getNetworkSession() : NetworkSession{ public function getNetworkSession() : NetworkSession{
return $this->session; return $this->session;

View File

@ -39,13 +39,14 @@ class PlayerDataSaveEvent extends Event implements Cancellable{
protected $data; protected $data;
/** @var string */ /** @var string */
protected $playerName; 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->data = $nbt;
$this->playerName = $playerName; $this->playerName = $playerName;
$this->player = $player;
} }
/** /**

View File

@ -38,10 +38,8 @@ class PlayerDeathEvent extends EntityDeathEvent{
/** @var Player */ /** @var Player */
protected $player; protected $player;
/** @var Translatable|string */ private Translatable|string $deathMessage;
private $deathMessage; private bool $keepInventory = false;
/** @var bool */
private $keepInventory = false;
/** /**
* @param Item[] $drops * @param Item[] $drops

View File

@ -27,15 +27,12 @@ use pocketmine\player\Player;
class PlayerDisplayNameChangeEvent extends PlayerEvent{ class PlayerDisplayNameChangeEvent extends PlayerEvent{
/** @var string */ public function __construct(
private $oldName; Player $player,
/** @var string */ private string $oldName,
private $newName; private string $newName
){
public function __construct(Player $player, string $oldName, string $newName){
$this->player = $player; $this->player = $player;
$this->oldName = $oldName;
$this->newName = $newName;
} }
public function getOldName() : string{ public function getOldName() : string{

View File

@ -34,12 +34,11 @@ use pocketmine\player\Player;
class PlayerDropItemEvent extends PlayerEvent implements Cancellable{ class PlayerDropItemEvent extends PlayerEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Item */ public function __construct(
private $drop; Player $player,
private Item $drop
public function __construct(Player $player, Item $drop){ ){
$this->player = $player; $this->player = $player;
$this->drop = $drop;
} }
public function getItem() : Item{ public function getItem() : Item{

View File

@ -35,17 +35,12 @@ use pocketmine\network\mcpe\NetworkSession;
class PlayerDuplicateLoginEvent extends Event implements Cancellable{ class PlayerDuplicateLoginEvent extends Event implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var NetworkSession */ private string $disconnectMessage = "Logged in from another location";
private $connectingSession;
/** @var NetworkSession */
private $existingSession;
/** @var string */
private $disconnectMessage = "Logged in from another location";
public function __construct(NetworkSession $connectingSession, NetworkSession $existingSession){ public function __construct(
$this->connectingSession = $connectingSession; private NetworkSession $connectingSession,
$this->existingSession = $existingSession; private NetworkSession $existingSession
} ){}
public function getConnectingSession() : NetworkSession{ public function getConnectingSession() : NetworkSession{
return $this->connectingSession; return $this->connectingSession;

View File

@ -37,24 +37,17 @@ class PlayerEditBookEvent extends PlayerEvent implements Cancellable{
public const ACTION_SWAP_PAGES = 3; public const ACTION_SWAP_PAGES = 3;
public const ACTION_SIGN_BOOK = 4; 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 * @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->player = $player;
$this->oldBook = $oldBook;
$this->newBook = $newBook;
$this->action = $action;
$this->modifiedPages = $modifiedPages;
} }
/** /**

View File

@ -46,19 +46,16 @@ class PlayerExhaustEvent extends EntityEvent implements Cancellable{
public const CAUSE_SPRINT_JUMPING = 10; public const CAUSE_SPRINT_JUMPING = 10;
public const CAUSE_CUSTOM = 11; public const CAUSE_CUSTOM = 11;
/** @var float */
private $amount;
/** @var int */
private $cause;
/** @var Human */ /** @var Human */
protected $player; 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->entity = $human;
$this->player = $human; $this->player = $human;
$this->amount = $amount;
$this->cause = $cause;
} }
/** /**

View File

@ -37,22 +37,15 @@ class PlayerExperienceChangeEvent extends EntityEvent implements Cancellable{
/** @var Human */ /** @var Human */
protected $entity; 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->entity = $player;
$this->oldLevel = $oldLevel;
$this->oldProgress = $oldProgress;
$this->newLevel = $newLevel;
$this->newProgress = $newProgress;
} }
public function getOldLevel() : int{ public function getOldLevel() : int{

View File

@ -34,12 +34,11 @@ use pocketmine\player\Player;
class PlayerItemConsumeEvent extends PlayerEvent implements Cancellable{ class PlayerItemConsumeEvent extends PlayerEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Item */ public function __construct(
private $item; Player $player,
private Item $item
public function __construct(Player $player, Item $item){ ){
$this->player = $player; $this->player = $player;
$this->item = $item;
} }
public function getItem() : Item{ public function getItem() : Item{

View File

@ -31,15 +31,12 @@ use pocketmine\player\Player;
class PlayerItemHeldEvent extends PlayerEvent implements Cancellable{ class PlayerItemHeldEvent extends PlayerEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Item */ public function __construct(
private $item; Player $player,
/** @var int */ private Item $item,
private $hotbarSlot; private int $hotbarSlot
){
public function __construct(Player $player, Item $item, int $hotbarSlot){
$this->player = $player; $this->player = $player;
$this->item = $item;
$this->hotbarSlot = $hotbarSlot;
} }
/** /**

View File

@ -35,15 +35,12 @@ use pocketmine\player\Player;
class PlayerItemUseEvent extends PlayerEvent implements Cancellable{ class PlayerItemUseEvent extends PlayerEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Item */ public function __construct(
private $item; Player $player,
/** @var Vector3 */ private Item $item,
private $directionVector; private Vector3 $directionVector
){
public function __construct(Player $player, Item $item, Vector3 $directionVector){
$this->player = $player; $this->player = $player;
$this->item = $item;
$this->directionVector = $directionVector;
} }
/** /**

View File

@ -32,15 +32,12 @@ use pocketmine\utils\Utils;
class PlayerMoveEvent extends PlayerEvent implements Cancellable{ class PlayerMoveEvent extends PlayerEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var Location */ public function __construct(
private $from; Player $player,
/** @var Location */ private Location $from,
private $to; private Location $to
){
public function __construct(Player $player, Location $from, Location $to){
$this->player = $player; $this->player = $player;
$this->from = $from;
$this->to = $to;
} }
public function getFrom() : Location{ public function getFrom() : Location{

View File

@ -52,22 +52,18 @@ class PlayerPreLoginEvent extends Event implements Cancellable{
self::KICK_REASON_BANNED self::KICK_REASON_BANNED
]; ];
/** @var PlayerInfo */
private $playerInfo;
/** @var string */
private $ip;
/** @var int */
private $port;
/** @var bool */ /** @var bool */
protected $authRequired; protected $authRequired;
/** @var string[] reason const => associated message */ /** @var string[] reason const => associated message */
protected $kickReasons = []; protected $kickReasons = [];
public function __construct(PlayerInfo $playerInfo, string $ip, int $port, bool $authRequired){ public function __construct(
$this->playerInfo = $playerInfo; private PlayerInfo $playerInfo,
$this->ip = $ip; private string $ip,
$this->port = $port; private int $port,
bool $authRequired
){
$this->authRequired = $authRequired; $this->authRequired = $authRequired;
} }

View File

@ -30,12 +30,7 @@ use pocketmine\event\Event;
use pocketmine\plugin\Plugin; use pocketmine\plugin\Plugin;
abstract class PluginEvent extends Event{ abstract class PluginEvent extends Event{
/** @var Plugin */ public function __construct(private Plugin $plugin){}
private $plugin;
public function __construct(Plugin $plugin){
$this->plugin = $plugin;
}
public function getPlugin() : Plugin{ public function getPlugin() : Plugin{
return $this->plugin; return $this->plugin;

View File

@ -31,15 +31,10 @@ use pocketmine\network\mcpe\protocol\ServerboundPacket;
class DataPacketReceiveEvent extends ServerEvent implements Cancellable{ class DataPacketReceiveEvent extends ServerEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var ServerboundPacket */ public function __construct(
private $packet; private NetworkSession $origin,
/** @var NetworkSession */ private ServerboundPacket $packet
private $origin; ){}
public function __construct(NetworkSession $origin, ServerboundPacket $packet){
$this->packet = $packet;
$this->origin = $origin;
}
public function getPacket() : ServerboundPacket{ public function getPacket() : ServerboundPacket{
return $this->packet; return $this->packet;

View File

@ -34,19 +34,14 @@ use pocketmine\network\mcpe\protocol\ClientboundPacket;
class DataPacketSendEvent extends ServerEvent implements Cancellable{ class DataPacketSendEvent extends ServerEvent implements Cancellable{
use CancellableTrait; use CancellableTrait;
/** @var NetworkSession[] */
private $targets;
/** @var ClientboundPacket[] */
private $packets;
/** /**
* @param NetworkSession[] $targets * @param NetworkSession[] $targets
* @param ClientboundPacket[] $packets * @param ClientboundPacket[] $packets
*/ */
public function __construct(array $targets, array $packets){ public function __construct(
$this->targets = $targets; private array $targets,
$this->packets = $packets; private array $packets
} ){}
/** /**
* @return NetworkSession[] * @return NetworkSession[]

View File

@ -30,21 +30,12 @@ use pocketmine\utils\Process;
* Plugins should free caches or other non-essential data. * Plugins should free caches or other non-essential data.
*/ */
class LowMemoryEvent extends ServerEvent{ class LowMemoryEvent extends ServerEvent{
/** @var int */ public function __construct(
private $memory; private int $memory,
/** @var int */ private int $memoryLimit,
private $memoryLimit; private bool $isGlobal = false,
/** @var int */ private int $triggerCount = 0
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;
}
/** /**
* Returns the memory usage at the time of the event call (in bytes) * 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{ public function isGlobal() : bool{
return $this->global; return $this->isGlobal;
} }
/** /**

View File

@ -26,12 +26,7 @@ namespace pocketmine\event\server;
use pocketmine\network\query\QueryInfo; use pocketmine\network\query\QueryInfo;
class QueryRegenerateEvent extends ServerEvent{ class QueryRegenerateEvent extends ServerEvent{
/** @var QueryInfo */ public function __construct(private QueryInfo $queryInfo){}
private $queryInfo;
public function __construct(QueryInfo $queryInfo){
$this->queryInfo = $queryInfo;
}
public function getQueryInfo() : QueryInfo{ public function getQueryInfo() : QueryInfo{
return $this->queryInfo; return $this->queryInfo;

View File

@ -30,12 +30,7 @@ use pocketmine\updater\UpdateChecker;
* Plugins may use this event to perform actions when an update notification is received. * Plugins may use this event to perform actions when an update notification is received.
*/ */
class UpdateNotifyEvent extends ServerEvent{ class UpdateNotifyEvent extends ServerEvent{
/** @var UpdateChecker */ public function __construct(private UpdateChecker $updater){}
private $updater;
public function __construct(UpdateChecker $updater){
$this->updater = $updater;
}
public function getUpdater() : UpdateChecker{ public function getUpdater() : UpdateChecker{
return $this->updater; return $this->updater;

View File

@ -30,18 +30,13 @@ use pocketmine\world\World;
* Chunk-related events * Chunk-related events
*/ */
abstract class ChunkEvent extends WorldEvent{ abstract class ChunkEvent extends WorldEvent{
/** @var Chunk */ public function __construct(
private $chunk; World $world,
/** @var int */ private int $chunkX,
private $chunkX; private int $chunkZ,
/** @var int */ private Chunk $chunk
private $chunkZ; ){
public function __construct(World $world, int $chunkX, int $chunkZ, Chunk $chunk){
parent::__construct($world); parent::__construct($world);
$this->chunk = $chunk;
$this->chunkX = $chunkX;
$this->chunkZ = $chunkZ;
} }
public function getChunk() : Chunk{ public function getChunk() : Chunk{

View File

@ -30,12 +30,14 @@ use pocketmine\world\World;
* Called when a Chunk is loaded * Called when a Chunk is loaded
*/ */
class ChunkLoadEvent extends ChunkEvent{ class ChunkLoadEvent extends ChunkEvent{
/** @var bool */ public function __construct(
private $newChunk; World $world,
int $chunkX,
public function __construct(World $world, int $chunkX, int $chunkZ, Chunk $chunk, bool $newChunk){ int $chunkZ,
Chunk $chunk,
private bool $newChunk
){
parent::__construct($world, $chunkX, $chunkZ, $chunk); parent::__construct($world, $chunkX, $chunkZ, $chunk);
$this->newChunk = $newChunk;
} }
public function isNewChunk() : bool{ public function isNewChunk() : bool{

View File

@ -31,12 +31,11 @@ use pocketmine\world\World;
* The previous spawn is included * The previous spawn is included
*/ */
class SpawnChangeEvent extends WorldEvent{ class SpawnChangeEvent extends WorldEvent{
/** @var Position */ public function __construct(
private $previousSpawn; World $world,
private Position $previousSpawn
public function __construct(World $world, Position $previousSpawn){ ){
parent::__construct($world); parent::__construct($world);
$this->previousSpawn = $previousSpawn;
} }
public function getPreviousSpawn() : Position{ public function getPreviousSpawn() : Position{

View File

@ -30,12 +30,7 @@ use pocketmine\event\Event;
use pocketmine\world\World; use pocketmine\world\World;
abstract class WorldEvent extends Event{ abstract class WorldEvent extends Event{
/** @var World */ public function __construct(private World $world){}
private $world;
public function __construct(World $world){
$this->world = $world;
}
public function getWorld() : World{ public function getWorld() : World{
return $this->world; return $this->world;