Removed obsolete parameters from Entity->attack() and Entity->heal()

This commit is contained in:
Dylan K. Taylor 2017-08-21 13:18:39 +01:00
parent b62597fe63
commit 456ddd3fb3
15 changed files with 40 additions and 44 deletions

View File

@ -3715,7 +3715,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
} }
public function attack($damage, EntityDamageEvent $source){ public function attack(EntityDamageEvent $source){
if(!$this->isAlive()){ if(!$this->isAlive()){
return; return;
} }
@ -3730,7 +3730,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$source->setCancelled(); $source->setCancelled();
} }
parent::attack($damage, $source); parent::attack($source);
if($source->isCancelled()){ if($source->isCancelled()){
return; return;

View File

@ -68,7 +68,7 @@ class Cactus extends Transparent{
public function onEntityCollide(Entity $entity){ public function onEntityCollide(Entity $entity){
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1); $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev);
} }
public function onUpdate(int $type){ public function onUpdate(int $type){

View File

@ -63,7 +63,7 @@ class Fire extends Flowable{
public function onEntityCollide(Entity $entity){ public function onEntityCollide(Entity $entity){
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1); $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev);
$ev = new EntityCombustByBlockEvent($this, $entity, 8); $ev = new EntityCombustByBlockEvent($this, $entity, 8);
if($entity instanceof Arrow){ if($entity instanceof Arrow){

View File

@ -52,7 +52,7 @@ class Lava extends Liquid{
$entity->fallDistance *= 0.5; $entity->fallDistance *= 0.5;
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4); $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev);
$ev = new EntityCombustByBlockEvent($this, $entity, 15); $ev = new EntityCombustByBlockEvent($this, $entity, 15);
Server::getInstance()->getPluginManager()->callEvent($ev); Server::getInstance()->getPluginManager()->callEvent($ev);

View File

@ -60,7 +60,7 @@ class Magma extends Solid{
public function onEntityCollide(Entity $entity){ public function onEntityCollide(Entity $entity){
if(!$entity->isSneaking()){ if(!$entity->isSneaking()){
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1); $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev);
} }
} }

View File

@ -337,19 +337,19 @@ class Effect{
case Effect::POISON: case Effect::POISON:
if($entity->getHealth() > 1){ if($entity->getHealth() > 1){
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1); $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev);
} }
break; break;
case Effect::WITHER: case Effect::WITHER:
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1); $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev);
break; break;
case Effect::REGENERATION: case Effect::REGENERATION:
if($entity->getHealth() < $entity->getMaxHealth()){ if($entity->getHealth() < $entity->getMaxHealth()){
$ev = new EntityRegainHealthEvent($entity, 1, EntityRegainHealthEvent::CAUSE_MAGIC); $ev = new EntityRegainHealthEvent($entity, 1, EntityRegainHealthEvent::CAUSE_MAGIC);
$entity->heal($ev->getAmount(), $ev); $entity->heal($ev);
} }
break; break;
@ -362,13 +362,13 @@ class Effect{
//TODO: add particles (witch spell) //TODO: add particles (witch spell)
if($entity->getHealth() < $entity->getMaxHealth()){ if($entity->getHealth() < $entity->getMaxHealth()){
$amount = 2 * (2 ** ($this->getEffectLevel() % 32)); $amount = 2 * (2 ** ($this->getEffectLevel() % 32));
$entity->heal($amount, new EntityRegainHealthEvent($entity, $amount, EntityRegainHealthEvent::CAUSE_MAGIC)); $entity->heal(new EntityRegainHealthEvent($entity, $amount, EntityRegainHealthEvent::CAUSE_MAGIC));
} }
break; break;
case Effect::INSTANT_DAMAGE: case Effect::INSTANT_DAMAGE:
//TODO: add particles (witch spell) //TODO: add particles (witch spell)
$amount = 2 * (2 ** ($this->getEffectLevel() % 32)); $amount = 2 * (2 ** ($this->getEffectLevel() % 32));
$entity->attack($amount, new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, $amount)); $entity->attack(new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, $amount));
break; break;
} }
} }

View File

