Solved Making skeletons shoot double arrows

Discussion in 'Plugin Development' started by mariosunny, Jul 29, 2015.

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

    mariosunny

    I want skeletons to fire two arrows instead of one.

    It is possible to launch a second arrow using World#spawnArrow() when a ProjectileLaunchEvent is thrown. However, World#spawnArrow() itself throws a ProjectileLaunchEvent, which makes this method infinitely recursive:
    Code:
    @EventHandler
    public void onProjectileLaunch(ProjectileLaunchEvent event) {
    
        Projectile projectile;
    
        projectile = event.getEntity();
    
        if(projectile.getShooter() instanceof Skeleton) {
       
            projectile.getWorld().spawnArrow(projectile.getLocation(), projectile.getVelocity(), (float) 0.6, 12);
        }
    }
    Anyone know a workaround? Thanks.

    Edit: Solved! The above code actually does work, but you have to be sure to check if the shooter of the projectile is null. If the shooter is null, then it was an artificially created arrow and another arrow should not be shot. Ensuring that the shooter is an instance of Skeleton ensures that the shooter is not null.
     
    Last edited: Jul 29, 2015
Thread Status:
Not open for further replies.

Share This Page