Hinting up Entity API to PHP 7.2 standards

This commit is contained in:
Dylan K. Taylor 2018-05-19 10:46:47 +01:00
parent 389990e0a8
commit 0bb5e88b5c
17 changed files with 181 additions and 171 deletions

View File

@ -401,7 +401,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* *
* @return UUID|null * @return UUID|null
*/ */
public function getUniqueId(){ public function getUniqueId() : ?UUID{
return parent::getUniqueId(); return parent::getUniqueId();
} }
@ -459,7 +459,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** /**
* @param Player $player * @param Player $player
*/ */
public function spawnTo(Player $player){ public function spawnTo(Player $player) : void{
if($this->spawned and $player->spawned and $this->isAlive() and $player->isAlive() and $player->getLevel() === $this->level and $player->canSee($this) and !$this->isSpectator()){ if($this->spawned and $player->spawned and $this->isAlive() and $player->isAlive() and $player->getLevel() === $this->level and $player->canSee($this) and !$this->isSpectator()){
parent::spawnTo($player); parent::spawnTo($player);
} }
@ -538,7 +538,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return !$this->isSpectator(); return !$this->isSpectator();
} }
public function resetFallDistance(){ public function resetFallDistance() : void{
parent::resetFallDistance(); parent::resetFallDistance();
if($this->inAirTicks !== 0){ if($this->inAirTicks !== 0){
$this->startAirTicks = 5; $this->startAirTicks = 5;
@ -812,7 +812,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* *
* If null is given, will additionally send the skin to the player itself as well as its viewers. * If null is given, will additionally send the skin to the player itself as well as its viewers.
*/ */
public function sendSkin(array $targets = null) : void{ public function sendSkin(?array $targets = null) : void{
parent::sendSkin($targets ?? $this->server->getOnlinePlayers()); parent::sendSkin($targets ?? $this->server->getOnlinePlayers());
} }
@ -1487,7 +1487,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return 0; return 0;
} }
protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz){ protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz) : void{
if(!$this->onGround or $movY != 0){ if(!$this->onGround or $movY != 0){
$bb = clone $this->boundingBox; $bb = clone $this->boundingBox;
$bb->minY = $this->y - 0.2; $bb->minY = $this->y - 0.2;
@ -1637,13 +1637,13 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->newPosition = null; $this->newPosition = null;
} }
public function jump(){ public function jump() : void{
$this->server->getPluginManager()->callEvent(new PlayerJumpEvent($this)); $this->server->getPluginManager()->callEvent(new PlayerJumpEvent($this));
parent::jump(); parent::jump();
} }
public function setMotion(Vector3 $mot){ public function setMotion(Vector3 $motion) : bool{
if(parent::setMotion($mot)){ if(parent::setMotion($motion)){
$this->broadcastMotion(); $this->broadcastMotion();
if($this->motionY > 0){ if($this->motionY > 0){
@ -1655,11 +1655,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return false; return false;
} }
protected function updateMovement(bool $teleport = false){ protected function updateMovement(bool $teleport = false) : void{
} }
protected function tryChangeMovement(){ protected function tryChangeMovement() : void{
} }
@ -1744,7 +1744,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return true; return true;
} }
public function doFoodTick(int $tickDiff = 1){ public function doFoodTick(int $tickDiff = 1) : void{
if($this->isSurvival()){ if($this->isSurvival()){
parent::doFoodTick($tickDiff); parent::doFoodTick($tickDiff);
} }
@ -1827,11 +1827,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return ($targetDot - $eyeDot) >= -$maxDiff; return ($targetDot - $eyeDot) >= -$maxDiff;
} }
protected function initHumanData(){ protected function initHumanData() : void{
$this->setNameTag($this->username); $this->setNameTag($this->username);
} }
protected function initEntity(){ protected function initEntity() : void{
parent::initEntity(); parent::initEntity();
$this->addDefaultWindows(); $this->addDefaultWindows();
} }
@ -3340,7 +3340,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
* @param string $reason Reason showed in console * @param string $reason Reason showed in console
* @param bool $notify * @param bool $notify
*/ */
final public function close($message = "", string $reason = "generic reason", bool $notify = true){ final public function close($message = "", string $reason = "generic reason", bool $notify = true) : void{
if($this->isConnected() and !$this->closed){ if($this->isConnected() and !$this->closed){
try{ try{
@ -3491,7 +3491,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
} }
public function kill(){ public function kill() : void{
if(!$this->spawned){ if(!$this->spawned){
return; return;
} }
@ -3501,7 +3501,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->sendRespawnPacket($this->getSpawn()); $this->sendRespawnPacket($this->getSpawn());
} }
protected function onDeath(){ protected function onDeath() : void{
$message = "death.attack.generic"; $message = "death.attack.generic";
$params = [ $params = [
@ -3689,7 +3689,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$this->exhaust(0.3, PlayerExhaustEvent::CAUSE_DAMAGE); $this->exhaust(0.3, PlayerExhaustEvent::CAUSE_DAMAGE);
} }
public function attack(EntityDamageEvent $source){ public function attack(EntityDamageEvent $source) : void{
if(!$this->isAlive()){ if(!$this->isAlive()){
return; return;
} }

View File

@ -51,7 +51,7 @@ class Attribute{
/** @var Attribute[] */ /** @var Attribute[] */
protected static $attributes = []; protected static $attributes = [];
public static function init(){ public static function init() : void{
self::addAttribute(self::ABSORPTION, "minecraft:absorption", 0.00, 340282346638528859811704183484516925440.00, 0.00); self::addAttribute(self::ABSORPTION, "minecraft:absorption", 0.00, 340282346638528859811704183484516925440.00, 0.00);
self::addAttribute(self::SATURATION, "minecraft:player.saturation", 0.00, 20.00, 20.00); self::addAttribute(self::SATURATION, "minecraft:player.saturation", 0.00, 20.00, 20.00);
self::addAttribute(self::EXHAUSTION, "minecraft:player.exhaustion", 0.00, 5.00, 0.0); self::addAttribute(self::EXHAUSTION, "minecraft:player.exhaustion", 0.00, 5.00, 0.0);
@ -92,7 +92,7 @@ class Attribute{
* *
* @return Attribute|null * @return Attribute|null
*/ */
public static function getAttribute(int $id){ public static function getAttribute(int $id) : ?Attribute{
return isset(self::$attributes[$id]) ? clone self::$attributes[$id] : null; return isset(self::$attributes[$id]) ? clone self::$attributes[$id] : null;
} }
@ -101,7 +101,7 @@ class Attribute{
* *
* @return Attribute|null * @return Attribute|null
*/ */
public static function getAttributeByName(string $name){ public static function getAttributeByName(string $name) : ?Attribute{
foreach(self::$attributes as $a){ foreach(self::$attributes as $a){
if($a->getName() === $name){ if($a->getName() === $name){
return clone $a; return clone $a;
@ -170,7 +170,7 @@ class Attribute{
return $this; return $this;
} }
public function resetToDefault(){ public function resetToDefault() : void{
$this->setValue($this->getDefaultValue()); $this->setValue($this->getDefaultValue());
} }
@ -219,7 +219,7 @@ class Attribute{
return $this->shouldSend and $this->desynchronized; return $this->shouldSend and $this->desynchronized;
} }
public function markSynchronized(bool $synced = true){ public function markSynchronized(bool $synced = true) : void{
$this->desynchronized = !$synced; $this->desynchronized = !$synced;
} }
} }

View File

@ -27,7 +27,7 @@ class AttributeMap implements \ArrayAccess{
/** @var Attribute[] */ /** @var Attribute[] */
private $attributes = []; private $attributes = [];
public function addAttribute(Attribute $attribute){ public function addAttribute(Attribute $attribute) : void{
$this->attributes[$attribute->getId()] = $attribute; $this->attributes[$attribute->getId()] = $attribute;
} }
@ -36,7 +36,7 @@ class AttributeMap implements \ArrayAccess{
* *
* @return Attribute|null * @return Attribute|null
*/ */
public function getAttribute(int $id){ public function getAttribute(int $id) : ?Attribute{
return $this->attributes[$id] ?? null; return $this->attributes[$id] ?? null;
} }
@ -56,19 +56,28 @@ class AttributeMap implements \ArrayAccess{
}); });
} }
public function offsetExists($offset){ public function offsetExists($offset) : bool{
return isset($this->attributes[$offset]); return isset($this->attributes[$offset]);
} }
public function offsetGet($offset){ /**
* @param int $offset
*
* @return float
*/
public function offsetGet($offset) : float{
return $this->attributes[$offset]->getValue(); return $this->attributes[$offset]->getValue();
} }
public function offsetSet($offset, $value){ /**
* @param int $offset
* @param float $value
*/
public function offsetSet($offset, $value) : void{
$this->attributes[$offset]->setValue($value); $this->attributes[$offset]->setValue($value);
} }
public function offsetUnset($offset){ public function offsetUnset($offset) : void{
throw new \RuntimeException("Could not unset an attribute from an attribute map"); throw new \RuntimeException("Could not unset an attribute from an attribute map");
} }
} }

View File

@ -573,7 +573,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** /**
* @return string * @return string
*/ */
public function getNameTag(){ public function getNameTag() : string{
return $this->propertyManager->getString(self::DATA_NAMETAG); return $this->propertyManager->getString(self::DATA_NAMETAG);
} }
@ -595,21 +595,21 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** /**
* @param string $name * @param string $name
*/ */
public function setNameTag($name){ public function setNameTag(string $name) : void{
$this->propertyManager->setString(self::DATA_NAMETAG, $name); $this->propertyManager->setString(self::DATA_NAMETAG, $name);
} }
/** /**
* @param bool $value * @param bool $value
*/ */
public function setNameTagVisible(bool $value = true){ public function setNameTagVisible(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_CAN_SHOW_NAMETAG, $value); $this->setGenericFlag(self::DATA_FLAG_CAN_SHOW_NAMETAG, $value);
} }
/** /**
* @param bool $value * @param bool $value
*/ */
public function setNameTagAlwaysVisible(bool $value = true){ public function setNameTagAlwaysVisible(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_ALWAYS_SHOW_NAMETAG, $value); $this->setGenericFlag(self::DATA_FLAG_ALWAYS_SHOW_NAMETAG, $value);
} }
@ -623,7 +623,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** /**
* @param float $value * @param float $value
*/ */
public function setScale(float $value){ public function setScale(float $value) : void{
$multiplier = $value / $this->getScale(); $multiplier = $value / $this->getScale();
$this->width *= $multiplier; $this->width *= $multiplier;
@ -635,7 +635,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->propertyManager->setFloat(self::DATA_SCALE, $value); $this->propertyManager->setFloat(self::DATA_SCALE, $value);
} }
public function getBoundingBox(){ public function getBoundingBox() : AxisAlignedBB{
return $this->boundingBox; return $this->boundingBox;
} }
@ -656,7 +656,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return $this->getGenericFlag(self::DATA_FLAG_SNEAKING); return $this->getGenericFlag(self::DATA_FLAG_SNEAKING);
} }
public function setSneaking(bool $value = true){ public function setSneaking(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_SNEAKING, $value); $this->setGenericFlag(self::DATA_FLAG_SNEAKING, $value);
} }
@ -664,7 +664,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return $this->getGenericFlag(self::DATA_FLAG_SPRINTING); return $this->getGenericFlag(self::DATA_FLAG_SPRINTING);
} }
public function setSprinting(bool $value = true){ public function setSprinting(bool $value = true) : void{
if($value !== $this->isSprinting()){ if($value !== $this->isSprinting()){
$this->setGenericFlag(self::DATA_FLAG_SPRINTING, $value); $this->setGenericFlag(self::DATA_FLAG_SPRINTING, $value);
$attr = $this->attributeMap->getAttribute(Attribute::MOVEMENT_SPEED); $attr = $this->attributeMap->getAttribute(Attribute::MOVEMENT_SPEED);
@ -676,7 +676,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return $this->getGenericFlag(self::DATA_FLAG_IMMOBILE); return $this->getGenericFlag(self::DATA_FLAG_IMMOBILE);
} }
public function setImmobile(bool $value = true){ public function setImmobile(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_IMMOBILE, $value); $this->setGenericFlag(self::DATA_FLAG_IMMOBILE, $value);
} }
@ -698,9 +698,10 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** /**
* Sets whether the entity is able to climb climbable blocks. * Sets whether the entity is able to climb climbable blocks.
*
* @param bool $value * @param bool $value
*/ */
public function setCanClimb(bool $value = true){ public function setCanClimb(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_CAN_CLIMB, $value); $this->setGenericFlag(self::DATA_FLAG_CAN_CLIMB, $value);
} }
@ -718,7 +719,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* *
* @param bool $value * @param bool $value
*/ */
public function setCanClimbWalls(bool $value = true){ public function setCanClimbWalls(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_WALLCLIMBING, $value); $this->setGenericFlag(self::DATA_FLAG_WALLCLIMBING, $value);
} }
@ -726,7 +727,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* Returns the entity ID of the owning entity, or null if the entity doesn't have an owner. * Returns the entity ID of the owning entity, or null if the entity doesn't have an owner.
* @return int|null * @return int|null
*/ */
public function getOwningEntityId(){ public function getOwningEntityId() : ?int{
return $this->propertyManager->getLong(self::DATA_OWNER_EID); return $this->propertyManager->getLong(self::DATA_OWNER_EID);
} }
@ -734,7 +735,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* Returns the owning entity, or null if the entity was not found. * Returns the owning entity, or null if the entity was not found.
* @return Entity|null * @return Entity|null
*/ */
public function getOwningEntity(){ public function getOwningEntity() : ?Entity{
$eid = $this->getOwningEntityId(); $eid = $this->getOwningEntityId();
if($eid !== null){ if($eid !== null){
return $this->server->findEntity($eid, $this->level); return $this->server->findEntity($eid, $this->level);
@ -750,7 +751,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* *
* @throws \InvalidArgumentException if the supplied entity is not valid * @throws \InvalidArgumentException if the supplied entity is not valid
*/ */
public function setOwningEntity(Entity $owner = null){ public function setOwningEntity(?Entity $owner) : void{
if($owner === null){ if($owner === null){
$this->propertyManager->removeProperty(self::DATA_OWNER_EID); $this->propertyManager->removeProperty(self::DATA_OWNER_EID);
}elseif($owner->closed){ }elseif($owner->closed){
@ -764,7 +765,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* Returns the entity ID of the entity's target, or null if it doesn't have a target. * Returns the entity ID of the entity's target, or null if it doesn't have a target.
* @return int|null * @return int|null
*/ */
public function getTargetEntityId(){ public function getTargetEntityId() : ?int{
return $this->propertyManager->getLong(self::DATA_TARGET_EID); return $this->propertyManager->getLong(self::DATA_TARGET_EID);
} }
@ -774,7 +775,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* *
* @return Entity|null * @return Entity|null
*/ */
public function getTargetEntity(){ public function getTargetEntity() : ?Entity{
$eid = $this->getTargetEntityId(); $eid = $this->getTargetEntityId();
if($eid !== null){ if($eid !== null){
return $this->server->findEntity($eid, $this->level); return $this->server->findEntity($eid, $this->level);
@ -790,7 +791,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* *
* @throws \InvalidArgumentException if the target entity is not valid * @throws \InvalidArgumentException if the target entity is not valid
*/ */
public function setTargetEntity(Entity $target = null){ public function setTargetEntity(?Entity $target) : void{
if($target === null){ if($target === null){
$this->propertyManager->removeProperty(self::DATA_TARGET_EID); $this->propertyManager->removeProperty(self::DATA_TARGET_EID);
}elseif($target->closed){ }elseif($target->closed){
@ -823,7 +824,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* *
* @return string * @return string
*/ */
public function getSaveId(){ public function getSaveId() : string{
if(!isset(self::$saveNames[static::class])){ if(!isset(self::$saveNames[static::class])){
throw new \InvalidStateException("Entity is not registered"); throw new \InvalidStateException("Entity is not registered");
} }
@ -831,7 +832,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return current(self::$saveNames[static::class]); return current(self::$saveNames[static::class]);
} }
public function saveNBT(){ public function saveNBT() : void{
if(!($this instanceof Player)){ if(!($this instanceof Player)){
$this->namedtag->setString("id", $this->getSaveId(), true); $this->namedtag->setString("id", $this->getSaveId(), true);
@ -867,7 +868,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->namedtag->setByte("Invulnerable", $this->invulnerable ? 1 : 0); $this->namedtag->setByte("Invulnerable", $this->invulnerable ? 1 : 0);
} }
protected function initEntity(){ protected function initEntity() : void{
assert($this->namedtag instanceof CompoundTag); assert($this->namedtag instanceof CompoundTag);
if($this->namedtag->hasTag("CustomName", StringTag::class)){ if($this->namedtag->hasTag("CustomName", StringTag::class)){
@ -885,14 +886,14 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->scheduleUpdate(); $this->scheduleUpdate();
} }
protected function addAttributes(){ protected function addAttributes() : void{
} }
/** /**
* @param EntityDamageEvent $source * @param EntityDamageEvent $source
*/ */
public function attack(EntityDamageEvent $source){ public function attack(EntityDamageEvent $source) : void{
$this->server->getPluginManager()->callEvent($source); $this->server->getPluginManager()->callEvent($source);
if($source->isCancelled()){ if($source->isCancelled()){
return; return;
@ -906,7 +907,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** /**
* @param EntityRegainHealthEvent $source * @param EntityRegainHealthEvent $source
*/ */
public function heal(EntityRegainHealthEvent $source){ public function heal(EntityRegainHealthEvent $source) : void{
$this->server->getPluginManager()->callEvent($source); $this->server->getPluginManager()->callEvent($source);
if($source->isCancelled()){ if($source->isCancelled()){
return; return;
@ -915,7 +916,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->setHealth($this->getHealth() + $source->getAmount()); $this->setHealth($this->getHealth() + $source->getAmount());
} }
public function kill(){ public function kill() : void{
$this->health = 0; $this->health = 0;
$this->scheduleUpdate(); $this->scheduleUpdate();
} }
@ -946,7 +947,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* *
* @param float $amount * @param float $amount
*/ */
public function setHealth(float $amount){ public function setHealth(float $amount) : void{
if($amount == $this->health){ if($amount == $this->health){
return; return;
} }
@ -973,25 +974,25 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** /**
* @param int $amount * @param int $amount
*/ */
public function setMaxHealth(int $amount){ public function setMaxHealth(int $amount) : void{
$this->maxHealth = $amount; $this->maxHealth = $amount;
} }
/** /**
* @param EntityDamageEvent $type * @param EntityDamageEvent $type
*/ */
public function setLastDamageCause(EntityDamageEvent $type){ public function setLastDamageCause(EntityDamageEvent $type) : void{
$this->lastDamageCause = $type; $this->lastDamageCause = $type;
} }
/** /**
* @return EntityDamageEvent|null * @return EntityDamageEvent|null
*/ */
public function getLastDamageCause(){ public function getLastDamageCause() : ?EntityDamageEvent{
return $this->lastDamageCause; return $this->lastDamageCause;
} }
public function getAttributeMap(){ public function getAttributeMap() : AttributeMap{
return $this->attributeMap; return $this->attributeMap;
} }
@ -1041,7 +1042,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return $this->fireTicks > 0; return $this->fireTicks > 0;
} }
public function setOnFire(int $seconds){ public function setOnFire(int $seconds) : void{
$ticks = $seconds * 20; $ticks = $seconds * 20;
if($ticks > $this->fireTicks){ if($ticks > $this->fireTicks){
$this->fireTicks = $ticks; $this->fireTicks = $ticks;
@ -1064,7 +1065,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->fireTicks = $fireTicks; $this->fireTicks = $fireTicks;
} }
public function extinguish(){ public function extinguish() : void{
$this->fireTicks = 0; $this->fireTicks = 0;
$this->setGenericFlag(self::DATA_FLAG_ONFIRE, false); $this->setGenericFlag(self::DATA_FLAG_ONFIRE, false);
} }
@ -1096,7 +1097,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** /**
* Called to deal damage to entities when they are on fire. * Called to deal damage to entities when they are on fire.
*/ */
protected function dealFireDamage(){ protected function dealFireDamage() : void{
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1);
$this->attack($ev); $this->attack($ev);
} }
@ -1109,7 +1110,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return true; return true;
} }
protected function updateMovement(bool $teleport = false){ protected function updateMovement(bool $teleport = false) : void{
$diffPosition = ($this->x - $this->lastX) ** 2 + ($this->y - $this->lastY) ** 2 + ($this->z - $this->lastZ) ** 2; $diffPosition = ($this->x - $this->lastX) ** 2 + ($this->y - $this->lastY) ** 2 + ($this->z - $this->lastZ) ** 2;
$diffRotation = ($this->yaw - $this->lastYaw) ** 2 + ($this->pitch - $this->lastPitch) ** 2; $diffRotation = ($this->yaw - $this->lastYaw) ** 2 + ($this->pitch - $this->lastPitch) ** 2;
@ -1139,7 +1140,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return new Vector3($vector3->x, $vector3->y + $this->baseOffset, $vector3->z); return new Vector3($vector3->x, $vector3->y + $this->baseOffset, $vector3->z);
} }
protected function broadcastMovement(bool $teleport = false){ protected function broadcastMovement(bool $teleport = false) : void{
if($this->chunk !== null){ if($this->chunk !== null){
$pk = new MoveEntityPacket(); $pk = new MoveEntityPacket();
$pk->entityRuntimeId = $this->id; $pk->entityRuntimeId = $this->id;
@ -1153,7 +1154,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
} }
} }
protected function broadcastMotion(){ protected function broadcastMotion() : void{
if($this->chunk !== null){ if($this->chunk !== null){
$pk = new SetEntityMotionPacket(); $pk = new SetEntityMotionPacket();
$pk->entityRuntimeId = $this->id; $pk->entityRuntimeId = $this->id;
@ -1167,11 +1168,11 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return false; return false;
} }
protected function applyGravity(){ protected function applyGravity() : void{
$this->motionY -= $this->gravity; $this->motionY -= $this->gravity;
} }
protected function tryChangeMovement(){ protected function tryChangeMovement() : void{
$friction = 1 - $this->drag; $friction = 1 - $this->drag;
if($this->applyDragBeforeGravity()){ if($this->applyDragBeforeGravity()){
@ -1290,7 +1291,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** /**
* @return int|null * @return int|null
*/ */
public function getDirection(){ public function getDirection() : ?int{
$rotation = ($this->yaw - 90) % 360; $rotation = ($this->yaw - 90) % 360;
if($rotation < 0){ if($rotation < 0){
$rotation += 360.0; $rotation += 360.0;
@ -1388,7 +1389,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
//return !($this instanceof Player); //return !($this instanceof Player);
} }
final public function scheduleUpdate(){ final public function scheduleUpdate() : void{
$this->level->updateEntities[$this->id] = $this; $this->level->updateEntities[$this->id] = $this;
} }
@ -1403,7 +1404,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* *
* @param bool $value * @param bool $value
*/ */
final public function setForceMovementUpdate(bool $value = true){ final public function setForceMovementUpdate(bool $value = true) : void{
$this->forceMovementUpdate = $value; $this->forceMovementUpdate = $value;
$this->blocksAround = null; $this->blocksAround = null;
@ -1427,7 +1428,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return true; return true;
} }
public function resetFallDistance(){ public function resetFallDistance() : void{
$this->fallDistance = 0.0; $this->fallDistance = 0.0;
} }
@ -1435,7 +1436,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param float $distanceThisTick * @param float $distanceThisTick
* @param bool $onGround * @param bool $onGround
*/ */
protected function updateFallState(float $distanceThisTick, bool $onGround){ protected function updateFallState(float $distanceThisTick, bool $onGround) : void{
if($onGround){ if($onGround){
if($this->fallDistance > 0){ if($this->fallDistance > 0){
$this->fall($this->fallDistance); $this->fall($this->fallDistance);
@ -1451,7 +1452,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* *
* @param float $fallDistance * @param float $fallDistance
*/ */
public function fall(float $fallDistance){ public function fall(float $fallDistance) : void{
} }
@ -1459,7 +1460,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return $this->eyeHeight; return $this->eyeHeight;
} }
public function onCollideWithPlayer(Player $player){ public function onCollideWithPlayer(Player $player) : void{
} }
@ -1669,7 +1670,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
Timings::$entityMoveTimer->stopTiming(); Timings::$entityMoveTimer->stopTiming();
} }
protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz){ protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz) : void{
$this->isCollidedVertically = $movY != $dy; $this->isCollidedVertically = $movY != $dy;
$this->isCollidedHorizontally = ($movX != $dx or $movZ != $dz); $this->isCollidedHorizontally = ($movX != $dx or $movZ != $dz);
$this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically); $this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically);
@ -1716,7 +1717,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return true; return true;
} }
protected function checkBlockCollision(){ protected function checkBlockCollision() : void{
$vector = $this->temporalVector->setComponents(0, 0, 0); $vector = $this->temporalVector->setComponents(0, 0, 0);
foreach($this->getBlocksAround() as $block){ foreach($this->getBlocksAround() as $block){
@ -1765,7 +1766,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return true; return true;
} }
public function setRotation(float $yaw, float $pitch){ public function setRotation(float $yaw, float $pitch) : void{
$this->yaw = $yaw; $this->yaw = $yaw;
$this->pitch = $pitch; $this->pitch = $pitch;
$this->scheduleUpdate(); $this->scheduleUpdate();
@ -1781,7 +1782,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return false; return false;
} }
protected function checkChunks(){ protected function checkChunks() : void{
$chunkX = $this->getFloorX() >> 4; $chunkX = $this->getFloorX() >> 4;
$chunkZ = $this->getFloorZ() >> 4; $chunkZ = $this->getFloorZ() >> 4;
if($this->chunk === null or ($this->chunk->getX() !== $chunkX or $this->chunk->getZ() !== $chunkZ)){ if($this->chunk === null or ($this->chunk->getX() !== $chunkX or $this->chunk->getZ() !== $chunkZ)){
@ -1812,7 +1813,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
} }
} }
protected function resetLastMovements(){ protected function resetLastMovements() : void{
list($this->lastX, $this->lastY, $this->lastZ) = [$this->x, $this->y, $this->z]; list($this->lastX, $this->lastY, $this->lastZ) = [$this->x, $this->y, $this->z];
list($this->lastYaw, $this->lastPitch) = [$this->yaw, $this->pitch]; list($this->lastYaw, $this->lastPitch) = [$this->yaw, $this->pitch];
list($this->lastMotionX, $this->lastMotionY, $this->lastMotionZ) = [$this->motionX, $this->motionY, $this->motionZ]; list($this->lastMotionX, $this->lastMotionY, $this->lastMotionZ) = [$this->motionX, $this->motionY, $this->motionZ];
@ -1822,7 +1823,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return new Vector3($this->motionX, $this->motionY, $this->motionZ); return new Vector3($this->motionX, $this->motionY, $this->motionZ);
} }
public function setMotion(Vector3 $motion){ public function setMotion(Vector3 $motion) : bool{
if(!$this->justCreated){ if(!$this->justCreated){
$this->server->getPluginManager()->callEvent($ev = new EntityMotionEvent($this, $motion)); $this->server->getPluginManager()->callEvent($ev = new EntityMotionEvent($this, $motion));
if($ev->isCancelled()){ if($ev->isCancelled()){
@ -1852,7 +1853,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* *
* @return bool * @return bool
*/ */
public function teleport(Vector3 $pos, float $yaw = null, float $pitch = null) : bool{ public function teleport(Vector3 $pos, ?float $yaw = null, ?float $pitch = null) : bool{
if($pos instanceof Location){ if($pos instanceof Location){
$yaw = $yaw ?? $pos->yaw; $yaw = $yaw ?? $pos->yaw;
$pitch = $pitch ?? $pos->pitch; $pitch = $pitch ?? $pos->pitch;
@ -1937,7 +1938,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** /**
* @param Player $player * @param Player $player
*/ */
public function spawnTo(Player $player){ public function spawnTo(Player $player) : void{
if(!isset($this->hasSpawned[$player->getLoaderId()]) and $this->chunk !== null and isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])){ if(!isset($this->hasSpawned[$player->getLoaderId()]) and $this->chunk !== null and isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])){
$this->hasSpawned[$player->getLoaderId()] = $player; $this->hasSpawned[$player->getLoaderId()] = $player;
@ -1945,7 +1946,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
} }
} }
public function spawnToAll(){ public function spawnToAll() : void{
if($this->chunk === null or $this->closed){ if($this->chunk === null or $this->closed){
return; return;
} }
@ -1956,7 +1957,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
} }
} }
public function respawnToAll(){ public function respawnToAll() : void{
foreach($this->hasSpawned as $key => $player){ foreach($this->hasSpawned as $key => $player){
unset($this->hasSpawned[$key]); unset($this->hasSpawned[$key]);
$this->spawnTo($player); $this->spawnTo($player);
@ -1967,7 +1968,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param Player $player * @param Player $player
* @param bool $send * @param bool $send
*/ */
public function despawnFrom(Player $player, bool $send = true){ public function despawnFrom(Player $player, bool $send = true) : void{
if(isset($this->hasSpawned[$player->getLoaderId()])){ if(isset($this->hasSpawned[$player->getLoaderId()])){
if($send){ if($send){
$pk = new RemoveEntityPacket(); $pk = new RemoveEntityPacket();
@ -1978,7 +1979,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
} }
} }
public function despawnFromAll(){ public function despawnFromAll() : void{
foreach($this->hasSpawned as $player){ foreach($this->hasSpawned as $player){
$this->despawnFrom($player); $this->despawnFrom($player);
} }
@ -2008,7 +2009,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* *
* WARNING: Entities are unusable after this has been executed! * WARNING: Entities are unusable after this has been executed!
*/ */
public function close(){ public function close() : void{
if(!$this->closed){ if(!$this->closed){
$this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this)); $this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this));
$this->closed = true; $this->closed = true;
@ -2037,7 +2038,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param bool $value * @param bool $value
* @param int $propertyType * @param int $propertyType
*/ */
public function setDataFlag(int $propertyId, int $flagId, bool $value = true, int $propertyType = self::DATA_TYPE_LONG){ public function setDataFlag(int $propertyId, int $flagId, bool $value = true, int $propertyType = self::DATA_TYPE_LONG) : void{
if($this->getDataFlag($propertyId, $flagId) !== $value){ if($this->getDataFlag($propertyId, $flagId) !== $value){
$flags = (int) $this->propertyManager->getPropertyValue($propertyId, $propertyType); $flags = (int) $this->propertyManager->getPropertyValue($propertyId, $propertyType);
$flags ^= 1 << $flagId; $flags ^= 1 << $flagId;
@ -2071,7 +2072,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param int $flagId * @param int $flagId
* @param bool $value * @param bool $value
*/ */
public function setGenericFlag(int $flagId, bool $value = true){ public function setGenericFlag(int $flagId, bool $value = true) : void{
$this->setDataFlag(self::DATA_FLAGS, $flagId, $value, self::DATA_TYPE_LONG); $this->setDataFlag(self::DATA_FLAGS, $flagId, $value, self::DATA_TYPE_LONG);
} }
@ -2079,7 +2080,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param Player[]|Player $player * @param Player[]|Player $player
* @param array $data Properly formatted entity data, defaults to everything * @param array $data Properly formatted entity data, defaults to everything
*/ */
public function sendData($player, array $data = null){ public function sendData($player, ?array $data = null) : void{
if(!is_array($player)){ if(!is_array($player)){
$player = [$player]; $player = [$player];
} }

View File

@ -111,7 +111,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
/** /**
* @return UUID|null * @return UUID|null
*/ */
public function getUniqueId(){ public function getUniqueId() : ?UUID{
return $this->uuid; return $this->uuid;
} }
@ -151,14 +151,14 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
* *
* @param Player[]|null $targets * @param Player[]|null $targets
*/ */
public function sendSkin(array $targets = null) : void{ public function sendSkin(?array $targets = null) : void{
$pk = new PlayerSkinPacket(); $pk = new PlayerSkinPacket();
$pk->uuid = $this->getUniqueId(); $pk->uuid = $this->getUniqueId();
$pk->skin = $this->skin; $pk->skin = $this->skin;
$this->server->broadcastPacket($targets ?? $this->hasSpawned, $pk); $this->server->broadcastPacket($targets ?? $this->hasSpawned, $pk);
} }
public function jump(){ public function jump() : void{
parent::jump(); parent::jump();
if($this->isSprinting()){ if($this->isSprinting()){
$this->exhaust(0.8, PlayerExhaustEvent::CAUSE_SPRINT_JUMPING); $this->exhaust(0.8, PlayerExhaustEvent::CAUSE_SPRINT_JUMPING);
@ -179,7 +179,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function setFood(float $new){ public function setFood(float $new) : void{
$attr = $this->attributeMap->getAttribute(Attribute::HUNGER); $attr = $this->attributeMap->getAttribute(Attribute::HUNGER);
$old = $attr->getValue(); $old = $attr->getValue();
$attr->setValue($new); $attr->setValue($new);
@ -202,7 +202,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
return $this->attributeMap->getAttribute(Attribute::HUNGER)->getMaxValue(); return $this->attributeMap->getAttribute(Attribute::HUNGER)->getMaxValue();
} }
public function addFood(float $amount){ public function addFood(float $amount) : void{
$attr = $this->attributeMap->getAttribute(Attribute::HUNGER); $attr = $this->attributeMap->getAttribute(Attribute::HUNGER);
$amount += $attr->getValue(); $amount += $attr->getValue();
$amount = max(min($amount, $attr->getMaxValue()), $attr->getMinValue()); $amount = max(min($amount, $attr->getMaxValue()), $attr->getMinValue());
@ -230,11 +230,11 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function setSaturation(float $saturation){ public function setSaturation(float $saturation) : void{
$this->attributeMap->getAttribute(Attribute::SATURATION)->setValue($saturation); $this->attributeMap->getAttribute(Attribute::SATURATION)->setValue($saturation);
} }
public function addSaturation(float $amount){ public function addSaturation(float $amount) : void{
$attr = $this->attributeMap->getAttribute(Attribute::SATURATION); $attr = $this->attributeMap->getAttribute(Attribute::SATURATION);
$attr->setValue($attr->getValue() + $amount, true); $attr->setValue($attr->getValue() + $amount, true);
} }
@ -249,7 +249,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
* *
* @param float $exhaustion * @param float $exhaustion
*/ */
public function setExhaustion(float $exhaustion){ public function setExhaustion(float $exhaustion) : void{
$this->attributeMap->getAttribute(Attribute::EXHAUSTION)->setValue($exhaustion); $this->attributeMap->getAttribute(Attribute::EXHAUSTION)->setValue($exhaustion);
} }
@ -529,14 +529,14 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
return $this->inventory; return $this->inventory;
} }
public function getEnderChestInventory(){ public function getEnderChestInventory() : EnderChestInventory{
return $this->enderChestInventory; return $this->enderChestInventory;
} }
/** /**
* For Human entities which are not players, sets their properties such as nametag, skin and UUID from NBT. * For Human entities which are not players, sets their properties such as nametag, skin and UUID from NBT.
*/ */
protected function initHumanData(){ protected function initHumanData() : void{
if($this->namedtag->hasTag("NameTag", StringTag::class)){ if($this->namedtag->hasTag("NameTag", StringTag::class)){
$this->setNameTag($this->namedtag->getString("NameTag")); $this->setNameTag($this->namedtag->getString("NameTag"));
} }
@ -555,7 +555,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$this->uuid = UUID::fromData((string) $this->getId(), $this->skin->getSkinData(), $this->getNameTag()); $this->uuid = UUID::fromData((string) $this->getId(), $this->skin->getSkinData(), $this->getNameTag());
} }
protected function initEntity(){ protected function initEntity() : void{
parent::initEntity(); parent::initEntity();
$this->setPlayerFlag(self::DATA_PLAYER_FLAG_SLEEP, false); $this->setPlayerFlag(self::DATA_PLAYER_FLAG_SLEEP, false);
@ -607,7 +607,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
} }
} }
protected function addAttributes(){ protected function addAttributes() : void{
parent::addAttributes(); parent::addAttributes();
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::SATURATION)); $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::SATURATION));
@ -629,7 +629,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
return $hasUpdate; return $hasUpdate;
} }
public function doFoodTick(int $tickDiff = 1){ public function doFoodTick(int $tickDiff = 1) : void{
if($this->isAlive()){ if($this->isAlive()){
$food = $this->getFood(); $food = $this->getFood();
$health = $this->getHealth(); $health = $this->getHealth();
@ -681,7 +681,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
); );
} }
public function saveNBT(){ public function saveNBT() : void{
parent::saveNBT(); parent::saveNBT();
$this->namedtag->setInt("foodLevel", (int) $this->getFood(), true); $this->namedtag->setInt("foodLevel", (int) $this->getFood(), true);
@ -743,7 +743,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
} }
} }
public function spawnTo(Player $player){ public function spawnTo(Player $player) : void{
if($player !== $this){ if($player !== $this){
parent::spawnTo($player); parent::spawnTo($player);
} }
@ -776,7 +776,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
} }
} }
public function close(){ public function close() : void{
if(!$this->closed){ if(!$this->closed){
if($this->inventory !== null){ if($this->inventory !== null){
$this->inventory->removeAllViewers(true); $this->inventory->removeAllViewers(true);
@ -806,7 +806,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
* @param int $flagId * @param int $flagId
* @param bool $value * @param bool $value
*/ */
public function setPlayerFlag(int $flagId, bool $value = true){ public function setPlayerFlag(int $flagId, bool $value = true) : void{
$this->setDataFlag(self::DATA_PLAYER_FLAGS, $flagId, $value, self::DATA_TYPE_BYTE); $this->setDataFlag(self::DATA_PLAYER_FLAGS, $flagId, $value, self::DATA_TYPE_BYTE);
} }
} }

View File

@ -72,7 +72,7 @@ abstract class Living extends Entity implements Damageable{
abstract public function getName() : string; abstract public function getName() : string;
protected function initEntity(){ protected function initEntity() : void{
parent::initEntity(); parent::initEntity();
$this->armorInventory = new ArmorInventory($this); $this->armorInventory = new ArmorInventory($this);
@ -112,7 +112,7 @@ abstract class Living extends Entity implements Damageable{
} }
} }
protected function addAttributes(){ protected function addAttributes() : void{
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::HEALTH)); $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::HEALTH));
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::FOLLOW_RANGE)); $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::FOLLOW_RANGE));
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::KNOCKBACK_RESISTANCE)); $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::KNOCKBACK_RESISTANCE));
@ -121,7 +121,7 @@ abstract class Living extends Entity implements Damageable{
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::ABSORPTION)); $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::ABSORPTION));
} }
public function setHealth(float $amount){ public function setHealth(float $amount) : void{
$wasAlive = $this->isAlive(); $wasAlive = $this->isAlive();
parent::setHealth($amount); parent::setHealth($amount);
$this->attributeMap->getAttribute(Attribute::HEALTH)->setValue(ceil($this->getHealth()), true); $this->attributeMap->getAttribute(Attribute::HEALTH)->setValue(ceil($this->getHealth()), true);
@ -134,7 +134,7 @@ abstract class Living extends Entity implements Damageable{
return (int) $this->attributeMap->getAttribute(Attribute::HEALTH)->getMaxValue(); return (int) $this->attributeMap->getAttribute(Attribute::HEALTH)->getMaxValue();
} }
public function setMaxHealth(int $amount){ public function setMaxHealth(int $amount) : void{
$this->attributeMap->getAttribute(Attribute::HEALTH)->setMaxValue($amount); $this->attributeMap->getAttribute(Attribute::HEALTH)->setMaxValue($amount);
} }
@ -142,11 +142,11 @@ abstract class Living extends Entity implements Damageable{
return $this->attributeMap->getAttribute(Attribute::ABSORPTION)->getValue(); return $this->attributeMap->getAttribute(Attribute::ABSORPTION)->getValue();
} }
public function setAbsorption(float $absorption){ public function setAbsorption(float $absorption) : void{
$this->attributeMap->getAttribute(Attribute::ABSORPTION)->setValue($absorption); $this->attributeMap->getAttribute(Attribute::ABSORPTION)->setValue($absorption);
} }
public function saveNBT(){ public function saveNBT() : void{
parent::saveNBT(); parent::saveNBT();
$this->namedtag->setFloat("Health", $this->getHealth(), true); $this->namedtag->setFloat("Health", $this->getHealth(), true);
@ -186,7 +186,7 @@ abstract class Living extends Entity implements Damageable{
/** /**
* Removes all effects from the mob. * Removes all effects from the mob.
*/ */
public function removeAllEffects(){ public function removeAllEffects() : void{
foreach($this->effects as $effect){ foreach($this->effects as $effect){
$this->removeEffect($effect->getId()); $this->removeEffect($effect->getId());
} }
@ -197,7 +197,7 @@ abstract class Living extends Entity implements Damageable{
* *
* @param int $effectId * @param int $effectId
*/ */
public function removeEffect(int $effectId){ public function removeEffect(int $effectId) : void{
if(isset($this->effects[$effectId])){ if(isset($this->effects[$effectId])){
$effect = $this->effects[$effectId]; $effect = $this->effects[$effectId];
$this->server->getPluginManager()->callEvent($ev = new EntityEffectRemoveEvent($this, $effect)); $this->server->getPluginManager()->callEvent($ev = new EntityEffectRemoveEvent($this, $effect));
@ -221,7 +221,7 @@ abstract class Living extends Entity implements Damageable{
* *
* @return EffectInstance|null * @return EffectInstance|null
*/ */
public function getEffect(int $effectId){ public function getEffect(int $effectId) : ?EffectInstance{
return $this->effects[$effectId] ?? null; return $this->effects[$effectId] ?? null;
} }
@ -292,7 +292,7 @@ abstract class Living extends Entity implements Damageable{
/** /**
* Recalculates the mob's potion bubbles colour based on the active effects. * Recalculates the mob's potion bubbles colour based on the active effects.
*/ */
protected function recalculateEffectColor(){ protected function recalculateEffectColor() : void{
/** @var Color[] $colors */ /** @var Color[] $colors */
$colors = []; $colors = [];
$ambient = true; $ambient = true;
@ -323,7 +323,7 @@ abstract class Living extends Entity implements Damageable{
* Sends the mob's potion effects to the specified player. * Sends the mob's potion effects to the specified player.
* @param Player $player * @param Player $player
*/ */
public function sendPotionEffects(Player $player){ public function sendPotionEffects(Player $player) : void{
foreach($this->effects as $effect){ foreach($this->effects as $effect){
$pk = new MobEffectPacket(); $pk = new MobEffectPacket();
$pk->entityRuntimeId = $this->id; $pk->entityRuntimeId = $this->id;
@ -374,13 +374,13 @@ abstract class Living extends Entity implements Damageable{
/** /**
* Called when the entity jumps from the ground. This method adds upwards velocity to the entity. * Called when the entity jumps from the ground. This method adds upwards velocity to the entity.
*/ */
public function jump(){ public function jump() : void{
if($this->onGround){ if($this->onGround){
$this->motionY = $this->getJumpVelocity(); //Y motion should already be 0 if we're jumping from the ground. $this->motionY = $this->getJumpVelocity(); //Y motion should already be 0 if we're jumping from the ground.
} }
} }
public function fall(float $fallDistance){ public function fall(float $fallDistance) : void{
$damage = ceil($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getEffectLevel() : 0)); $damage = ceil($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getEffectLevel() : 0));
if($damage > 0){ if($damage > 0){
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage);
@ -427,7 +427,7 @@ abstract class Living extends Entity implements Damageable{
return $this->armorInventory; return $this->armorInventory;
} }
public function setOnFire(int $seconds){ public function setOnFire(int $seconds) : void{
parent::setOnFire($seconds - (int) min($seconds, $seconds * $this->getHighestArmorEnchantmentLevel(Enchantment::FIRE_PROTECTION) * 0.15)); parent::setOnFire($seconds - (int) min($seconds, $seconds * $this->getHighestArmorEnchantmentLevel(Enchantment::FIRE_PROTECTION) * 0.15));
} }
@ -492,7 +492,7 @@ abstract class Living extends Entity implements Damageable{
$this->armorInventory->setContents($armor); $this->armorInventory->setContents($armor);
} }
public function attack(EntityDamageEvent $source){ public function attack(EntityDamageEvent $source) : void{
if($this->attackTime > 0 or $this->noDamageTicks > 0){ if($this->attackTime > 0 or $this->noDamageTicks > 0){
$lastCause = $this->getLastDamageCause(); $lastCause = $this->getLastDamageCause();
if($lastCause !== null and $lastCause->getDamage() >= $source->getDamage()){ if($lastCause !== null and $lastCause->getDamage() >= $source->getDamage()){
@ -559,7 +559,7 @@ abstract class Living extends Entity implements Damageable{
$this->broadcastEntityEvent(EntityEventPacket::HURT_ANIMATION); $this->broadcastEntityEvent(EntityEventPacket::HURT_ANIMATION);
} }
public function knockBack(Entity $attacker, float $damage, float $x, float $z, float $base = 0.4){ public function knockBack(Entity $attacker, float $damage, float $x, float $z, float $base = 0.4) : void{
$f = sqrt($x * $x + $z * $z); $f = sqrt($x * $x + $z * $z);
if($f <= 0){ if($f <= 0){
return; return;
@ -583,12 +583,12 @@ abstract class Living extends Entity implements Damageable{
$this->setMotion($motion); $this->setMotion($motion);
} }
public function kill(){ public function kill() : void{
parent::kill(); parent::kill();
$this->onDeath(); $this->onDeath();
} }
protected function onDeath(){ protected function onDeath() : void{
$this->server->getPluginManager()->callEvent($ev = new EntityDeathEvent($this, $this->getDrops())); $this->server->getPluginManager()->callEvent($ev = new EntityDeathEvent($this, $this->getDrops()));
foreach($ev->getDrops() as $item){ foreach($ev->getDrops() as $item){
$this->getLevel()->dropItem($this, $item); $this->getLevel()->dropItem($this, $item);
@ -649,7 +649,7 @@ abstract class Living extends Entity implements Damageable{
return $hasUpdate; return $hasUpdate;
} }
protected function doEffectsTick(int $tickDiff = 1){ protected function doEffectsTick(int $tickDiff = 1) : void{
foreach($this->effects as $instance){ foreach($this->effects as $instance){
$type = $instance->getType(); $type = $instance->getType();
if($type->canTick($instance)){ if($type->canTick($instance)){
@ -666,7 +666,7 @@ abstract class Living extends Entity implements Damageable{
* Ticks the entity's air supply when it cannot breathe. * Ticks the entity's air supply when it cannot breathe.
* @param int $tickDiff * @param int $tickDiff
*/ */
protected function doAirSupplyTick(int $tickDiff){ protected function doAirSupplyTick(int $tickDiff) : void{
if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(Enchantment::RESPIRATION)) <= 0 or if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(Enchantment::RESPIRATION)) <= 0 or
lcg_value() <= (1 / ($respirationLevel + 1)) lcg_value() <= (1 / ($respirationLevel + 1))
){ ){
@ -703,7 +703,7 @@ abstract class Living extends Entity implements Damageable{
* *
* @param bool $value * @param bool $value
*/ */
public function setBreathing(bool $value = true){ public function setBreathing(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_BREATHING, $value); $this->setGenericFlag(self::DATA_FLAG_BREATHING, $value);
} }
@ -721,7 +721,7 @@ abstract class Living extends Entity implements Damageable{
* Sets the number of air ticks left in the entity's air supply. * Sets the number of air ticks left in the entity's air supply.
* @param int $ticks * @param int $ticks
*/ */
public function setAirSupplyTicks(int $ticks){ public function setAirSupplyTicks(int $ticks) : void{
$this->propertyManager->setShort(self::DATA_AIR, $ticks); $this->propertyManager->setShort(self::DATA_AIR, $ticks);
} }
@ -737,7 +737,7 @@ abstract class Living extends Entity implements Damageable{
* Sets the maximum amount of air ticks the air supply can hold. * Sets the maximum amount of air ticks the air supply can hold.
* @param int $ticks * @param int $ticks
*/ */
public function setMaxAirSupplyTicks(int $ticks){ public function setMaxAirSupplyTicks(int $ticks) : void{
$this->propertyManager->setShort(self::DATA_MAX_AIR, $ticks); $this->propertyManager->setShort(self::DATA_MAX_AIR, $ticks);
} }
@ -745,7 +745,7 @@ abstract class Living extends Entity implements Damageable{
* Called when the entity's air supply ticks reaches -20 or lower. The entity will usually take damage at this point * Called when the entity's air supply ticks reaches -20 or lower. The entity will usually take damage at this point
* and then the supply is reset to 0, so this method will be called roughly every second. * and then the supply is reset to 0, so this method will be called roughly every second.
*/ */
public function onAirExpired(){ public function onAirExpired() : void{
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
$this->attack($ev); $this->attack($ev);
} }
@ -815,7 +815,7 @@ abstract class Living extends Entity implements Damageable{
* *
* @return Block|null * @return Block|null
*/ */
public function getTargetBlock(int $maxDistance, array $transparent = []){ public function getTargetBlock(int $maxDistance, array $transparent = []) : ?Block{
$line = $this->getLineOfSight($maxDistance, 1, $transparent); $line = $this->getLineOfSight($maxDistance, 1, $transparent);
if(!empty($line)){ if(!empty($line)){
return array_shift($line); return array_shift($line);
@ -849,7 +849,7 @@ abstract class Living extends Entity implements Damageable{
$this->armorInventory->sendContents($player); $this->armorInventory->sendContents($player);
} }
public function close(){ public function close() : void{
if(!$this->closed){ if(!$this->closed){
if($this->armorInventory !== null){ if($this->armorInventory !== null){
$this->armorInventory->removeAllViewers(true); $this->armorInventory->removeAllViewers(true);

View File

@ -42,7 +42,7 @@ class Squid extends WaterAnimal{
private $switchDirectionTicker = 0; private $switchDirectionTicker = 0;
public function initEntity(){ public function initEntity() : void{
$this->setMaxHealth(10); $this->setMaxHealth(10);
parent::initEntity(); parent::initEntity();
} }
@ -51,7 +51,7 @@ class Squid extends WaterAnimal{
return "Squid"; return "Squid";
} }
public function attack(EntityDamageEvent $source){ public function attack(EntityDamageEvent $source) : void{
parent::attack($source); parent::attack($source);
if($source->isCancelled()){ if($source->isCancelled()){
return; return;
@ -115,7 +115,7 @@ class Squid extends WaterAnimal{
return $hasUpdate; return $hasUpdate;
} }
protected function applyGravity(){ protected function applyGravity() : void{
if(!$this->isInsideOfWater()){ if(!$this->isInsideOfWater()){
parent::applyGravity(); parent::applyGravity();
} }

View File

@ -39,7 +39,7 @@ class Villager extends Creature implements NPC, Ageable{
return "Villager"; return "Villager";
} }
protected function initEntity(){ protected function initEntity() : void{
parent::initEntity(); parent::initEntity();
/** @var int $profession */ /** @var int $profession */
@ -52,7 +52,7 @@ class Villager extends Creature implements NPC, Ageable{
$this->setProfession($profession); $this->setProfession($profession);
} }
public function saveNBT(){ public function saveNBT() : void{
parent::saveNBT(); parent::saveNBT();
$this->namedtag->setInt("Profession", $this->getProfession()); $this->namedtag->setInt("Profession", $this->getProfession());
} }
@ -62,7 +62,7 @@ class Villager extends Creature implements NPC, Ageable{
* *
* @param int $profession * @param int $profession
*/ */
public function setProfession(int $profession){ public function setProfession(int $profession) : void{
$this->propertyManager->setInt(self::DATA_VARIANT, $profession); $this->propertyManager->setInt(self::DATA_VARIANT, $profession);
} }

View File

@ -35,7 +35,7 @@ abstract class WaterAnimal extends Creature implements Ageable{
return $this->isInsideOfWater(); return $this->isInsideOfWater();
} }
public function onAirExpired(){ public function onAirExpired() : void{
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 2); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 2);
$this->attack($ev); $this->attack($ev);
} }

View File

@ -100,7 +100,7 @@ class ExperienceOrb extends Entity{
*/ */
protected $targetPlayerRuntimeId = null; protected $targetPlayerRuntimeId = null;
protected function initEntity(){ protected function initEntity() : void{
parent::initEntity(); parent::initEntity();
$this->age = $this->namedtag->getShort("Age", 0); $this->age = $this->namedtag->getShort("Age", 0);
@ -115,7 +115,7 @@ class ExperienceOrb extends Entity{
$this->setXpValue($value); $this->setXpValue($value);
} }
public function saveNBT(){ public function saveNBT() : void{
parent::saveNBT(); parent::saveNBT();
$this->namedtag->setShort("Age", $this->age); $this->namedtag->setShort("Age", $this->age);
@ -210,7 +210,7 @@ class ExperienceOrb extends Entity{
return $hasUpdate; return $hasUpdate;
} }
protected function tryChangeMovement(){ protected function tryChangeMovement() : void{
$this->checkObstruction($this->x, $this->y, $this->z); $this->checkObstruction($this->x, $this->y, $this->z);
parent::tryChangeMovement(); parent::tryChangeMovement();
} }

View File

@ -50,7 +50,7 @@ class FallingBlock extends Entity{
public $canCollide = false; public $canCollide = false;
protected function initEntity(){ protected function initEntity() : void{
parent::initEntity(); parent::initEntity();
$blockId = 0; $blockId = 0;
@ -83,7 +83,7 @@ class FallingBlock extends Entity{
return false; return false;
} }
public function attack(EntityDamageEvent $source){ public function attack(EntityDamageEvent $source) : void{
if($source->getCause() === EntityDamageEvent::CAUSE_VOID){ if($source->getCause() === EntityDamageEvent::CAUSE_VOID){
parent::attack($source); parent::attack($source);
} }
@ -126,15 +126,15 @@ class FallingBlock extends Entity{
return $hasUpdate; return $hasUpdate;
} }
public function getBlock(){ public function getBlock() : int{
return $this->block->getId(); return $this->block->getId();
} }
public function getDamage(){ public function getDamage() : int{
return $this->block->getDamage(); return $this->block->getDamage();
} }
public function saveNBT(){ public function saveNBT() : void{
$this->namedtag->setInt("TileID", $this->block->getId(), true); $this->namedtag->setInt("TileID", $this->block->getId(), true);
$this->namedtag->setByte("Data", $this->block->getDamage()); $this->namedtag->setByte("Data", $this->block->getDamage());
} }

View File

@ -53,7 +53,7 @@ class ItemEntity extends Entity{
public $canCollide = false; public $canCollide = false;
protected function initEntity(){ protected function initEntity() : void{
parent::initEntity(); parent::initEntity();
$this->setMaxHealth(5); $this->setMaxHealth(5);
@ -106,7 +106,7 @@ class ItemEntity extends Entity{
return $hasUpdate; return $hasUpdate;
} }
protected function tryChangeMovement(){ protected function tryChangeMovement() : void{
$this->checkObstruction($this->x, $this->y, $this->z); $this->checkObstruction($this->x, $this->y, $this->z);
parent::tryChangeMovement(); parent::tryChangeMovement();
} }
@ -115,7 +115,7 @@ class ItemEntity extends Entity{
return true; return true;
} }
public function saveNBT(){ public function saveNBT() : void{
parent::saveNBT(); parent::saveNBT();
$this->namedtag->setTag($this->item->nbtSerialize(-1, "Item")); $this->namedtag->setTag($this->item->nbtSerialize(-1, "Item"));
$this->namedtag->setShort("Health", (int) $this->getHealth()); $this->namedtag->setShort("Health", (int) $this->getHealth());
@ -154,7 +154,7 @@ class ItemEntity extends Entity{
/** /**
* @param int $delay * @param int $delay
*/ */
public function setPickupDelay(int $delay){ public function setPickupDelay(int $delay) : void{
$this->pickupDelay = $delay; $this->pickupDelay = $delay;
} }
@ -168,7 +168,7 @@ class ItemEntity extends Entity{
/** /**
* @param string $owner * @param string $owner
*/ */
public function setOwner(string $owner){ public function setOwner(string $owner) : void{
$this->owner = $owner; $this->owner = $owner;
} }
@ -182,7 +182,7 @@ class ItemEntity extends Entity{
/** /**
* @param string $thrower * @param string $thrower
*/ */
public function setThrower(string $thrower){ public function setThrower(string $thrower) : void{
$this->thrower = $thrower; $this->thrower = $thrower;
} }
@ -197,7 +197,7 @@ class ItemEntity extends Entity{
$player->dataPacket($pk); $player->dataPacket($pk);
} }
public function onCollideWithPlayer(Player $player){ public function onCollideWithPlayer(Player $player) : void{
if($this->getPickupDelay() > 0){ if($this->getPickupDelay() > 0){
return; return;
} }

View File

@ -70,13 +70,13 @@ class Painting extends Entity{
parent::__construct($level, $nbt); parent::__construct($level, $nbt);
} }
protected function initEntity(){ protected function initEntity() : void{
$this->setMaxHealth(1); $this->setMaxHealth(1);
$this->setHealth(1); $this->setHealth(1);
parent::initEntity(); parent::initEntity();
} }
public function saveNBT(){ public function saveNBT() : void{
parent::saveNBT(); parent::saveNBT();
$this->namedtag->setInt("TileX", (int) $this->blockIn->x); $this->namedtag->setInt("TileX", (int) $this->blockIn->x);
$this->namedtag->setInt("TileY", (int) $this->blockIn->y); $this->namedtag->setInt("TileY", (int) $this->blockIn->y);
@ -86,7 +86,7 @@ class Painting extends Entity{
$this->namedtag->setByte("Direction", (int) $this->direction); //Save both for full compatibility $this->namedtag->setByte("Direction", (int) $this->direction); //Save both for full compatibility
} }
public function kill(){ public function kill() : void{
parent::kill(); parent::kill();
$drops = true; $drops = true;
@ -138,7 +138,7 @@ class Painting extends Entity{
return false; return false;
} }
protected function updateMovement(bool $teleport = false){ protected function updateMovement(bool $teleport = false) : void{
} }
@ -166,7 +166,7 @@ class Painting extends Entity{
return PaintingMotive::getMotiveByName($this->motive); return PaintingMotive::getMotiveByName($this->motive);
} }
public function getDirection() : int{ public function getDirection() : ?int{
return $this->direction; return $this->direction;
} }

View File

@ -47,13 +47,13 @@ class PrimedTNT extends Entity implements Explosive{
public $canCollide = false; public $canCollide = false;
public function attack(EntityDamageEvent $source){ public function attack(EntityDamageEvent $source) : void{
if($source->getCause() === EntityDamageEvent::CAUSE_VOID){ if($source->getCause() === EntityDamageEvent::CAUSE_VOID){
parent::attack($source); parent::attack($source);
} }
} }
protected function initEntity(){ protected function initEntity() : void{
parent::initEntity(); parent::initEntity();
if($this->namedtag->hasTag("Fuse", ShortTag::class)){ if($this->namedtag->hasTag("Fuse", ShortTag::class)){
@ -73,7 +73,7 @@ class PrimedTNT extends Entity implements Explosive{
return false; return false;
} }
public function saveNBT(){ public function saveNBT() : void{
parent::saveNBT(); parent::saveNBT();
$this->namedtag->setShort("Fuse", $this->fuse, true); //older versions incorrectly saved this as a byte $this->namedtag->setShort("Fuse", $this->fuse, true); //older versions incorrectly saved this as a byte
} }
@ -101,7 +101,7 @@ class PrimedTNT extends Entity implements Explosive{
return $hasUpdate or $this->fuse >= 0; return $hasUpdate or $this->fuse >= 0;
} }
public function explode(){ public function explode() : void{
$this->server->getPluginManager()->callEvent($ev = new ExplosionPrimeEvent($this, 4)); $this->server->getPluginManager()->callEvent($ev = new ExplosionPrimeEvent($this, 4));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){

View File

@ -48,7 +48,7 @@ class Arrow extends Projectile{
protected $damage = 2; protected $damage = 2;
public function __construct(Level $level, CompoundTag $nbt, Entity $shootingEntity = null, bool $critical = false){ public function __construct(Level $level, CompoundTag $nbt, ?Entity $shootingEntity = null, bool $critical = false){
parent::__construct($level, $nbt, $shootingEntity); parent::__construct($level, $nbt, $shootingEntity);
$this->setCritical($critical); $this->setCritical($critical);
} }
@ -57,7 +57,7 @@ class Arrow extends Projectile{
return $this->getGenericFlag(self::DATA_FLAG_CRITICAL); return $this->getGenericFlag(self::DATA_FLAG_CRITICAL);
} }
public function setCritical(bool $value = true){ public function setCritical(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_CRITICAL, $value); $this->setGenericFlag(self::DATA_FLAG_CRITICAL, $value);
} }
@ -95,7 +95,7 @@ class Arrow extends Projectile{
$this->broadcastEntityEvent(EntityEventPacket::ARROW_SHAKE, 7); //7 ticks $this->broadcastEntityEvent(EntityEventPacket::ARROW_SHAKE, 7); //7 ticks
} }
public function onCollideWithPlayer(Player $player){ public function onCollideWithPlayer(Player $player) : void{
if($this->blockHit === null){ if($this->blockHit === null){
return; return;
} }

View File

@ -55,20 +55,20 @@ abstract class Projectile extends Entity{
/** @var int|null */ /** @var int|null */
protected $blockHitData; protected $blockHitData;
public function __construct(Level $level, CompoundTag $nbt, Entity $shootingEntity = null){ public function __construct(Level $level, CompoundTag $nbt, ?Entity $shootingEntity = null){
parent::__construct($level, $nbt); parent::__construct($level, $nbt);
if($shootingEntity !== null){ if($shootingEntity !== null){
$this->setOwningEntity($shootingEntity); $this->setOwningEntity($shootingEntity);
} }
} }
public function attack(EntityDamageEvent $source){ public function attack(EntityDamageEvent $source) : void{
if($source->getCause() === EntityDamageEvent::CAUSE_VOID){ if($source->getCause() === EntityDamageEvent::CAUSE_VOID){
parent::attack($source); parent::attack($source);
} }
} }
protected function initEntity(){ protected function initEntity() : void{
parent::initEntity(); parent::initEntity();
$this->setMaxHealth(1); $this->setMaxHealth(1);
@ -120,7 +120,7 @@ abstract class Projectile extends Entity{
return (int) ceil(sqrt($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2) * $this->damage); return (int) ceil(sqrt($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2) * $this->damage);
} }
public function saveNBT(){ public function saveNBT() : void{
parent::saveNBT(); parent::saveNBT();
$this->namedtag->setShort("Age", $this->age); $this->namedtag->setShort("Age", $this->age);

View File

@ -42,13 +42,13 @@ class SplashPotion extends Throwable{
protected $gravity = 0.05; protected $gravity = 0.05;
protected $drag = 0.01; protected $drag = 0.01;
protected function initEntity(){ protected function initEntity() : void{
parent::initEntity(); parent::initEntity();
$this->setPotionId($this->namedtag->getShort("PotionId", 0)); $this->setPotionId($this->namedtag->getShort("PotionId", 0));
} }
public function saveNBT(){ public function saveNBT() : void{
parent::saveNBT(); parent::saveNBT();
$this->namedtag->setShort("PotionId", $this->getPotionId()); $this->namedtag->setShort("PotionId", $this->getPotionId());
} }