PlayerDeathEvent: add ability to set message displayed on the death screen (#5726)

This commit is contained in:
BrandPVP 2023-05-19 18:18:18 +03:00 committed by GitHub
parent bd6af68f91
commit 8245cfab0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -39,6 +39,7 @@ class PlayerDeathEvent extends EntityDeathEvent{
protected $player;
private Translatable|string $deathMessage;
private Translatable|string $deathScreenMessage;
private bool $keepInventory = false;
private bool $keepXp = false;
@ -50,6 +51,7 @@ class PlayerDeathEvent extends EntityDeathEvent{
parent::__construct($entity, $drops, $xp);
$this->player = $entity;
$this->deathMessage = $deathMessage ?? self::deriveMessage($entity->getDisplayName(), $entity->getLastDamageCause());
$this->deathScreenMessage = $this->deathMessage;
}
/**
@ -71,6 +73,14 @@ class PlayerDeathEvent extends EntityDeathEvent{
$this->deathMessage = $deathMessage;
}
public function getDeathScreenMessage() : Translatable|string{
return $this->deathScreenMessage;
}
public function setDeathScreenMessage(Translatable|string $deathScreenMessage) : void{
$this->deathScreenMessage = $deathScreenMessage;
}
public function getKeepInventory() : bool{
return $this->keepInventory;
}

View File

@ -2344,7 +2344,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$this->startDeathAnimation();
$this->getNetworkSession()->onServerDeath($ev->getDeathMessage());
$this->getNetworkSession()->onServerDeath($ev->getDeathScreenMessage());
}
protected function onDeathUpdate(int $tickDiff) : bool{