EntityDamageEvent: Add API to customize Living entity attack cooldown time

closes #2310
This commit is contained in:
왕고슴도치 2018-07-16 09:29:17 +00:00 committed by Dylan K. Taylor
parent f582b5a3db
commit 47cd6fe105
2 changed files with 24 additions and 1 deletions

View File

@ -560,7 +560,7 @@ abstract class Living extends Entity implements Damageable{
return;
}
$this->attackTime = 10; //0.5 seconds cooldown
$this->attackTime = $source->getAttackCooldown();
if($source instanceof EntityDamageByEntityEvent){
$e = $source->getDamager();

View File

@ -69,6 +69,9 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{
/** @var float[] */
private $originals;
/** @var int */
private $attackCooldown = 10;
/**
* @param Entity $entity
@ -197,4 +200,24 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{
return true;
}
/**
* Returns the cooldown in ticks before the target entity can be attacked again.
*
* @return int
*/
public function getAttackCooldown() : int{
return $this->attackCooldown;
}
/**
* Returns the cooldown in ticks before the target entity can be attacked again.
*
* NOTE: This value is not used in non-Living entities
*
* @param int $attackCooldown
*/
public function setAttackCooldown(int $attackCooldown) : void{
$this->attackCooldown = $attackCooldown;
}
}