From 20aa519f3a4ce05826f4ba026ff9a83e9dbbd605 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 16 Aug 2017 19:14:15 +0100 Subject: [PATCH] Added capability to remove owners/target entities --- src/pocketmine/entity/Entity.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index e37bbfdaf..374233673 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -600,18 +600,20 @@ abstract class Entity extends Location implements Metadatable{ } /** - * Sets the owner of the entity. + * Sets the owner of the entity. Passing null will remove the current owner. * - * @param Entity $owner + * @param Entity|null $owner * * @throws \InvalidArgumentException if the supplied entity is not valid */ - public function setOwningEntity(Entity $owner){ - if($owner->closed){ + public function setOwningEntity(Entity $owner = null){ + if($owner === null){ + $this->removeDataProperty(self::DATA_OWNER_EID); + }elseif($owner->closed){ throw new \InvalidArgumentException("Supplied owning entity is garbage and cannot be used"); + }else{ + $this->setDataProperty(self::DATA_OWNER_EID, self::DATA_TYPE_LONG, $owner->getId()); } - - $this->setDataProperty(self::DATA_OWNER_EID, self::DATA_TYPE_LONG, $owner->getId()); } /** @@ -638,18 +640,20 @@ abstract class Entity extends Location implements Metadatable{ } /** - * Sets the entity's target entity. + * Sets the entity's target entity. Passing null will remove the current target. * - * @param Entity $target + * @param Entity|null $target * * @throws \InvalidArgumentException if the target entity is not valid */ - public function setTargetEntity(Entity $target){ - if($target->closed){ + public function setTargetEntity(Entity $target = null){ + if($target === null){ + $this->removeDataProperty(self::DATA_TARGET_EID); + }elseif($target->closed){ throw new \InvalidArgumentException("Supplied target entity is garbage and cannot be used"); + }else{ + $this->setDataProperty(self::DATA_TARGET_EID, self::DATA_TYPE_LONG, $target->getId()); } - - $this->setDataProperty(self::DATA_TARGET_EID, self::DATA_TYPE_LONG, $target->getId()); } /** @@ -1875,6 +1879,10 @@ abstract class Entity extends Location implements Metadatable{ return isset($this->dataProperties[$id]) ? $this->dataProperties[$id][1] : null; } + public function removeDataProperty(int $id){ + unset($this->dataProperties[$id]); + } + /** * @param int $id *