Detecting When Player Interacts With Projectile

Discussion in 'Plugin Development' started by Smeary_Subset, Apr 30, 2023.

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

    Smeary_Subset

    I want to make it so a player can "catch" an ender pearl, by right clicking on it while it's flying by. I don't think PlayerInteractEvent works because that only fires when it's a block or air. EntityDamageByEntity doesn't work either because a player can't damage a projectile. Any ideas?
     
  2. Offline

    mehboss

    You can try and use PlayerInteractEntityEvent or PlayerInteractAtEntityEvent
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerInteractEntityEvent.html
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerInteractAtEntityEvent.html

    Not sure if it will work as I have never tried it before, but it should.
    • Check if interacting w/ enderpearl
    • Do whatever w/ that information (such as remove it and add it to catchers inventory)
     
    Last edited: Apr 30, 2023
  3. Offline

    Smeary_Subset

    Good suggestion. Unfortunately, after doing some testing, I found that it does not work. I tested that out on a number of different projectile and, oddly enough, it seems to be only called for fireballs and shulker bullets.

    I noticed that fireballs and shulker bullets are some of the only non-abstract classes that directly extend the Projectile class, while most of them have a middle man (for example, Trident and Arrow extend AbstractArrow which extend Projectile). EnderPearl extends ThrowableProjectile. I wonder if that has anything to do with it.

    The other two classes that directly extend Projectile are llama spit and fish hook. I couldn't seem to get it called for llamma spit (but it was difficult to hit it, so I might have missed it); and it was impossible to test for fish hooks because when I try to right click the hook it returns to the fishing rod, so I couldn't even get the opportunity to interact with it.
     
Thread Status:
Not open for further replies.

Share This Page