Solved Determine PlayerMoveEvent cause is knockback?

Discussion in 'Plugin Development' started by RcExtract, Feb 15, 2018.

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

    RcExtract

    How do i determine a PlayerMoveEvent is fired due to being hit (knockback)? Will EntityDamageByEntityEvent and PlayerMoveEvent be triggered at the same tick?
     
  2. @RcExtract
    Well if you know they will be moved if hit, why not just use the EntityDamageByEntityEvent and not use the move event
     
  3. Offline

    Nostos

    Use EntityDamageByEntityEvent and check if the attacker#getItemInHand().getEnchantment() is equal to knockback or something along those lines :D
     
  4. Offline

    RcExtract

    Because i want to know location of the player after being hit
     
  5. @RcExtract
    You can, get the player and do p.getLocation(), or do a bukkit scheduler to run 1 or 2 seconds later and then get the location so that'll be when they're moved, or when the damage event is triggered add the player to a list and then on move event check if the player is in the list if so get the location and etc then remove them from the list
     
    Last edited: Feb 15, 2018
  6. Offline

    RcExtract

    Items without knockback enchantment, even fist, can deal knockback to an entity, so i think the enchantment is not related.
    Thanks. But how can i guarantee the first PlayerMoveEvent after an EntityDamageByEntityEvent with the same entity is caused by knockback?
     
  7. Offline

    Horsey

    This is how I'd personally go about it —
    1. Listen to the EntityDamageByEntityEvent
    2. Add the player into a list
    3. Listen for the PlayerMoveEvent
    4. Ensure the player is in the list
    5. Ensure the player is actually on the ground
    6. The Player's Location should essentially be where it lands after being hit.
    You may need to tweak a couple of things with the scheduler.
     
Thread Status:
Not open for further replies.

Share This Page