mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-09 03:06:55 +00:00
Use entity IDs in EntityDamageBy*EntityEvents, fixed memory leaks related to PvP/PvE/PvM (#418)
This commit is contained in:
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user