Weird exeption; Cannot cast. Please help!

Discussion in 'Plugin Development' started by FirecatHD, Feb 20, 2014.

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

    FirecatHD

    So i am coding a rocket launcher, and everything works but every time i the arrow hits something it spams the console and says that it cannot pass ProjectileHitEvent to Rocket_Frenzy 1,0.

    I am think i have forgotten to check for something, but idk what so if you can please help :)

    Code:java
    1. package me.FirecatHD.RocketFrenzy;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.Effect;
    7. import org.bukkit.entity.Arrow;
    8. import org.bukkit.entity.HumanEntity;
    9. import org.bukkit.entity.LivingEntity;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.entity.Projectile;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.entity.ProjectileHitEvent;
    15. import org.bukkit.potion.PotionEffect;
    16. import org.bukkit.potion.PotionEffectType;
    17.  
    18. public class RocketListener implements Listener {
    19.  
    20. public static List<String> fraggerKit = new ArrayList<String>();
    21.  
    22. public static List<String> getFraggerKit() {
    23. return fraggerKit;
    24. }
    25.  
    26. @EventHandler
    27. public void onProjectileHit(ProjectileHitEvent e) {
    28. Projectile p = e.getEntity();
    29. if (!(p.getShooter() instanceof Player)) return;
    30. if (!(p instanceof Arrow)) return;
    31. if (!fraggerKit.contains (((HumanEntity) p.getShooter()).getName())) return;
    32. Arrow a = (Arrow) p;
    33.  
    34. p.getWorld().playEffect(p.getLocation(), Effect.POTION_BREAK, 3);
    35. p.getWorld().playEffect(p.getLocation(), Effect.POTION_BREAK, 5);
    36. p.getWorld().playEffect(p.getLocation(), Effect.SMOKE, 0);
    37.  
    38. p.getShooter().addPotionEffect(new PotionEffect(
    39. PotionEffectType.BLINDNESS, 1, 2));
    40. p.getShooter().addPotionEffect(new PotionEffect(
    41. PotionEffectType.SLOW, 1, 2 ));
    42.  
    43. a.getWorld().createExplosion(a.getLocation(), 2); {
    44.  
    45. List<org.bukkit.entity.Entity> nearbyEntities = a.getNearbyEntities(3, 3, 3);
    46. for (int i = 0; i < nearbyEntities.size(); i++) {
    47. //if (nearbyEntities.get(i) instanceof LivingEntity) {
    48. //LivingEntity living = (LivingEntity) nearbyEntities.get(i);
    49. //living.damage(0D);
    50.  
    51. nearbyEntities.get(i);
    52. ((LivingEntity) p).addPotionEffect(new PotionEffect(
    53. PotionEffectType.BLINDNESS, 10, 2));
    54. }
    55. }
    56.  
    57. }
    58. }


    Thanks in advance :)
     
  2. Offline

    alex123099

    Post stack trace please
     
  3. Offline

    FirecatHD

    Attached Files:

  4. Offline

    AmShaegar

    Cannot cast CraftArrow to LivingEntitiy. Sounds legit, no?

    You are trying to add a potion effect to an arrow... Line 52.
     
  5. Offline

    FirecatHD

    Thanks, fixed it now :)
     
Thread Status:
Not open for further replies.

Share This Page