1.14.4 Check if entity is moving?

Discussion in 'Spigot Plugin Development' started by kinukin, Feb 1, 2020.

  1. How can I check if an entity is moving?
  2. Well there’s no event for that so you have two options:
    1. Registering entities that you wanna know if they moved into a list or anything similar and use a bukkit runnable to compare their current position with their last known position
    2. Use a bukkit runnable to get every entities in every loaded chunks, save their location somewhere and compare their current location with the last known location using the runnable
  3. How do I get their current position with their last known position?
  4. For example, create a hash map, the key is gonna be the instance of the entity itself and the value is gonna be their current location. Now in the bukkit runnable you have to loop through the hash map and for each key (entity) you will get their value (location) and compare it to the entity current location (at the time that the runnable runs), if it’s different it’s because the entity moved
  5. A map would be inefficient. Just check Entity#getVelocity isn't equal to Vector.zero()
    • Agree Agree x 1
  6. What event do I use?
  7. There is no event for entity movement. What exactly are you trying to do that requires you to know that the entity is moving?
  8. You could even create your own event to make usage easier. Unfortunately, as stated above, Bukkit doesn't have an event for this. I'd assume it would cause a lot of lag.
    • Like Like x 1
  9. Vector.zero is basically checking if all 3 values are 0
  10. What do you need this for? If its a player, there is an exact listener for that but if its a zombie or a cow you cant check it.