Search in sources :

Example 1 with MagicMobDeathEvent

use of com.elmakers.mine.bukkit.api.event.MagicMobDeathEvent in project MagicPlugin by elBukkit.

the class MobController method onEntityDeath.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
    // TODO: fix all of this, don't reference by names.
    Entity entity = event.getEntity();
    if (!(entity instanceof LivingEntity)) {
        return;
    }
    LivingEntity died = (LivingEntity) entity;
    String name = died.getCustomName();
    if (name == null || name.isEmpty()) {
        return;
    }
    // TODO Fix this
    EntityData mob = mobsByName.get(name);
    if (mob == null)
        return;
    MagicMobDeathEvent deathEvent = new MagicMobDeathEvent(controller, mob, event);
    Bukkit.getPluginManager().callEvent(deathEvent);
    if (!died.hasMetadata("nodrops")) {
        mob.modifyDrops(controller, event);
    }
    // Prevent double-deaths .. gg Mojang?
    // Kind of hacky to use this flag for it, but seemed easiest
    died.setCustomNameVisible(false);
    died.setCustomName(null);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) EntityData(com.elmakers.mine.bukkit.entity.EntityData) MagicMobDeathEvent(com.elmakers.mine.bukkit.api.event.MagicMobDeathEvent) EventHandler(org.bukkit.event.EventHandler)

Aggregations

MagicMobDeathEvent (com.elmakers.mine.bukkit.api.event.MagicMobDeathEvent)1 EntityData (com.elmakers.mine.bukkit.entity.EntityData)1 Entity (org.bukkit.entity.Entity)1 LivingEntity (org.bukkit.entity.LivingEntity)1 EventHandler (org.bukkit.event.EventHandler)1