From 47cd6fe105399e66a604ab1ab3e10af317cdb2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=99=95=EA=B3=A0=EC=8A=B4=EB=8F=84=EC=B9=98?= Date: Mon, 16 Jul 2018 09:29:17 +0000 Subject: [PATCH] EntityDamageEvent: Add API to customize Living entity attack cooldown time closes #2310 --- src/pocketmine/entity/Living.php | 2 +- .../event/entity/EntityDamageEvent.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index b4cad9433..aa182f1fa 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -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(); diff --git a/src/pocketmine/event/entity/EntityDamageEvent.php b/src/pocketmine/event/entity/EntityDamageEvent.php index fb448db95..bbde1967d 100644 --- a/src/pocketmine/event/entity/EntityDamageEvent.php +++ b/src/pocketmine/event/entity/EntityDamageEvent.php @@ -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; + } }