Could not pass event EntityDeathEvent Error

Discussion in 'Plugin Development' started by Bib, Jul 29, 2014.

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

    Bib

    When ever I kill a mob I get this "Could not pass event EntityDeathEvent" error, how would I fix this?

    Code:java
    1. @EventHandler
    2. public void entityDeath(EntityDeathEvent e) {
    3. Monster monsterEnt = (Monster) e.getEntity();
    4. Player pl = (Player) monsterEnt.getKiller();
    5. if (pl.hasPermission("gold.ba")) {
    6. if (e.getEntity().getType() == EntityType.CREEPER) {
    7. ItemStack drops = new ItemStack(Material.DIAMOND);
    8. e.getEntity().getWorld().dropItem(e.getEntity().getLocation(), drops);
    9. }
    10. }
    11. }
     
  2. Offline

    HeadGam3z

    You're casting the entity to a monster without checking it's a monster or not. Pigs, sheep, chickens, cows, etc are not monsters (at least not on the outside)
     
    Bib likes this.
  3. Offline

    JWhy

    Replace
    Code:java
    1. Monster monsterEnt = (Monster) e.getEntity();

    by
    Code:java
    1. Creature monsterEnt = (Creature) e.getEntity();

    Since the event can trigger for non-hostiles (Monsters) too (in this case cows and sheeps)
     
    Bib likes this.
  4. Offline

    Bib

Thread Status:
Not open for further replies.

Share This Page