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

@ -573,7 +573,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/**
* @return string
*/
public function getNameTag(){
public function getNameTag() : string{
return $this->propertyManager->getString(self::DATA_NAMETAG);
}
@ -595,21 +595,21 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/**
* @param string $name
*/
public function setNameTag($name){
public function setNameTag(string $name) : void{
$this->propertyManager->setString(self::DATA_NAMETAG, $name);
}
/**
* @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);
}
/**
* @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);
}
@ -623,7 +623,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/**
* @param float $value
*/
public function setScale(float $value){
public function setScale(float $value) : void{
$multiplier = $value / $this->getScale();
$this->width *= $multiplier;
@ -635,7 +635,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->propertyManager->setFloat(self::DATA_SCALE, $value);
}
public function getBoundingBox(){
public function getBoundingBox() : AxisAlignedBB{
return $this->boundingBox;
}
@ -656,7 +656,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
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);
}
@ -664,7 +664,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return $this->getGenericFlag(self::DATA_FLAG_SPRINTING);
}
public function setSprinting(bool $value = true){
public function setSprinting(bool $value = true) : void{
if($value !== $this->isSprinting()){
$this->setGenericFlag(self::DATA_FLAG_SPRINTING, $value);
$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);
}
public function setImmobile(bool $value = true){
public function setImmobile(bool $value = true) : void{
$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.
*
* @param bool $value
*/
public function setCanClimb(bool $value = true){
public function setCanClimb(bool $value = true) : void{
$this->setGenericFlag(self::DATA_FLAG_CAN_CLIMB, $value);
}
@ -718,7 +719,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
*
* @param bool $value
*/
public function setCanClimbWalls(bool $value = true){
public function setCanClimbWalls(bool $value = true) : void{
$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.
* @return int|null
*/
public function getOwningEntityId(){
public function getOwningEntityId() : ?int{
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.
* @return Entity|null
*/
public function getOwningEntity(){
public function getOwningEntity() : ?Entity{
$eid = $this->getOwningEntityId();
if($eid !== null){
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
*/
public function setOwningEntity(Entity $owner = null){
public function setOwningEntity(?Entity $owner) : void{
if($owner === null){
$this->propertyManager->removeProperty(self::DATA_OWNER_EID);
}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.
* @return int|null
*/
public function getTargetEntityId(){
public function getTargetEntityId() : ?int{
return $this->propertyManager->getLong(self::DATA_TARGET_EID);
}
@ -774,7 +775,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
*
* @return Entity|null
*/
public function getTargetEntity(){
public function getTargetEntity() : ?Entity{
$eid = $this->getTargetEntityId();
if($eid !== null){
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
*/
public function setTargetEntity(Entity $target = null){
public function setTargetEntity(?Entity $target) : void{
if($target === null){
$this->propertyManager->removeProperty(self::DATA_TARGET_EID);
}elseif($target->closed){
@ -823,7 +824,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
*
* @return string
*/
public function getSaveId(){
public function getSaveId() : string{
if(!isset(self::$saveNames[static::class])){
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]);
}
public function saveNBT(){
public function saveNBT() : void{
if(!($this instanceof Player)){
$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);
}
protected function initEntity(){
protected function initEntity() : void{
assert($this->namedtag instanceof CompoundTag);
if($this->namedtag->hasTag("CustomName", StringTag::class)){
@ -885,14 +886,14 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->scheduleUpdate();
}
protected function addAttributes(){
protected function addAttributes() : void{
}
/**
* @param EntityDamageEvent $source
*/
public function attack(EntityDamageEvent $source){
public function attack(EntityDamageEvent $source) : void{
$this->server->getPluginManager()->callEvent($source);
if($source->isCancelled()){
return;
@ -906,7 +907,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/**
* @param EntityRegainHealthEvent $source
*/
public function heal(EntityRegainHealthEvent $source){
public function heal(EntityRegainHealthEvent $source) : void{
$this->server->getPluginManager()->callEvent($source);
if($source->isCancelled()){
return;
@ -915,7 +916,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->setHealth($this->getHealth() + $source->getAmount());
}
public function kill(){
public function kill() : void{
$this->health = 0;
$this->scheduleUpdate();
}
@ -946,7 +947,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
*
* @param float $amount
*/
public function setHealth(float $amount){
public function setHealth(float $amount) : void{
if($amount == $this->health){
return;
}
@ -973,25 +974,25 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/**
* @param int $amount
*/
public function setMaxHealth(int $amount){
public function setMaxHealth(int $amount) : void{
$this->maxHealth = $amount;
}
/**
* @param EntityDamageEvent $type
*/
public function setLastDamageCause(EntityDamageEvent $type){
public function setLastDamageCause(EntityDamageEvent $type) : void{
$this->lastDamageCause = $type;
}
/**
* @return EntityDamageEvent|null
*/
public function getLastDamageCause(){
public function getLastDamageCause() : ?EntityDamageEvent{
return $this->lastDamageCause;
}
public function getAttributeMap(){
public function getAttributeMap() : AttributeMap{
return $this->attributeMap;
}
@ -1041,7 +1042,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return $this->fireTicks > 0;
}
public function setOnFire(int $seconds){
public function setOnFire(int $seconds) : void{
$ticks = $seconds * 20;
if($ticks > $this->fireTicks){
$this->fireTicks = $ticks;
@ -1064,7 +1065,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->fireTicks = $fireTicks;
}
public function extinguish(){
public function extinguish() : void{
$this->fireTicks = 0;
$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.
*/
protected function dealFireDamage(){
protected function dealFireDamage() : void{
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1);
$this->attack($ev);
}
@ -1109,7 +1110,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
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;
$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);
}
protected function broadcastMovement(bool $teleport = false){
protected function broadcastMovement(bool $teleport = false) : void{
if($this->chunk !== null){
$pk = new MoveEntityPacket();
$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){
$pk = new SetEntityMotionPacket();
$pk->entityRuntimeId = $this->id;
@ -1167,11 +1168,11 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return false;
}
protected function applyGravity(){
protected function applyGravity() : void{
$this->motionY -= $this->gravity;
}
protected function tryChangeMovement(){
protected function tryChangeMovement() : void{
$friction = 1 - $this->drag;
if($this->applyDragBeforeGravity()){
@ -1290,7 +1291,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/**
* @return int|null
*/
public function getDirection(){
public function getDirection() : ?int{
$rotation = ($this->yaw - 90) % 360;
if($rotation < 0){
$rotation += 360.0;
@ -1388,7 +1389,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
//return !($this instanceof Player);
}
final public function scheduleUpdate(){
final public function scheduleUpdate() : void{
$this->level->updateEntities[$this->id] = $this;
}
@ -1403,7 +1404,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
*
* @param bool $value
*/
final public function setForceMovementUpdate(bool $value = true){
final public function setForceMovementUpdate(bool $value = true) : void{
$this->forceMovementUpdate = $value;
$this->blocksAround = null;
@ -1427,7 +1428,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return true;
}
public function resetFallDistance(){
public function resetFallDistance() : void{
$this->fallDistance = 0.0;
}
@ -1435,7 +1436,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param float $distanceThisTick
* @param bool $onGround
*/
protected function updateFallState(float $distanceThisTick, bool $onGround){
protected function updateFallState(float $distanceThisTick, bool $onGround) : void{
if($onGround){
if($this->fallDistance > 0){
$this->fall($this->fallDistance);
@ -1451,7 +1452,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
*
* @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;
}
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();
}
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->isCollidedHorizontally = ($movX != $dx or $movZ != $dz);
$this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically);
@ -1716,7 +1717,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return true;
}
protected function checkBlockCollision(){
protected function checkBlockCollision() : void{
$vector = $this->temporalVector->setComponents(0, 0, 0);
foreach($this->getBlocksAround() as $block){
@ -1765,7 +1766,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return true;
}
public function setRotation(float $yaw, float $pitch){
public function setRotation(float $yaw, float $pitch) : void{
$this->yaw = $yaw;
$this->pitch = $pitch;
$this->scheduleUpdate();
@ -1781,7 +1782,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return false;
}
protected function checkChunks(){
protected function checkChunks() : void{
$chunkX = $this->getFloorX() >> 4;
$chunkZ = $this->getFloorZ() >> 4;
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->lastYaw, $this->lastPitch) = [$this->yaw, $this->pitch];
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);
}
public function setMotion(Vector3 $motion){
public function setMotion(Vector3 $motion) : bool{
if(!$this->justCreated){
$this->server->getPluginManager()->callEvent($ev = new EntityMotionEvent($this, $motion));
if($ev->isCancelled()){
@ -1852,7 +1853,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
*
* @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){
$yaw = $yaw ?? $pos->yaw;
$pitch = $pitch ?? $pos->pitch;
@ -1937,7 +1938,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/**
* @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())])){
$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){
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){
unset($this->hasSpawned[$key]);
$this->spawnTo($player);
@ -1967,7 +1968,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param Player $player
* @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($send){
$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){
$this->despawnFrom($player);
}
@ -2008,7 +2009,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
*
* WARNING: Entities are unusable after this has been executed!
*/
public function close(){
public function close() : void{
if(!$this->closed){
$this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this));
$this->closed = true;
@ -2037,7 +2038,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param bool $value
* @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){
$flags = (int) $this->propertyManager->getPropertyValue($propertyId, $propertyType);
$flags ^= 1 << $flagId;
@ -2071,7 +2072,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param int $flagId
* @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);
}
@ -2079,7 +2080,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
* @param Player[]|Player $player
* @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)){
$player = [$player];
}