Search in sources :

Example 26 with Monster

use of org.bukkit.entity.Monster in project modules-extra by CubeEngine.

the class ListenerDeath method onEntityDeath.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
    // TODO handle when there is no reference on lookup of dependent actions
    DeathKill killAction = this.newAction(DeathKill.class, event.getEntity().getWorld());
    if (killAction != null) {
        // TODO check config for killer type
        killAction.setLocation(event.getEntity().getLocation());
        EntityDamageEvent cause = event.getEntity().getLastDamageCause();
        if (cause == null) {
            killAction.otherKiller = DamageCause.CUSTOM;
        } else if (cause instanceof EntityDamageByEntityEvent) {
            Entity damager = ((EntityDamageByEntityEvent) cause).getDamager();
            if (damager instanceof Player) {
                killAction.playerKiller = new PlayerSection((Player) damager);
            } else if (damager instanceof Projectile) {
                killAction.projectile = true;
                if (((Projectile) damager).getShooter() instanceof Entity) {
                    if (((Projectile) damager).getShooter() instanceof Player) {
                        killAction.playerKiller = new PlayerSection((Player) ((Projectile) damager).getShooter());
                    } else {
                        killAction.entityKiller = new EntitySection((Entity) ((Projectile) damager).getShooter());
                    }
                } else {
                    killAction.entityKiller = new EntitySection(damager);
                }
            } else {
                killAction.entityKiller = new EntitySection(damager);
            }
        } else {
            killAction.otherKiller = cause.getCause();
        }
        this.logAction(killAction);
    }
    Reference<DeathKill> reference = this.reference(killAction);
    LivingEntity killed = event.getEntity();
    if (killed instanceof Player) {
        DeathPlayer action = this.newAction(DeathPlayer.class, killed.getWorld());
        if (action != null) {
            action.killer = reference;
            action.setPlayer((Player) killed);
            this.logAction(action);
        }
        if (this.isActive(DeathDrop.class, event.getEntity().getWorld())) {
            Reference<DeathPlayer> deathRef = this.reference(action);
            for (ItemStack itemStack : event.getDrops()) {
                PlayerDeathDrop dropAction = newAction(PlayerDeathDrop.class);
                dropAction.item = itemStack;
                dropAction.death = deathRef;
                this.logAction(dropAction);
            }
        }
        return;
    }
    Class<? extends EntityDeathAction> actionType;
    if (killed instanceof Wither || killed instanceof EnderDragon) {
        actionType = DeathBoss.class;
    } else if (killed instanceof Animals) {
        if (killed instanceof Tameable && ((Tameable) killed).isTamed()) {
            actionType = DeathPet.class;
        } else {
            actionType = DeathAnimal.class;
        }
    } else if (killed instanceof Villager) {
        actionType = DeathNpc.class;
    } else if (killed instanceof Monster) {
        actionType = DeathMonster.class;
    } else {
        actionType = DeathOther.class;
    }
    EntityDeathAction action = this.newAction(actionType, killed.getWorld());
    if (action != null) {
        action.setKilled(killed);
        action.setLocation(killed.getLocation());
        action.killer = reference;
        this.logAction(action);
    }
    Reference<EntityDeathAction> deathRef = this.reference(action);
    if (this.isActive(DeathDrop.class, event.getEntity().getWorld())) {
        for (ItemStack itemStack : event.getDrops()) {
            DeathDrop dropAction = newAction(DeathDrop.class);
            dropAction.item = itemStack;
            dropAction.death = deathRef;
            this.logAction(dropAction);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.spongepowered.api.entity.Entity) PlayerSection(org.cubeengine.module.log.action.block.player.ActionPlayerBlock.PlayerSection) LivingEntity(org.bukkit.entity.LivingEntity) EnderDragon(org.bukkit.entity.EnderDragon) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) EntitySection(org.cubeengine.module.log.action.block.entity.ActionEntityBlock.EntitySection) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Wither(org.bukkit.entity.Wither) Player(org.spongepowered.api.entity.player.Player) Tameable(org.bukkit.entity.Tameable) Projectile(org.bukkit.entity.Projectile) Animals(org.bukkit.entity.Animals) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) ItemStack(org.spongepowered.api.item.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 27 with Monster

use of org.bukkit.entity.Monster in project Towny by ElgarL.

the class TownyEntityListener method onEntityDeath.

/**
 * Prevent monsters from dropping blocks if within an arena plot.
 *
 * @param event
 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
    if (plugin.isError()) {
        return;
    }
    Entity entity = event.getEntity();
    if (entity instanceof Monster) {
        Location loc = entity.getLocation();
        TownyWorld townyWorld = null;
        try {
            townyWorld = TownyUniverse.getDataSource().getWorld(loc.getWorld().getName());
            // remove drops from monster deaths if in an arena plot
            if (townyWorld.isUsingTowny()) {
                if (townyWorld.getTownBlock(Coord.parseCoord(loc)).getType() == TownBlockType.ARENA)
                    event.getDrops().clear();
            }
        } catch (NotRegisteredException e) {
        // Unknown world or not in a town
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Monster(org.bukkit.entity.Monster) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) Location(org.bukkit.Location) BlockLocation(com.palmergames.bukkit.towny.regen.block.BlockLocation) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Monster (org.bukkit.entity.Monster)27 EventHandler (org.bukkit.event.EventHandler)22 Player (org.bukkit.entity.Player)18 LivingEntity (org.bukkit.entity.LivingEntity)16 Animals (org.bukkit.entity.Animals)15 Entity (org.bukkit.entity.Entity)14 Villager (org.bukkit.entity.Villager)11 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)10 Projectile (org.bukkit.entity.Projectile)9 Location (org.bukkit.Location)8 Slime (org.bukkit.entity.Slime)8 Squid (org.bukkit.entity.Squid)8 IronGolem (org.bukkit.entity.IronGolem)6 Snowman (org.bukkit.entity.Snowman)6 Island (com.wasteofplastic.acidisland.Island)4 Island (com.wasteofplastic.askyblock.Island)4 Golem (org.bukkit.entity.Golem)4 Hanging (org.bukkit.entity.Hanging)4 UUID (java.util.UUID)3 ArmorStand (org.bukkit.entity.ArmorStand)3