Solved Player location

Discussion in 'Spigot Plugin Development' started by OopsyPoopsy, Apr 21, 2017.

  1. Hello Spigot.

    I'm trying to track a players location from before they move, PlayerMoveEvent has getFrom() and getTo()
    but is there any way I can access these from EntityDamageByEntityEvent? Or is there a way to check if a player has been attacked in a PlayerMoveEvent?

    ~ Thank You
     
  2. You would need to write their location to a variable outside of the player move event where the entitydamage event can access it.

    It could be a hashMap of <Player><Location> lastMove

    Then when the damage event fires if the entity is InstanceOf player.

    location last = lastMove.getPlayer();
    If last != null
    Compare their last position to their current position

    Note you will probably want to use a distance check when updating the location in player move, because player move fires OFTEN. Just wiggling your mouse will fire it a lot. So be cautious what you do in onPlayerMove.

    Finally you always need to check that the world in the saved list is == the players current world before measuring distance, if you fail to do this and a player teleports to a different world you'll get an error because you can not measure distance between worlds.




    Sent from my iPhone using Tapatalk
     
  3. You could check if the Player's velocity isn't 0. It's better than storing it in a hashmap 20 times per second
     
  4. Well, when a player is hit they are automatically moved back due to knock back.

    When they are hit, add that player to an array list. Inside the PlayerMoveEvent, check if they are contained in the array list. The list will store their previous location

    If they are in the list, do what you want and then remove them.

    If they are not in the list, don't do anything.
     
  5. Hmm. So you are trying to get the location where they got hit, and the location they were hit to (knockbacked)?
     
  6. yeah pretty much, to see if the player even takes knockback
     
  7. I tried that exactly and it did the exact opposite of what i wanted it to do
     
  8. Anti knockback hacks bypass velocity statements in the code, i would do it with protocollib but I'm not familiar with the API