Most efficient way to track thrown enderpearls?

Discussion in 'Plugin Development' started by makskay, Jun 1, 2012.

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

    makskay

    I'm trying to track enderpearls thrown by a specific player so that I can determine where they land (the land location being the location of the pearl when velocity = 0). At the moment, I'm doing this by:
    1. Using a PlayerInteractEvent listener to schedule a Runnable set to run once, on the next tick, when a specific player throws an enderpearl (i.e. rightclicks with an enderpearl in hand).
    2. In the Runnable, which runs on the next tick, grabbing all Entities near the player and adding those which are enderpearls thrown by the player to a list of enderpearls to track.
    3. On every tick where the list isn't empty, check the velocity of each enderpearl in the list. If the velocity of the enderpearl is 0, do something at that pearl's current location, then remove the pearl from the list.
    Since this seems really unnecessarily complicated, is there a simpler or better way to do it? There doesn't seem to be a PlayerThrowEnderpearl event, which is basically what I'm looking for, but I can't shake the feeling that I am overcomplicating this entire process.
     
  2. Offline

    Njol

    You can likely use ProjectileHitEvent since EnderPearl is a Projectile and check whether event.getEntity() is an instance of EnderPearl. You can then get the player who shot it with ((EnderPearl) event.getEntity()).getShooter().
     
  3. Offline

    Prgr

    I am not sure what you need this for so I might not be adding anything helpful to this conversation :)
    Any way makskay you can also listen to the PlayerTeleportEvent and then check
    Code:
    event.getCause()==TeleportCause.ENDER_PEARL 
    That is pretty simple but I would like to know what your trying to do with this :)
     
  4. Offline

    makskay

    Njol That works great, thanks - didn't think to look for more generalized Projectile events that might apply :)

    Prgr I'm actually also already listening for PlayerTeleportEvents so that I can cancel them when they apply to a certain player and were caused by enderpearls. I'm attempting to use enderpearls as a targeting system for ranged, "magic-based" abilities, so the essential part here is detecting the location and thrower of the pearl when it hits.
     
Thread Status:
Not open for further replies.

Share This Page