Effects on arrows

Discussion in 'Plugin Development' started by creppii, Jul 25, 2014.

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

    creppii

    Hey :)

    whats the best method to do this:

    if a player with a bow named "Legendary Bow" fires an arrow and this arrow hit a player, the hitted player should get blindness...

    thats what i tried, but doesnt work and i think thats not a good method:


    Code:
    public void playerHitEvent(EntityDamageByEntityEvent e) {
    e.getEntity().getWorld().playEffect(e.getEntity().getLocation(), Effect.STEP_SOUND, 10);
    public void playerHitEvent(EntityDamageByEntityEvent e) {
            e.getEntity().getWorld().playEffect(e.getEntity().getLocation(), Effect.STEP_SOUND, 10);
     
            Player test = (Player)e.getDamager();
            if(e.getDamager() instanceof Arrow){
                /* Cast Projectile to the damager */
                Projectile egg = (Projectile) e.getDamager();
                Player p = (Player)e.getDamager();
                if(test.getItemInHand().getItemMeta().getDisplayName() == "§6§l§k#§r§e§lLegendary Bow") {
             
                }
            }
        }
     
  2. Offline

    AnOrangeGamer

    You're checking if e.getDamager() is an instance of an Arrow, yet you still cast e.getDamager() to a player and a random projectile (you should change (Projectile) to (Arrow)). Therefore the lines
    Projectile egg = (Projectile) e.getDamager(); and Player p = (Player) e.getDamager(); will throw an error and stop the code there (not entirely sure it stops the code, I'm just using knowledge from my experiences). This is what you should do instead:

    Code:java
    1. if(e.getDamager() instaceof Arrow) {
    2. Arrow arrow = (Arrow) e.getDamager();
    3. if(arrow.getShooter() instanceof Player) {
    4. Player p = (Player) arrow.getShooter();
    5. if(p.getIteminHand().getType() == Material.BOW) {
    6. if(p.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Legendary Bow") {
    7. //effect
    8. }
    9. }
    10. }


    Sorry if it's kind of sloppy, I didn't write it in eclipse.

    If this doesn't work, let me know.
     
  3. Offline

    creppii

Thread Status:
Not open for further replies.

Share This Page