Use entity IDs in EntityDamageBy*EntityEvents, fixed memory leaks related to PvP/PvE/PvM (#418)

This commit is contained in:
Dylan K. Taylor
2017-03-13 10:30:31 +00:00
committed by GitHub
parent 083d1e9ef8
commit 92193fd27b
8 changed files with 63 additions and 17 deletions

View File

@ -23,10 +23,13 @@ namespace pocketmine\event\entity;
use pocketmine\entity\Entity;
/**
* Called when an entity takes damage from an entity sourced from another entity, for example being hit by a snowball thrown by a Player.
*/
class EntityDamageByChildEntityEvent extends EntityDamageByEntityEvent{
/** @var Entity */
private $childEntity;
/** @var int */
private $childEntityEid;
/**
@ -37,15 +40,17 @@ class EntityDamageByChildEntityEvent extends EntityDamageByEntityEvent{
* @param int|int[] $damage
*/
public function __construct(Entity $damager, Entity $childEntity, Entity $entity, $cause, $damage){
$this->childEntity = $childEntity;
$this->childEntityEid = $childEntity->getId();
parent::__construct($damager, $entity, $cause, $damage);
}
/**
* @return Entity
* Returns the entity which caused the damage, or null if the entity has been killed or closed.
*
* @return Entity|null
*/
public function getChild(){
return $this->childEntity;
return $this->getEntity()->getLevel()->getServer()->findEntity($this->childEntityEid, $this->getEntity()->getLevel());
}