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") { } } }
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 if(e.getDamager() instaceof Arrow) {Arrow arrow = (Arrow) e.getDamager();if(arrow.getShooter() instanceof Player) {Player p = (Player) arrow.getShooter();if(p.getIteminHand().getType() == Material.BOW) {if(p.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Legendary Bow") {//effect}}} Sorry if it's kind of sloppy, I didn't write it in eclipse. If this doesn't work, let me know.