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

View File

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

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.
*/
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{

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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