PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
PlayerDeathEvent.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
25
37
39 protected Player $player;
40
41 private Translatable|string $deathMessage;
42 private Translatable|string $deathScreenMessage;
43 private bool $keepInventory = false;
44 private bool $keepXp = false;
45
50 public function __construct(Player $entity, array $drops, int $xp, Translatable|string|null $deathMessage){
51 parent::__construct($entity, $drops, $xp);
52 $this->player = $entity;
53 $this->deathMessage = $deathMessage ?? self::deriveMessage($entity->getDisplayName(), $entity->getLastDamageCause());
54 $this->deathScreenMessage = $this->deathMessage;
55 }
56
60 public function getEntity(){
61 return $this->player;
62 }
63
64 public function getPlayer() : Player{
65 return $this->player;
66 }
67
68 public function getDeathMessage() : Translatable|string{
69 return $this->deathMessage;
70 }
71
72 public function setDeathMessage(Translatable|string $deathMessage) : void{
73 $this->deathMessage = $deathMessage;
74 }
75
76 public function getDeathScreenMessage() : Translatable|string{
77 return $this->deathScreenMessage;
78 }
79
80 public function setDeathScreenMessage(Translatable|string $deathScreenMessage) : void{
81 $this->deathScreenMessage = $deathScreenMessage;
82 }
83
84 public function getKeepInventory() : bool{
85 return $this->keepInventory;
86 }
87
88 public function setKeepInventory(bool $keepInventory) : void{
89 $this->keepInventory = $keepInventory;
90 }
91
92 public function getKeepXp() : bool{
93 return $this->keepXp;
94 }
95
96 public function setKeepXp(bool $keepXp) : void{
97 $this->keepXp = $keepXp;
98 }
99
103 public static function deriveMessage(string $name, ?EntityDamageEvent $deathCause) : Translatable{
104 switch($deathCause === null ? EntityDamageEvent::CAUSE_CUSTOM : $deathCause->getCause()){
105 case EntityDamageEvent::CAUSE_ENTITY_ATTACK:
106 if($deathCause instanceof EntityDamageByEntityEvent){
107 $e = $deathCause->getDamager();
108 if($e instanceof Player){
109 return KnownTranslationFactory::death_attack_player($name, $e->getDisplayName());
110 }elseif($e instanceof Living){
111 return KnownTranslationFactory::death_attack_mob($name, $e->getDisplayName());
112 }
113 }
114 break;
115 case EntityDamageEvent::CAUSE_PROJECTILE:
116 if($deathCause instanceof EntityDamageByEntityEvent){
117 $e = $deathCause->getDamager();
118 if($e instanceof Living){
119 return KnownTranslationFactory::death_attack_arrow($name, $e->getDisplayName());
120 }
121 }
122 break;
123 case EntityDamageEvent::CAUSE_SUICIDE:
124 return KnownTranslationFactory::death_attack_generic($name);
125 case EntityDamageEvent::CAUSE_VOID:
126 return KnownTranslationFactory::death_attack_outOfWorld($name);
127 case EntityDamageEvent::CAUSE_FALL:
128 if($deathCause instanceof EntityDamageEvent && $deathCause->getFinalDamage() > 2){
129 return KnownTranslationFactory::death_fell_accident_generic($name);
130 }
131 return KnownTranslationFactory::death_attack_fall($name);
132
133 case EntityDamageEvent::CAUSE_SUFFOCATION:
134 return KnownTranslationFactory::death_attack_inWall($name);
135
136 case EntityDamageEvent::CAUSE_LAVA:
137 return KnownTranslationFactory::death_attack_lava($name);
138
139 case EntityDamageEvent::CAUSE_FIRE:
140 return KnownTranslationFactory::death_attack_onFire($name);
141
142 case EntityDamageEvent::CAUSE_FIRE_TICK:
143 return KnownTranslationFactory::death_attack_inFire($name);
144
145 case EntityDamageEvent::CAUSE_DROWNING:
146 return KnownTranslationFactory::death_attack_drown($name);
147
148 case EntityDamageEvent::CAUSE_CONTACT:
149 if($deathCause instanceof EntityDamageByBlockEvent){
150 if($deathCause->getDamager()->getTypeId() === BlockTypeIds::CACTUS){
151 return KnownTranslationFactory::death_attack_cactus($name);
152 }
153 }
154 break;
155
156 case EntityDamageEvent::CAUSE_BLOCK_EXPLOSION:
157 case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION:
158 if($deathCause instanceof EntityDamageByEntityEvent){
159 $e = $deathCause->getDamager();
160 if($e instanceof Living){
161 return KnownTranslationFactory::death_attack_explosion_player($name, $e->getDisplayName());
162 }
163 }
164 return KnownTranslationFactory::death_attack_explosion($name);
165
166 case EntityDamageEvent::CAUSE_MAGIC:
167 return KnownTranslationFactory::death_attack_magic($name);
168
169 case EntityDamageEvent::CAUSE_FALLING_BLOCK:
170 if($deathCause instanceof EntityDamageByEntityEvent){
171 $e = $deathCause->getDamager();
172 if($e instanceof FallingBlock){
173 if($e->getBlock()->getTypeId() === BlockTypeIds::ANVIL){
174 return KnownTranslationFactory::death_attack_anvil($name);
175 }else{
176 return KnownTranslationFactory::death_attack_fallingBlock($name);
177 }
178 }
179 }
180 break;
181
182 case EntityDamageEvent::CAUSE_CUSTOM:
183 break;
184
185 default:
186 break;
187 }
188
189 return KnownTranslationFactory::death_attack_generic($name);
190 }
191}
static deriveMessage(string $name, ?EntityDamageEvent $deathCause)
__construct(Player $entity, array $drops, int $xp, Translatable|string|null $deathMessage)