Set projectile hit event cancelled if the projectile hit the player

Discussion in 'Plugin Development' started by VortexGmer, Mar 8, 2015.

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

    VortexGmer

    How would you cancel the projectile hit event of the player was the entity that got hit?
    this is my code and my intention is to have the player ride the ender pearl.
    Code:
        @EventHandler
        public void onProjectileLaunch(ProjectileLaunchEvent event) {
            Player player = (Player) event.getEntity().getShooter();
            if (event.getEntity().getShooter() instanceof Player && event.getEntity() instanceof EnderPearl) {
                event.getEntity().setPassenger(player);
            }
        @EventHandler
        public void onProjectileHitEvent(ProjectileHitEvent event){
            if(event.getEntity() instanceof EnderPearl){
                //WHAT
            }
        }
     
  2. Offline

    mine-care

    What if the shooter is a skeleton? This will throw you an error.

    If you are looking for when a projectile damages a player like an arrow hiting a player you'll need to use EntityDamageEvent or a subclass of it (EntityDamageByEntityEvent) that will allow you to cancel it.
     
  3. Offline

    VortexGmer

    No like The player is riding an ender pearl, right? and all goes fine until they start going downwards. The enderpearl hits the player and disappears, The player falls. how would you make the enderpearl NOT disappear?
     
  4. Offline

    CXdur

    @VortexGmer
    I don't think you're using the right event because that event is not even cancellable. I'm not quite sure how to fix your issue, but I don't think that's the answer. ProjectileHitEvent seems to be a very poor event because it doesn't really seem like you can get what it hits (if it even hits something that you can get - like another entity)
     
  5. Offline

    VortexGmer

    What about using the EntityDamgebyEntityEvent and see if the damger was an ender pearl and then if it was, respawn the enderpearl with the same velocity?
     
Thread Status:
Not open for further replies.

Share This Page