Solved Custom EntityDamageByEntityEvent

Discussion in 'Spigot Plugin Development' started by Alex_qp, Jul 29, 2018.

  1. Hey there,

    For my plugin I need a custom EntityDamageByEntityEvent in order to change the last entity who damaged the target.

    But as soon as I opened javadoc EntityDamageByEntityEvent I saw two constructor:
    1) marked as deprecated
    2) needs a param of EntityDamageEvent.DamageModifier which is deprecated as well.

    So my question now: Is there any solution to create a custom EntityDamageByEntityEvent without using deprecated stuff or should I stick with one of the above (probably the first one) and not bother about the deprecation?

    Thanks a lot!
    Alex

    PS: My main goal is to change the damager entity of the last EntityDamageEvent without calling my EventHandlers. So what I thought about just now was to call the event and cancel it right after so no listener kicks into action. But will this update the last damager?
     
    #1 Alex_qp, Jul 29, 2018
    Last edited: Jul 29, 2018
  2. That would not work this way.
    Explain your task a little bit more. And from the beginning please. Do you manually invoke the damage?
    Why not using this method when applying custom damage?
    damage
     
  3. So my task is the following:

    1. Change the anger of a pigman if hit by a player (EntityDamageByEntityEvent, no problem there)
    2. If a player angers a pigman (new mechanics added by plugin) set this player as last damager (in order to perform step 3)
    3. If a pigman targets a player get the last damager and cancel if its not the last damager. (EntitytargetLivingEntityEvent)

    The problem here is I cannot call the default EntityDamageByEntityEvent cause this would collide with step 1
    I would like to work with the Entity#getLastDamageCause()
     
    #3 Alex_qp, Jul 29, 2018
    Last edited: Jul 29, 2018
    • Informative Informative x 1

  4. Why setting the last damageCause when it is done in the entityDamageEvent implicit by default?


    Why not saving your data elsewhere? Map<pigmenZombieUUID, playerUUID> ?
     
    • Useful Useful x 1
  5. Could you explain that a little bit more?

    About the map thing:
    I thought I could prevent saving all this but I guess I could try that but a few questions first:

    1) Does a map save its keys or do I have to save them elsewhere too? (List for example, I worked with maps before but I do not know this)
    2) Would it not overflow after time when pigmen despawn? And also: Is this unique ID so unique that it cannot appear twice (after the first despawned for example)
     
    1. Yes it saves it itself, so you are able to access the key.
    2. On EntityDespawn -> map.remove(entity.getUniqueId());
     
  6. There is no such thing as EntityDespawnEvent...?
     
  7. Well that was fast.
    I created an issue and it got resolved in no time! The first constructor is not deprecated anymore.