mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 20:07:09 +00:00
Implement a Living::getDisplayName()
(#5384)
This commit is contained in:
parent
80a432d9ff
commit
d476a4c1aa
@ -184,6 +184,13 @@ abstract class Living extends Entity{
|
||||
$this->attributeMap->add($this->absorptionAttr = AttributeFactory::getInstance()->mustGet(Attribute::ABSORPTION));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name used to describe this entity in chat and command outputs.
|
||||
*/
|
||||
public function getDisplayName() : string{
|
||||
return $this->nameTag !== "" ? $this->nameTag : $this->getName();
|
||||
}
|
||||
|
||||
public function setHealth(float $amount) : void{
|
||||
$wasAlive = $this->isAlive();
|
||||
parent::setHealth($amount);
|
||||
|
@ -98,17 +98,15 @@ class PlayerDeathEvent extends EntityDeathEvent{
|
||||
if($e instanceof Player){
|
||||
return KnownTranslationFactory::death_attack_player($name, $e->getDisplayName());
|
||||
}elseif($e instanceof Living){
|
||||
return KnownTranslationFactory::death_attack_mob($name, $e->getNameTag() !== "" ? $e->getNameTag() : $e->getName());
|
||||
return KnownTranslationFactory::death_attack_mob($name, $e->getDisplayName());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EntityDamageEvent::CAUSE_PROJECTILE:
|
||||
if($deathCause instanceof EntityDamageByEntityEvent){
|
||||
$e = $deathCause->getDamager();
|
||||
if($e instanceof Player){
|
||||
if($e instanceof Living){
|
||||
return KnownTranslationFactory::death_attack_arrow($name, $e->getDisplayName());
|
||||
}elseif($e instanceof Living){
|
||||
return KnownTranslationFactory::death_attack_arrow($name, $e->getNameTag() !== "" ? $e->getNameTag() : $e->getName());
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -149,10 +147,8 @@ class PlayerDeathEvent extends EntityDeathEvent{
|
||||
case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION:
|
||||
if($deathCause instanceof EntityDamageByEntityEvent){
|
||||
$e = $deathCause->getDamager();
|
||||
if($e instanceof Player){
|
||||
if($e instanceof Living){
|
||||
return KnownTranslationFactory::death_attack_explosion_player($name, $e->getDisplayName());
|
||||
}elseif($e instanceof Living){
|
||||
return KnownTranslationFactory::death_attack_explosion_player($name, $e->getNameTag() !== "" ? $e->getNameTag() : $e->getName());
|
||||
}
|
||||
}
|
||||
return KnownTranslationFactory::death_attack_explosion($name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user