Damage Event called again on .damage(damage, entity)

Discussion in 'Plugin Development' started by Jalau, Aug 23, 2014.

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

    Jalau

    So I have a problem,
    I have a damage listener that sets the damage, but I don't want it to happen when the damage comes from a skill, then the damage from the skill should be used... I'm using entity.damage(damage, player) in the skill and event.setDamage(damage) in my Listener. The problem is the DamageEvent is called again if I damage it with entity.damage(damage, player) and so the damage is overwritten, the damageCause is everytime ENTITY_ATTACK so I can't go for that :/ Any ideas? I had the idea to make an array in which I add the player when he calls a skill and remove him if the skill is finished, and then theck in the Listener if he is in the array, but thats the last and complicated way.
    Any help is appreciated :)
     
  2. Offline

    WEEEEEE

  3. Offline

    Jalau

    WEEEEEE
    Ok, maybe.. I think array is easier and faster then ^^
    Hm, other solution? :)
     
  4. Offline

    reider45

    Yes, just temporarily store it in a list, then in the event listener check to make sure the entity isn't in the list, also do you know if the DamageCause.CUSTOM may work? I've never tried it.
     
  5. Offline

    unon1100

    reider45 A set would be more efficient ;)
     
  6. Offline

    RawCode

    try to use your head at least

    set some variable
    damage
    set some variable

    events like damage always inside main thread
     
  7. Offline

    reider45


    Why?
     
  8. Offline

    unon1100

    @reider45 It's a very small issue tbh, but if your need of storage is only to figure out if an object is in the list (like checking to see if a UUID is stored), Sets are more efficient than Lists. If you ever actually plan on accessing something in the collection, you should use Lists.
    Proof: http://pastebin.com/ksqbNkyC (Read the last line for the avg efficiency boost)

    Again, not a big deal since it's only a few milliseconds, but it is something to consider, and is especially useful for if you are doing something that is called a ton (ie something in PlayerMoveEvent)
     
Thread Status:
Not open for further replies.

Share This Page