mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
parent
a38a5c67f1
commit
02cf6ae46c
@ -40,6 +40,7 @@ class PlayerDeathEvent extends EntityDeathEvent{
|
||||
|
||||
private Translatable|string $deathMessage;
|
||||
private bool $keepInventory = false;
|
||||
private bool $keepXp = false;
|
||||
|
||||
/**
|
||||
* @param Item[] $drops
|
||||
@ -78,6 +79,14 @@ class PlayerDeathEvent extends EntityDeathEvent{
|
||||
$this->keepInventory = $keepInventory;
|
||||
}
|
||||
|
||||
public function getKeepXp() : bool{
|
||||
return $this->keepXp;
|
||||
}
|
||||
|
||||
public function setKeepXp(bool $keepXp) : void{
|
||||
$this->keepXp = $keepXp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the vanilla death message for the given death cause.
|
||||
*/
|
||||
|
@ -33,6 +33,7 @@ use pocketmine\data\java\GameModeIdMap;
|
||||
use pocketmine\entity\animation\Animation;
|
||||
use pocketmine\entity\animation\ArmSwingAnimation;
|
||||
use pocketmine\entity\animation\CriticalHitAnimation;
|
||||
use pocketmine\entity\Attribute;
|
||||
use pocketmine\entity\effect\VanillaEffects;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\entity\Human;
|
||||
@ -2223,8 +2224,10 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
}
|
||||
}
|
||||
|
||||
$this->getWorld()->dropExperience($this->location, $ev->getXpDropAmount());
|
||||
$this->xpManager->setXpAndProgress(0, 0.0);
|
||||
if(!$ev->getKeepXp()){
|
||||
$this->getWorld()->dropExperience($this->location, $ev->getXpDropAmount());
|
||||
$this->xpManager->setXpAndProgress(0, 0.0);
|
||||
}
|
||||
|
||||
if($ev->getDeathMessage() != ""){
|
||||
$this->server->broadcastMessage($ev->getDeathMessage());
|
||||
@ -2285,6 +2288,9 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
||||
$this->setHealth($this->getMaxHealth());
|
||||
|
||||
foreach($this->attributeMap->getAll() as $attr){
|
||||
if($attr->getId() === Attribute::EXPERIENCE || $attr->getId() === Attribute::EXPERIENCE_LEVEL){ //we have already reset both of those if needed when the player died
|
||||
continue;
|
||||
}
|
||||
$attr->resetToDefault();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user