Damage Player with specified DamageCause?

Discussion in 'Plugin Development' started by MrAndeos, Apr 10, 2018.

Thread Status:
Not open for further replies.
  1. Offline

    MrAndeos

    Hello.
    I need to damage a Player and set the DamageCause to SUICIDE, currently i have this:
    Code:java
    1. Bukkit.getPluginManager().callEvent(new EntityDamageEvent(player, DamageCause.SUICIDE, 1.0));

    And this doesn't work, it doesn't damage the player. How I can make this work?
     
  2. Offline

    Zombie_Striker

    @MrAndeos
    There is currently no way to directly set the damage cause while inflicting damage. However, you can do the following:
    1. Use Player#damage(amount) to damage the entity.
    2. After that, store the damaged player's instance somewhere outside of the method. This will be used to detect if a player 'committed suicide'
    3. Create a new listener for EntityDamageEvent. Set its priority equal to HIGHEST so it is triggered first.
    4. In it, check if the player's instance from #2 is equal to the player from the event.
    5. If so, set the DamageCause to SUICIDE and set the player's instance from #2 to null.
     
    MrAndeos likes this.
  3. Offline

    MrAndeos

    @Zombie_Striker
    Ok, but how I can set the DamageCause? I don't see any method for this in EntityDamageEvent.
     
    RcExtract likes this.
  4. Offline

    MightyOne

    @MrAndeos me neither but the first part of @Zombie_Striker solution should do it. Which part in you code needs to know what kind of damage a player received? What's the greater purpose of SUICIDE?
     
  5. Offline

    MrAndeos

    @MightyOne
    I need to set DamageCause to have a correct death message in other plugin.
     
  6. Offline

    MightyOne

    If you dont have source code of the other plugin you should maybe contact the aithor. I dont think its possible to achieve this woth another plugin
     
Thread Status:
Not open for further replies.

Share This Page