Getting what mob died...

Discussion in 'Plugin Development' started by Windows_i7_920, Feb 27, 2012.

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

    Windows_i7_920

    How would I go about getting the name of the mob that died when a player kills one? I need a bit of an explanation on this, as I have no idea since theres no e.getType.getName() or anything...

    Code:
        @EventHandler
        public void onEntityDeath(EntityDeathEvent e)
        {
           
           
        }
     
  2. Offline

    Morthis

    Get the entity and then do a check for instanceof.

    For example: if (entity instanceof Creeper)

    Edit: Here's an example.

    Code:
        @EventHandler
        public void onEntityDeath(EntityDeathEvent e) {
            Entity entity = e.getEntity();
            if (entity instanceof Creeper) {
                // Do something
            }
        }
     
    Windows_i7_920 likes this.
  3. Offline

    Sorroko

    This is a slightly hackish way but will give you the name of any entity in one line :D :
    Code:
    String MobName = entity.getClass().getSimpleName().replace("Craft", "")
     
  4. Offline

    Njol

    event.getEntity().getType().toString() is better, as it will also work on non-craftbukkit servers.
     
  5. Offline

    Seadragon91

    There is no: event.getEntity().getType().toString()
     
  6. Offline

    Njol

  7. Offline

    Seadragon91

Thread Status:
Not open for further replies.

Share This Page