@@ -155,27 +155,18 @@ private static BedWarsDeathResult handleEnvironmentalDeath(BedWarsDeathResult.Bu
155155 public static Component createDeathMessage (@ NotNull BedWarsDeathResult result ) {
156156 String victimName = result .victim ().getUsername ();
157157 String victimColor = getTeamColor (result .victim ());
158-
159- Component message = switch (result .deathType ()) {
160- case PLAYER_MELEE -> createPlayerKillMessage (victimName , victimColor , result .killer (), " was slain by " );
161- case PLAYER_VOID_KNOCK -> createPlayerKillMessage (victimName , victimColor , result .killer (), " was knocked into the void by " );
162- case PLAYER_FALL_KNOCK -> createPlayerKillMessage (victimName , victimColor , result .killer (), " was knocked off by " );
163- case PLAYER_PROJECTILE -> createPlayerKillMessage (victimName , victimColor , result .killer (), " was shot by " );
164- case PLAYER_EXPLOSION -> createPlayerKillMessage (victimName , victimColor , result .killer (), " was blown up by " );
165- case PLAYER_FIRE -> createPlayerKillMessage (victimName , victimColor , result .killer (), " was burned to death by " );
166-
167- case VOID_ASSISTED -> createAssistedMessage (victimName , victimColor , result .assistPlayer (), " was knocked into the void by " );
168- case FALL_ASSISTED -> createAssistedMessage (victimName , victimColor , result .assistPlayer (), " was knocked off by " );
169-
170- case VOID -> createSimpleMessage (victimName , victimColor , " fell into the void." );
171- case FALL -> createSimpleMessage (victimName , victimColor , " fell from a high place." );
172- case FIRE -> createSimpleMessage (victimName , victimColor , " burned to death." );
173- case EXPLOSION -> createSimpleMessage (victimName , victimColor , " blew up." );
174-
175- case MOB_KILL -> createMobKillMessage (victimName , victimColor , result .attackerEntity ());
176-
177- case GENERIC -> createSimpleMessage (victimName , victimColor , " died." );
178- };
158+ BedWarsDeathType deathType = result .deathType ();
159+ String messageFormat = deathType .getMessageFormat ();
160+
161+ Component message ;
162+ if (deathType .involvesPlayer ()) {
163+ BedWarsPlayer involvedPlayer = deathType .isAssisted () ? result .assistPlayer () : result .killer ();
164+ message = createPlayerInvolvedMessage (victimName , victimColor , involvedPlayer , messageFormat );
165+ } else if (deathType == BedWarsDeathType .MOB_KILL ) {
166+ message = createMobKillMessage (victimName , victimColor , messageFormat , result .attackerEntity ());
167+ } else {
168+ message = createSingleMessage (victimName , victimColor , messageFormat );
169+ }
179170
180171 // Append FINAL KILL if applicable
181172 if (result .isFinalKill ()) {
@@ -187,38 +178,28 @@ public static Component createDeathMessage(@NotNull BedWarsDeathResult result) {
187178 return message ;
188179 }
189180
190- private static Component createPlayerKillMessage (String victimName , String victimColor ,
191- @ Nullable BedWarsPlayer killer , String action ) {
192- if (killer == null ) {
193- return createSimpleMessage (victimName , victimColor , " died." );
181+ private static Component createPlayerInvolvedMessage (String victimName , String victimColor ,
182+ @ Nullable BedWarsPlayer otherPlayer ,
183+ String messageFormat ) {
184+ if (otherPlayer == null ) {
185+ return createSingleMessage (victimName , victimColor , messageFormat );
194186 }
195187
196- String killerColor = getTeamColor (killer );
197-
198- return Component .text (victimColor + victimName + "§7" + action + killerColor + killer .getUsername () + "§7." );
199- }
200-
201- private static Component createAssistedMessage (String victimName , String victimColor ,
202- @ Nullable BedWarsPlayer assistPlayer , String action ) {
203- if (assistPlayer == null ) {
204- return createSimpleMessage (victimName , victimColor , " died." );
205- }
206-
207- String assistColor = getTeamColor (assistPlayer );
208-
209- return Component .text (victimColor + victimName + "§7" + action + assistColor + assistPlayer .getUsername () + "§7." );
188+ String otherColor = getTeamColor (otherPlayer );
189+ return Component .text (victimColor + victimName + "§7" + messageFormat + otherColor + otherPlayer .getUsername () + "§7." );
210190 }
211191
212- private static Component createSimpleMessage (String victimName , String victimColor , String suffix ) {
213- return Component .text (victimColor + victimName + "§7" + suffix );
192+ private static Component createSingleMessage (String victimName , String victimColor , String messageFormat ) {
193+ return Component .text (victimColor + victimName + "§7" + messageFormat );
214194 }
215195
216- private static Component createMobKillMessage (String victimName , String victimColor , @ Nullable Entity mob ) {
196+ private static Component createMobKillMessage (String victimName , String victimColor , String messageFormat ,
197+ @ Nullable Entity mob ) {
217198 String mobName = mob != null
218199 ? mob .getEntityType ().name ().toLowerCase ().replace ("_" , " " )
219200 : "a mob" ;
220201
221- return Component .text (victimColor + victimName + "§7 was killed by " + mobName + "§7." );
202+ return Component .text (victimColor + victimName + "§7" + messageFormat + mobName + "§7." );
222203 }
223204
224205 private static String getTeamColor (@ Nullable BedWarsPlayer player ) {
0 commit comments