Applying a potion effect via arrow

Discussion in 'Plugin Development' started by TCO_007, Jun 8, 2014.

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

    TCO_007

    Hi! I am trying to figure out how to apply the weakness potion effect to the player the arrow of the kit atlatl had hit. In other words, I want the player who threw the arrow (The atlatl kit) to hit a player with that arrow and when they do, it adds the potion effect of weakness for 20 seconds to the player it hit. Can anyone help? I have 2 seperate listeners for the kit atlatl which are shown here:
    Code:
    @EventHandler
        public void onAtlatlThrow(PlayerInteractEvent e){
            final Player player = e.getPlayer();
            if (e.getAction() == Action.RIGHT_CLICK_AIR && player.getItemInHand().getType() == Material.ARROW){
                Arrow arrow = player.launchProjectile(Arrow.class);
            //    arrow.setMetadata(null, null , );
                if (player.getGameMode() != GameMode.CREATIVE){
                    if (player.getItemInHand().getAmount() > 1){
                        player.getItemInHand().setAmount(player.getItemInHand().getAmount() - 1);
                        arrow.setVelocity(player.getLocation().getDirection().multiply(2));
                       
                    }else{
                        arrow.setVelocity(player.getLocation().getDirection().multiply(2));
                        player.setItemInHand(new ItemStack(Material.AIR));    }
                }
               
            }
        }
    Code:java
    1. @EventHandler
    2. public void OnAtlatlArrowHit(EntityDamageByEntityEvent e){
    3. Arrow arrow = (Arrow) e.getDamager();
    4. Player hit = (Player) e.getEntity();
    5. Player shooter = (Player)((Arrow) e.getEntity()).getShooter();
    6. if (plugin.Atlatl.contains(shooter.getName())){
    7. if (e.getCause().equals(DamageCause.PROJECTILE)){
    8. hit.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 20*20, 1));
    9. }
    10. }
    11. }
    12. }

    I create the second listener to try to apply that potion effect to the player it hit but it will not work. Can anyone help me?
     
  2. Offline

    mine-care

    Check projectile hit event and get if entity is arrow, it it is make a arrow instance and then get nearby entities and apply the potion while looping ANC checking for the closest one, or if there is a way to get entity hit by arrow, idk
     
Thread Status:
Not open for further replies.

Share This Page