Java Code Examples for org.bukkit.entity.Ageable#isAdult()

The following examples show how to use org.bukkit.entity.Ageable#isAdult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemListener.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityKilled(EntityDeathEvent e) {
    if (e.getEntity().getType() != EntityType.SHEEP || !plugin.getConfig().getBoolean("options.sheep.dropMutton", true) || !e.getEntity().getWorld().isGameRule("doMobLoot") || !(e.getEntity() instanceof Ageable)) {
        return;
    }
    Ageable entity = (Ageable) e.getEntity();
    if (!entity.isAdult()) {
        return;
    }
    boolean fireaspect = false;
    int looting = 1;
    if (entity.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent dEvent = (EntityDamageByEntityEvent) entity.getLastDamageCause();
        if (dEvent.getDamager() != null && dEvent.getDamager() instanceof Player) {
            ItemStack hand = ((Player) dEvent.getDamager()).getItemInHand();
            fireaspect = hand.containsEnchantment(Enchantment.FIRE_ASPECT);
            if (hand.containsEnchantment(Enchantment.LOOT_BONUS_MOBS))
                looting += hand.getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS);
            if (looting < 1) //Incase a plugin sets an enchantment level to be negative
                looting = 1;
        } else if (dEvent.getDamager() != null && dEvent.getDamager() instanceof Arrow) {
            Arrow a = (Arrow) dEvent.getDamager();
            if (a.getFireTicks() > 0)
                fireaspect = true;
        }
    }
    if (entity.getLastDamageCause().getCause() == DamageCause.FIRE_TICK || entity.getLastDamageCause().getCause() == DamageCause.FIRE
            || entity.getLastDamageCause().getCause() == DamageCause.LAVA || fireaspect)
        e.getDrops().add(new ItemStack(Carbon.injector().cookedMuttonItemMat, random.nextInt(2) + 1 + random.nextInt(looting)));
    else
        e.getDrops().add(new ItemStack(Carbon.injector().muttonItemMat, random.nextInt(2) + 1 + random.nextInt(looting)));
}