Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by zKiller171, Jul 30, 2018.
Hi, i have a question: how can i get the arrow distance when it hits a player?
Arrow distance as in, how far it goes?
Whenever X hits an Entity Y you can then do:
It may not be accurate as the player can move while the arrow is on the air however you could possibly save the X's location when the arrow is fired and then retrieve it when it lands a hit.
I was referring to the distance (blocks) that the arrow have traveled when shoots the player.
Not sure how that didn't answer your question?
I dont think that's something you can get from the arrow data itself. You could however. Get the player that fired the arrow and calulate the distance from the player to the player it hit.
Also you could get when the arrow is fired. Save that location. Run a timer that checks when the arrow hits the ground and compare those two locations. Whichever you prefer.
Why make it so complicated? My solution is by far the most convenient. A Map could be created storing an entity or whatever as a key and a location as a value. Whenever the arrow is fired save the entity(arrow) in the map with it's location as the value. By the time it lands with another event retrieve that entity(arrow) from the map and compare the distances.
That's basicly the same as mine, but you are just using an event to see if the arrow landed. Where as i'm using a runnable to check (basicly creating the event on your own). But yes that would be better then using a runnable.
Simply, just use the event onShoot and OnHit.
Saves each position in each event and calculates the distance between this positions