EntityDamageByEntityEvent

Discussion in 'Plugin Development' started by MoeMix, Feb 3, 2014.

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

    MoeMix

    So I fixed my cooldown, but using this code the squids won't spawn...Can anyone spot what I did wrong?
    Code:java
    1. private ArrayList<Player> cooldown = new ArrayList<Player>();
    2.  
    3. @EventHandler
    4. public void onsnowballfallevent(EntityDamageByEntityEvent event){
    5. if(event.getDamager() instanceof Snowball){
    6. Player p = (Player) event.getEntity();
    7. Snowball snowball = (Snowball) event.getDamager();
    8. final Player damager = (Player) snowball.getShooter();
    9. if(!cooldown.contains(damager)){
    10. Entity e = event.getEntity();
    11. Location l = e.getLocation();
    12. World world = l.getWorld();
    13. EntityType mob = EntityType.SQUID;
    14. world.spawnEntity(l, mob);
    15. world.playEffect(l, Effect.MOBSPAWNER_FLAMES, 20);
    16. p.sendMessage(ChatColor.BLUE + "You were attacked by " + ChatColor.RED + damager.getName());
    17. cooldown.add(damager);
    18. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    19. public void run(){
    20. cooldown.remove(damager);
    21. }
    22. }, 100);
    23.  
    24. }else if(cooldown.contains(damager)){
    25. event.setCancelled(true);
    26. }
    27. }
    28. }
    29. }


    bump, anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  2. Offline

    ThePlayerPaul

    MoeMix I tried that code and it works!
     
  3. Offline

    MoeMix

    :O hm ok ill check whats goin on on my end.
     
  4. Offline

    ThePlayerPaul

  5. Offline

    MoeMix

    ThePlayerPaul I am getting an error saying Cannot pass EntityDamageByEntityEvent. Any ideas why?
     
  6. Offline

    rangersmash

    Post the stack trace so we can see the errors ;) MoeMix
     
  7. Offline

    MoeMix

  8. Offline

    rangersmash

    Ahh, you are casting the entity to a player, which isn't a player. So what you need to do is check that (event.getEntity() instanceof Player) before you cast anything ;) MoeMix
     
  9. Offline

    MoeMix

    but I want to somehow get the shooter of the entity rangersmash

    rangersmash, do I just put if(event.getEntity() instanceof Player) as the first thing and keep everything else the same?

    Bump, I have been trying to get this to work for a few hours now but can't get it. Does anyone know what my casting mistake is and where I can fix it?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page