Creating a Damage Event?

Discussion in 'Spigot Plugin Development' started by CrafterChris, May 16, 2019 at 6:13 AM.

  1. I'm currently trying to run a damage event where the player damages something with a custom damage cause.

    Code (Text):

    public void spellDamage(Entity e, Player p, double damage) {
            if (e instanceof LivingEntity) {
                EntityDamageByEntityEvent en = new EntityDamageByEntityEvent(p, e, DamageCause.CUSTOM, damage);
    The correct damage is printed (of course, I passed it in), but it doesn't actually do any damage. It even triggers my Bossbar HP system which also runs off of entity damage by entity events.

    Any ideas why it doesn't do any damage?
  2. You're calling the event but the event isn't what's damaging the player. Try calling e.damage after checking if en.isCancelled is false
  3. Code (Text):

    EntityDamageByEntityEvent en = new EntityDamageByEntityEvent(p, e, DamageCause.CUSTOM, damage);
                if (e instanceof LivingEntity) {
    Like this?
    And it just prints false every time.
  4. Because you (probably) dont handle it and dont set it cancelled.
  5. At the moment though I'm just trying to deal damage to an entity under the DamageCause of custom with a damager as a player. Is there any way to do that?
  6. I’ve experienced some issues, but you can do e.damage(damage, damager)
  7. That runs a damage cause of Entity_Attack though I believe. I'm trying to do a Damage Cause of Custom. In the worst case I'll use a list based system but was just wondering if there was a less hacky method.
  8. a bukkit event doesnt make the event happen. a bukkit event is an 'event' when the action happens. if you're familar with a callback-like system, that is essentially what the bukkit event system is.
  9. Although I am not familiar with the event.

    It is pretty obvious that you need to be able to change the 'damage' value somewhere, by using a 'set' and 'update' statement
  10. Are you sure? Have you tested this as I would not expect calling class members of Bukkit objects to trigger events.

    If for some reason it does then you could use getHealth and setHealth instead.
  11. You could create ur own custom event :)))

    Just create a new class with ur custom name and call the "extends Event"
    Ur gonna get some imports then :)

    In thats not what you need

    e.damage() causes damage to a living entity
    e.setLastDamage() sets the time the entity got damaged last time (good to bypass damage cooldowns)
    e.setLastDamageCause() changes the last damage cause (only Good to change the deathmessage)
    #11 Mr_Boogi, May 17, 2019 at 12:55 PM
    Last edited: May 17, 2019 at 1:03 PM
  12. In terms of creating an event, how would that enable me to set a damage cause, would I just have to manage all damage?
  13. to change the lastdamagecause, you dont need to create a new event
    its okay if you use ur own listener u just created

    just call e. damage(10.0);
    then e.setlastdamagecause(custom)
  14. Problem is e.damage(10.0) does not set the player as the damager
  15. TST1818#8683 add me on discord

Share This Page