#Using display name in death messages

1 messages · Page 1 of 1 (latest)

rich python
#

Hey guys! Title basically says it all, is there a good way to replace the player's name with the player's display name for each death message, without manually checking for and replacing each indivdiaul death cause?

lofty arrow
#

hi commandgeek

pseudo cape
#
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
   event.setDeathMessage(event.getEntity().getDisplayName());
}

Something like this you mean?

#

Use .replace() on the event.getDeathMessage() and use their name and display name.

#

And just set it to that

rich python
lofty arrow
#

didnt know u used spigot i thought u just did datapacks

rich python
pseudo cape
lofty arrow
#

oh

pseudo cape
#

Ohh wait I see what you mean

#

Hmm

rich python
#

Actually, as long as every death message begins with the player's name, all I have to do is replace the first time it appears

#

I guess I gotta find every death message in the game :P

pseudo cape
#

Mhm, just make sure that no death message repeats their username.

rich python
#

oh true

pseudo cape
#

And you could handle the outliers manually

lofty arrow
#

it sucked

rich python
#

oh wait I just realised, in all the cases where there is a second name (e.g. "player1 was shot by player2"), I want all the names to be replaced with display-names, including the second player....

#

that becomes harder

lofty arrow
#

ignore my weird + string formatting but ye basically that

pseudo cape
#

You could iterate through all the online players, and replace any instance of their name with their display name.

#

Should fix that issue.

rich python
#

ahhh

#

yes

#

I'll give that shot, thanks!

pseudo cape
#

No problem, good luck!