@ -883,11 +883,9 @@ abstract class Entity extends Location implements Metadatable{
} }
/** /**
* @param float $damage
* @param EntityDamageEvent $source * @param EntityDamageEvent $source
*
*/ */
public function attack($damage, EntityDamageEvent $source){ public function attack(EntityDamageEvent $source){
$this->server->getPluginManager()->callEvent($source); $this->server->getPluginManager()->callEvent($source);
if($source->isCancelled()){ if($source->isCancelled()){
return; return;
@ -913,11 +911,9 @@ abstract class Entity extends Location implements Metadatable{
} }
/** /**
* @param float $amount
* @param EntityRegainHealthEvent $source * @param EntityRegainHealthEvent $source
*
*/ */
public function heal($amount, EntityRegainHealthEvent $source){ public function heal(EntityRegainHealthEvent $source){
$this->server->getPluginManager()->callEvent($source); $this->server->getPluginManager()->callEvent($source);
if($source->isCancelled()){ if($source->isCancelled()){
return; return;
@ -1125,7 +1121,7 @@ abstract class Entity extends Location implements Metadatable{
if($this->y <= -16 and $this->isAlive()){ if($this->y <= -16 and $this->isAlive()){
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev);
$hasUpdate = true; $hasUpdate = true;
} }
@ -1173,7 +1169,7 @@ abstract class Entity extends Location implements Metadatable{
*/ */
protected function dealFireDamage(){ protected function dealFireDamage(){
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev);
} }
protected function updateMovement(){ protected function updateMovement(){

View File

@ -74,9 +74,9 @@ class FallingSand extends Entity{
return false; return false;
} }
public function attack($damage, EntityDamageEvent $source){ public function attack(EntityDamageEvent $source){
if($source->getCause() === EntityDamageEvent::CAUSE_VOID){ if($source->getCause() === EntityDamageEvent::CAUSE_VOID){
parent::attack($damage, $source); parent::attack($source);
} }
} }

View File

@ -402,19 +402,19 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$this->addFood(1.0); $this->addFood(1.0);
} }
if($this->foodTickTimer % 20 === 0 and $health < $this->getMaxHealth()){ if($this->foodTickTimer % 20 === 0 and $health < $this->getMaxHealth()){
$this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION)); $this->heal(new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION));
} }
} }
if($this->foodTickTimer === 0){ if($this->foodTickTimer === 0){
if($food >= 18){ if($food >= 18){
if($health < $this->getMaxHealth()){ if($health < $this->getMaxHealth()){
$this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION)); $this->heal(new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION));
$this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN); $this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN);
} }
}elseif($food <= 0){ }elseif($food <= 0){
if(($difficulty === 1 and $health > 10) or ($difficulty === 2 and $health > 1) or $difficulty === 3){ if(($difficulty === 1 and $health > 10) or ($difficulty === 2 and $health > 1) or $difficulty === 3){
$this->attack(1, new EntityDamageEvent($this, EntityDamageEvent::CAUSE_STARVATION, 1)); $this->attack(new EntityDamageEvent($this, EntityDamageEvent::CAUSE_STARVATION, 1));
} }
} }
} }

View File

@ -87,14 +87,14 @@ class Item extends Entity{
$this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this)); $this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
} }
public function attack($damage, EntityDamageEvent $source){ public function attack(EntityDamageEvent $source){
if( if(
$source->getCause() === EntityDamageEvent::CAUSE_VOID or $source->getCause() === EntityDamageEvent::CAUSE_VOID or
$source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK or $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK or
$source->getCause() === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION or $source->getCause() === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION or
$source->getCause() === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION $source->getCause() === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION
){ ){
parent::attack($damage, $source); parent::attack($source);
} }
} }

View File

