From 3cb1450ff1c40f97a11181a74bfff2134690af32 Mon Sep 17 00:00:00 2001 From: TheHyper45 Date: Sun, 20 Jun 2021 10:20:42 +0100 Subject: Small refinements in BroadcastDeathMessage method. --- src/Entities/Entity.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index c4f61ad1e..858f9e0de 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -2420,11 +2420,22 @@ void cEntity::BroadcastDeathMessage(TakeDamageInfo & a_TDI) GetWorld()->BroadcastChatDeath(DeathMessage); } } - else + // This will trigger if a player/tamed pet has been killed by another mob/tamed pet. + else if (a_TDI.Attacker->IsMob()) { - AString KillerClass = a_TDI.Attacker->GetClass(); - KillerClass.erase(KillerClass.begin()); // Erase the 'c' of the class (e.g. "cWitch" -> "Witch") - AString DeathMessage = Printf("%s was killed by a %s", Name.c_str(), KillerClass.c_str()); + cMonster * Monster = static_cast(a_TDI.Attacker); + + AString DeathMessage; + if (Monster->HasCustomName()) + { + DeathMessage = Printf("%s was killed by %s", Name.c_str(), Monster->GetCustomName().c_str()); + } + else + { + AString KillerName = AString(NamespaceSerializer::Prettify(Monster->GetMobType(), Monster->IsTame())); + DeathMessage = Printf("%s was killed by a %s", Name.c_str(), KillerName.c_str()); + } + PluginManager->CallHookKilled(*this, a_TDI, DeathMessage); if (DeathMessage != AString("")) { -- cgit v1.2.3