From 3a76a111d315c9893251fc5a1d4b106a6cc01588 Mon Sep 17 00:00:00 2001 From: GJ Date: Sun, 14 Apr 2013 02:10:22 -0400 Subject: [PATCH] Use the mob name when we have it. --- .../gmail/nossr50/listeners/PlayerListener.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 29c6609c1..e4b8a116f 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -11,6 +11,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerChangedWorldEvent; @@ -49,6 +51,7 @@ import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Motd; import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.SkillUtils; @@ -68,7 +71,17 @@ public class PlayerListener implements Listener { return; } - event.setDeathMessage(deathMessage.replaceAll("(?:\u00A7(?:[0-9A-FK-ORa-fk-or]){1}(?:[\u2764\u25A0]{1,10})){1,2}", "a mob")); + EntityDamageEvent lastDamageCause = event.getEntity().getLastDamageCause(); + String replaceString; + + if (lastDamageCause instanceof EntityDamageByEntityEvent) { + replaceString = StringUtils.getPrettyEntityTypeString(((EntityDamageByEntityEvent) lastDamageCause).getDamager().getType()); + } + else { + replaceString = "a mob"; + } + + event.setDeathMessage(deathMessage.replaceAll("(?:\u00A7(?:[0-9A-FK-ORa-fk-or]){1}(?:[\u2764\u25A0]{1,10})){1,2}", replaceString)); } /**