@ -157,8 +157,8 @@ abstract class Living extends Entity implements Damageable{
//return $this->getLevel()->rayTraceBlocks(Vector3::createVector($this->x, $this->y + $this->height, $this->z), Vector3::createVector($entity->x, $entity->y + $entity->height, $entity->z)) === null; //return $this->getLevel()->rayTraceBlocks(Vector3::createVector($this->x, $this->y + $this->height, $this->z), Vector3::createVector($entity->x, $entity->y + $entity->height, $entity->z)) === null;
} }
public function heal($amount, EntityRegainHealthEvent $source){ public function heal(EntityRegainHealthEvent $source){
parent::heal($amount, $source); parent::heal($source);
if($source->isCancelled()){ if($source->isCancelled()){
return; return;
} }
@ -321,14 +321,14 @@ abstract class Living extends Entity implements Damageable{
$damage = floor($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getEffectLevel() : 0)); $damage = floor($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);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev);
} }
} }
public function attack($damage, EntityDamageEvent $source){ public function attack(EntityDamageEvent $source){
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() >= $damage){ if($lastCause !== null and $lastCause->getDamage() >= $source->getDamage()){
$source->setCancelled(); $source->setCancelled();
} }
} }
@ -346,7 +346,7 @@ abstract class Living extends Entity implements Damageable{
$source->setDamage(-($source->getDamage(EntityDamageEvent::MODIFIER_BASE) * 0.20 * $this->getEffect(Effect::DAMAGE_RESISTANCE)->getEffectLevel()), EntityDamageEvent::MODIFIER_RESISTANCE); $source->setDamage(-($source->getDamage(EntityDamageEvent::MODIFIER_BASE) * 0.20 * $this->getEffect(Effect::DAMAGE_RESISTANCE)->getEffectLevel()), EntityDamageEvent::MODIFIER_RESISTANCE);
} }
parent::attack($damage, $source); parent::attack($source);
if($source->isCancelled()){ if($source->isCancelled()){
return; return;
@ -365,7 +365,7 @@ abstract class Living extends Entity implements Damageable{
$deltaX = $this->x - $e->x; $deltaX = $this->x - $e->x;
$deltaZ = $this->z - $e->z; $deltaZ = $this->z - $e->z;
$this->knockBack($e, $damage, $deltaX, $deltaZ, $source->getKnockBack()); $this->knockBack($e, $source->getDamage(), $deltaX, $deltaZ, $source->getKnockBack());
} }
} }
@ -428,7 +428,7 @@ abstract class Living extends Entity implements Damageable{
if($this->isInsideOfSolid()){ if($this->isInsideOfSolid()){
$hasUpdate = true; $hasUpdate = true;
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev);
} }
if(!$this->hasEffect(Effect::WATER_BREATHING) and $this->isInsideOfWater()){ if(!$this->hasEffect(Effect::WATER_BREATHING) and $this->isInsideOfWater()){
@ -441,7 +441,7 @@ abstract class Living extends Entity implements Damageable{
$airTicks = 0; $airTicks = 0;
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev);
} }
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks); $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks);
} }
@ -453,7 +453,7 @@ abstract class Living extends Entity implements Damageable{
$airTicks = 0; $airTicks = 0;
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 2); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 2);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev);
} }
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks); $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks);
}else{ }else{

View File

@ -48,9 +48,9 @@ class PrimedTNT extends Entity implements Explosive{
public $canCollide = false; public $canCollide = false;
public function attack($damage, EntityDamageEvent $source){ public function attack(EntityDamageEvent $source){
if($source->getCause() === EntityDamageEvent::CAUSE_VOID){ if($source->getCause() === EntityDamageEvent::CAUSE_VOID){
parent::attack($damage, $source); parent::attack($source);
} }
} }

View File

@ -49,9 +49,9 @@ abstract class Projectile extends Entity{
parent::__construct($level, $nbt); parent::__construct($level, $nbt);
} }
public function attack($damage, EntityDamageEvent $source){ public function attack(EntityDamageEvent $source){
if($source->getCause() === EntityDamageEvent::CAUSE_VOID){ if($source->getCause() === EntityDamageEvent::CAUSE_VOID){
parent::attack($damage, $source); parent::attack($source);
} }
} }
@ -88,7 +88,7 @@ abstract class Projectile extends Entity{
$ev = new EntityDamageByChildEntityEvent($this->getOwningEntity(), $this, $entity, EntityDamageEvent::CAUSE_PROJECTILE, $damage); $ev = new EntityDamageByChildEntityEvent($this->getOwningEntity(), $this, $entity, EntityDamageEvent::CAUSE_PROJECTILE, $damage);
} }
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev);
$this->hadCollision = true; $this->hadCollision = true;

View File

@ -53,8 +53,8 @@ class Squid extends WaterAnimal{
return "Squid"; return "Squid";
} }
public function attack($damage, EntityDamageEvent $source){ public function attack(EntityDamageEvent $source){
parent::attack($damage, $source); parent::attack($source);
if($source->isCancelled()){ if($source->isCancelled()){
return; return;
} }

View File

@ -187,7 +187,7 @@ class Explosion{
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage); $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_BLOCK_EXPLOSION, $damage);
} }
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev);
$entity->setMotion($motion->multiply($impact)); $entity->setMotion($motion->multiply($impact));
} }
} }