mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
EntityDeathEvent: add XP amount API, closes #2690
This commit is contained in:
@ -29,14 +29,18 @@ use pocketmine\item\Item;
|
||||
class EntityDeathEvent extends EntityEvent{
|
||||
/** @var Item[] */
|
||||
private $drops = [];
|
||||
/** @var int */
|
||||
private $xp;
|
||||
|
||||
/**
|
||||
* @param Living $entity
|
||||
* @param Item[] $drops
|
||||
* @param int $xp
|
||||
*/
|
||||
public function __construct(Living $entity, array $drops = []){
|
||||
public function __construct(Living $entity, array $drops = [], int $xp = 0){
|
||||
$this->entity = $entity;
|
||||
$this->drops = $drops;
|
||||
$this->xp = $xp;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,4 +63,24 @@ class EntityDeathEvent extends EntityEvent{
|
||||
public function setDrops(array $drops) : void{
|
||||
$this->drops = $drops;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns how much experience is dropped due to this entity's death.
|
||||
* @return int
|
||||
*/
|
||||
public function getXpDropAmount() : int{
|
||||
return $this->xp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $xp
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setXpDropAmount(int $xp) : void{
|
||||
if($xp < 0){
|
||||
throw new \InvalidArgumentException("XP drop amount must not be negative");
|
||||
}
|
||||
$this->xp = $xp;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user