1.17.x EntityDamageCause

Discussion in 'Spigot Plugin Development' started by youfish30gamer, Jul 21, 2021 at 3:44 PM.

  1. Try logging the DamageCause when another player /kills another. You can use that and add it to your if statements (i think)
  2. Yea but what is the code, if the player does /kill to kill the target. my program doesn't show me anything expect. player.performCommand
  3. Are you logging the damage cause? Because player.performCommand isn't part of that
  4. Yea I don't know what that means
  5. When the event is fired, (/kill <another player>) print to the console (log) what the damage cause was.
  7. Yea, but why does it say fell into void and it gives another message.
  8. what message?
  9. <player> killed
  10. Anyone who can help would be appreciated
  11. This actually doesn't have to do anything with an living entity
  12. Oh wrong thread my bad!
  13. aah okey ..
  14. This code...
    Code (Java):
    if (Objects.requireNonNull(player.getLastDamageCause()).getCause().equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION)) {
                        e.setDeathMessage(HexUtil.chat(CreeperKill).replace("%player_name%", player.getName()));
                    if (player.getLastDamageCause().getCause().equals(EntityDamageEvent.DamageCause.LAVA)) {
                        e.setDeathMessage(HexUtil.chat(LavaKill).replace("%player_name%", player.getName()));
                    if (player.getLastDamageCause().getCause().equals(EntityDamageEvent.DamageCause.DROWNING)) {
                        e.setDeathMessage(HexUtil.chat(DrownKill).replace("%player_name%", player.getName()));
    ...is this:
    Code (Java):
    DamageCause cause = player.getLastDamageCause().getCause();
    String message;
    switch (cause) {
        case ENTITY_EXPLOSION:
            message = CreeperKill;
        case LAVA:
            message = LavaKill;
        case DROWNING:
            message = DrownKill;
            message = null;
    e.setDeathMessage(HexUtil.chat(message).replace("%player_name%", player.getName()));
    If you don't implement your own /kill, then you have to trust the reason of the damage, or work with magic numbers: the void deals 4 damages each second, a /kill does at least player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() damages. You can check if damage type is void and the damage is greater than the value written before
  15. What if I want Zombie as the last Entity Attack
  16. Can you explain that suicide thing one more time please. I don't understand it completley