Skip to content

Commit

Permalink
onEntityDeath: Replace deprecated customName method
Browse files Browse the repository at this point in the history
  • Loading branch information
mindsolve committed Mar 27, 2024
1 parent 3f0dfe6 commit e16a1e2
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,14 @@ public void onEntityDeath(EntityDeathEvent event) {
instance.playerKillStats.put(killerPlayer.getUniqueId(), currentKillStat);

// Check if entity has a custom name
boolean hasCustomName = deadEntity.getCustomName() != null;
String customName = "";
Component customNameComponent = deadEntity.customName();
if (customNameComponent != null) {
customName = PlainTextComponentSerializer.plainText().serialize(customNameComponent);
}

// Get name for killed entity (or custom name if mob is named)
String killedEntityName = hasCustomName ? deadEntity.getCustomName().trim() : deadEntity.getName().trim();
String killedEntityName = !customName.isEmpty() ? customName : deadEntity.getName().trim();
killedEntityName = WordUtils.capitalize(killedEntityName);

/*
Expand All @@ -124,7 +128,7 @@ public void onEntityDeath(EntityDeathEvent event) {


ComponentBuilder deathMessage = new ComponentBuilder().color(DARK_GRAY);
if (hasCustomName) {
if (!customName.isEmpty()) {
// Get killed entity type (e.g. "Ender Dragon", "Bee")
String killedEntityTypeName = deadEntity.getType().toString().replace("_", " ");
killedEntityTypeName = WordUtils.capitalizeFully(killedEntityTypeName);
Expand Down Expand Up @@ -320,7 +324,7 @@ public void onEntityDeath(EntityDeathEvent event) {
.append("").reset().color(DARK_GRAY);
} else {
deathMessage.append(" (How the heck did you do this? Event (block): " +
"Cause:" + cause.getCause() + "; Damager:" + cause.getDamager() + ")").color(DARK_RED);
"Cause:" + cause.getCause() + "; Damager:" + cause.getDamager() + ")").color(DARK_RED);
}

} else if (deadEntity.getLastDamageCause().getCause() == EntityDamageEvent.DamageCause.MAGIC) {
Expand Down

0 comments on commit e16a1e2

Please sign in to comment.