Java Code Examples for org.bukkit.event.entity.EntityDeathEvent#getEntity()

The following examples show how to use org.bukkit.event.entity.EntityDeathEvent#getEntity() . 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: CustomItemManager.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void OnEntityDeath(EntityDeathEvent event) {
	if (event.getEntity() instanceof Player) {
		return;
	}
			
	/* Remove any vanilla item IDs that can't be crafted from vanilla drops. */
	LinkedList<ItemStack> removed = new LinkedList<ItemStack>();
	for (ItemStack stack : event.getDrops()) {
		Integer key = ItemManager.getId(stack);
		
		if (CivSettings.removedRecipies.containsKey(key)) {
			if (!LoreMaterial.isCustom(stack)) {
				removed.add(stack);
			}
		}
	}
	
	event.getDrops().removeAll(removed);
}
 
Example 2
Source File: GolemListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onGolemDeath(EntityDeathEvent event) {
    if (!(event.getEntity() instanceof IronGolem)) {
        return;
    }

    IronGolem ironGolem = (IronGolem) event.getEntity();
    for (String name : Main.getGameNames()) {
        Game game = Main.getGame(name);
        if ((game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) && ironGolem.getWorld().equals(game.getGameWorld())) {
            List<SpecialItem> golems = game.getActivedSpecialItems(Golem.class);
            for (SpecialItem item : golems) {
                if (item instanceof Golem) {
                    Golem golem = (Golem) item;
                    if (golem.getEntity().equals(ironGolem)) {
                        event.getDrops().clear();
                    }
                }
            }
        }
    }
}
 
Example 3
Source File: StatsListener.java    From ScoreboardStats with MIT License 6 votes vote down vote up
/**
 * Tracks the mob kills.
 *
 * @param event the death event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onMobDeath(EntityDeathEvent event) {
    LivingEntity entity = event.getEntity();
    //killer is null if it's not a player
    Player killer = entity.getKiller();

    //Check if it's not player because we are already handling it
    if (entity.getType() != EntityType.PLAYER && Settings.isActiveWorld(entity.getWorld().getName())) {
        database.getStats(killer).ifPresent(stats -> {
            //If the cache entry is loaded and the player isn't null, increase the mob kills
            stats.onMobKill();

            ReplaceManager.getInstance().forceUpdate(killer, "mob", stats.getMobkills());
        });
    }
}
 
Example 4
Source File: DeathEvent.java    From StackMob-3 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onDeath(EntityDeathEvent e) {
    LivingEntity dead = e.getEntity();
    if(!(dead instanceof Mob)){
        return;
    }
    if(!(StackTools.hasValidStackData(dead))){
        if(StackTools.hasValidData(dead)){
            sm.getLogic().cleanup(dead);
        }
        return;
    }
    int stackAmount = StackTools.getSize(dead);
    
    DeathStep method = sm.getDeathManager().calculateMethod(dead);
    int subtractAmount = sm.getDeathManager().calculateStep(dead, method);
    callEvent(dead, e, subtractAmount);
    multiplication(dead, e.getDrops(), subtractAmount - 1, e.getDroppedExp());
    if(subtractAmount != stackAmount){
        Entity entity = spawnNewEntity(stackAmount - subtractAmount, dead);
        if(method instanceof KillStepDamage){
            ((KillStepDamage)method).onceSpawned(dead, (LivingEntity) entity);
        }
    }
    sm.getLogic().cleanup(dead);
}
 
Example 5
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Drops the Enderman's block when he dies if he has one
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEndermanDeath(final EntityDeathEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (!Settings.endermanDeathDrop)
        return;
    if (!inWorld(e.getEntity())) {
        return;
    }
    if (!(e.getEntity() instanceof Enderman)) {
        // plugin.getLogger().info("Not an Enderman!");
        return;
    }
    // Get the block the enderman is holding
    Enderman ender = (Enderman) e.getEntity();
    MaterialData m = ender.getCarriedMaterial();
    if (m != null && !m.getItemType().equals(Material.AIR)) {
        // Drop the item
        // plugin.getLogger().info("Dropping item " + m.toString());
        e.getEntity().getWorld().dropItemNaturally(e.getEntity().getLocation(), m.toItemStack(1));
    }
}
 
Example 6
Source File: TalismanListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onKill(EntityDeathEvent e) {
    if (e.getDrops().isEmpty() || e.getEntity().getKiller() == null) {
        return;
    }

    LivingEntity entity = e.getEntity();

    if (!(entity instanceof Player) && !(entity instanceof ArmorStand) && Talisman.checkFor(e, SlimefunItems.TALISMAN_HUNTER)) {
        Collection<ItemStack> extraDrops = getExtraDrops(e.getEntity(), e.getDrops());

        for (ItemStack drop : extraDrops) {
            if (drop != null) {
                e.getDrops().add(drop.clone());
            }
        }
    }
}
 
Example 7
Source File: LifeskillingListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Killing mobs gives enhancement stone.
 *
 * @param e
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onKilling(EntityDeathEvent e) {
    // If the killed entity is a monster
    if (e.getEntity() instanceof Monster) {
        if (e.getEntity().getKiller() instanceof Player) {
            Player player = e.getEntity().getKiller();
            if (DropManager.killingChance > random.nextDouble()) {
                DropManager.randomDrop(player, DropManager.killingLootTable);
            }
        }
    }
}
 
Example 8
Source File: Spy.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPlayerDeath(EntityDeathEvent event, ItemStack stack) {
	
	Player player = (Player)event.getEntity();
	Resident resident = CivGlobal.getResident(player);
	if (resident == null || !resident.hasTown()) {
		return;
	}
	
	
	ArrayList<String> bookout = MissionLogger.getMissionLogs(resident.getTown());
	
	ItemStack book = new ItemStack(Material.WRITTEN_BOOK, 1);
	BookMeta meta = (BookMeta) book.getItemMeta();
	ArrayList<String> lore = new ArrayList<String>();
	lore.add("Mission Report");
	meta.setAuthor("Mission Reports");
	meta.setTitle("Missions From "+resident.getTown().getName());
	
	String out = "";
	for (String str : bookout) {
		out += str+"\n";
	}
	BookUtil.paginate(meta, out);			

	
	meta.setLore(lore);
	book.setItemMeta(meta);
	player.getWorld().dropItem(player.getLocation(), book);
	
}
 
Example 9
Source File: BukkitExpListener.java    From Parties with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityDie(EntityDeathEvent event) {
	if (BukkitConfigMain.ADDITIONAL_EXP_ENABLE && BukkitConfigMain.ADDITIONAL_EXP_DROP_ENABLE) {
		Entity killedEntity = event.getEntity();
		
		if (event.getEntity().getKiller() != null) {
			PartyPlayerImpl killer = plugin.getPlayerManager().getPlayer(event.getEntity().getKiller().getUniqueId());
			if (!killer.getPartyName().isEmpty()) {
				if (checkForMythicMobsHandler(event)) {
					return;
				}
				double vanillaExp = 0;
				double skillapiExp = 0;
				
				if (BukkitConfigMain.ADDITIONAL_EXP_DROP_GET_NORMAL)
					vanillaExp = event.getDroppedExp();
				if (BukkitConfigMain.ADDITIONAL_EXP_DROP_GET_SKILLAPI)
					skillapiExp = SkillAPIHandler.getExp(killedEntity);
				
				ExpDrop drop = new ExpDrop((int) vanillaExp, (int) skillapiExp, killer, killedEntity);
				boolean result = plugin.getExpManager().distributeExp(drop);
				if (result && BukkitConfigMain.ADDITIONAL_EXP_DROP_CONVERT_REMOVEREALEXP) {
					// Remove exp from vanilla event if hooked
					if (BukkitConfigMain.ADDITIONAL_EXP_DROP_GET_NORMAL)
						event.setDroppedExp(0);
					// Remove exp drop from SkillAPI
					if (BukkitConfigMain.ADDITIONAL_EXP_DROP_GET_SKILLAPI)
						SkillAPIHandler.fakeEntity(killedEntity);
					
					plugin.getLoggerManager().logDebug(PartiesConstants.DEBUG_EXP_REMOVINGEXP
							.replace("{value1}", Boolean.toString(BukkitConfigMain.ADDITIONAL_EXP_DROP_GET_NORMAL))
							.replace("{value2}", Boolean.toString(BukkitConfigMain.ADDITIONAL_EXP_DROP_GET_SKILLAPI)), true);
				}
			}
		}
	}
}
 
Example 10
Source File: ListenerRewards.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onDeath(EntityDeathEvent e) {
    LivingEntity entity = e.getEntity();
    Player killer = entity.getKiller();
    if(killer == null) return;

    List<Reward> rewardList = this.expansion.getAllRewards();
    for(Reward reward : rewardList) reward.tryActivate(killer, entity);
}
 
Example 11
Source File: ZombieNecronomicon.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onSummonedCreatureDeath(EntityDeathEvent event) {

    if (event.getEntity() instanceof Zombie && EntityTracker.isEliteMob(event.getEntity()) && event.getEntity().getCustomName() != null &&
            (event.getEntity().getCustomName().equals(ConfigValues.translationConfig.getString("ZombieNecronomicon.Summoned zombie")) ||
                    event.getEntity().getCustomName().equals(ConfigValues.translationConfig.getString("ZombieNecronomicon.Summoned skeleton"))))
        event.getDrops().clear();

}
 
Example 12
Source File: MobKillListener.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onKill(EntityDeathEvent event) {
    LivingEntity entity = event.getEntity();
    Player killer = entity.getKiller();
    if (killer != null) {
        MobKillNotifier.addKill(killer, entity);
    }
}
 
Example 13
Source File: DieObjective.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDeath(EntityDeathEvent event) {
    if (cancel) {
        return;
    }
    if (event.getEntity() instanceof Player) {
        String playerID = PlayerConverter.getID((Player) event.getEntity());
        if (containsPlayer(playerID) && checkConditions(playerID)) {
            completeObjective(playerID);
        }
    }
}
 
Example 14
Source File: EntityListener.java    From Guilds with MIT License 5 votes vote down vote up
/**
 * Handles extra XP dropped from mobs
 *
 * @param event
 */
@EventHandler
public void onMobDeath(EntityDeathEvent event) {
    if (!(event.getEntity() instanceof Monster)) return;
    Monster monster = (Monster) event.getEntity();
    Player killer = monster.getKiller();
    if (killer == null) return;
    Guild guild = guildHandler.getGuild(killer);
    if (guild == null) {
        return;
    }
    double xp = event.getDroppedExp();
    double multiplier = guild.getTier().getMobXpMultiplier();
    event.setDroppedExp((int) Math.round(xp * multiplier));
}
 
Example 15
Source File: LWCPlayerListener.java    From Modern-LWC with MIT License 5 votes vote down vote up
@EventHandler
public void onDeath(EntityDeathEvent e) {
    Entity entity = e.getEntity();
    if (plugin.getLWC().isProtectable(e.getEntity().getType())) {
        int A = 50000 + entity.getUniqueId().hashCode();
        Player player = e.getEntity().getKiller();
        LWC lwc = LWC.getInstance();
        Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A);
        if (protection != null) {
            boolean canAccess = lwc.canAccessProtection(player, protection);
            boolean canAdmin = lwc.canAdminProtection(player, protection);
            try {
                if (player != null) {
                    LWCProtectionDestroyEvent evt = new LWCProtectionDestroyEvent(player, protection,
                            LWCProtectionDestroyEvent.Method.ENTITY_DESTRUCTION, canAccess, canAdmin);
                    lwc.getModuleLoader().dispatchEvent(evt);
                } else {
                    protection.remove();
                    protection.removeAllPermissions();
                    protection.removeCache();
                }
            } catch (Exception ex) {
                if (player != null) {
                    lwc.sendLocale(player, "protection.internalerror", "id", "ENTITY_DEATH");
                }
                lwc.sendLocale(Bukkit.getServer().getConsoleSender(), "protection.internalerror", "id",
                        "ENTITY_DEATH");
                ex.printStackTrace();
            }
        }
    }
}
 
Example 16
Source File: EntityDeathListener.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
    try {
        final LivingEntity entity = event.getEntity();
        final Player killer = entity.getKiller();
        if (killer == null) return;

        final Location location = killer.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        if (!islandManager.isIslandWorld(location)) return;

        final User user = User.getUser(killer);
        final Island userIsland = user.getIsland();
        if (userIsland == null) return;

        for (Mission mission : IridiumSkyblock.getMissions().missions) {
            final Map<String, Integer> levels = userIsland.getMissionLevels();
            levels.putIfAbsent(mission.name, 1);

            final MissionData level = mission.levels.get(levels.get(mission.name));
            if (level.type != MissionType.ENTITY_KILL) continue;

            final List<String> conditions = level.conditions;
            if (conditions.isEmpty() || conditions.contains(entity.toString()))
                userIsland.addMission(mission.name, 1);
        }

        if (userIsland.getExpBooster() != 0)
            event.setDroppedExp(event.getDroppedExp() * 2);
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 17
Source File: DMob.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
public void onDeath(DungeonsXL plugin, EntityDeathEvent event) {
    LivingEntity victim = event.getEntity();
    DGameWorld gameWorld = (DGameWorld) plugin.getGameWorld(victim.getWorld());
    String name = null;

    if (gameWorld == null) {
        return;
    }

    DungeonMobDeathEvent dMobDeathEvent = new DungeonMobDeathEvent(this);
    Bukkit.getServer().getPluginManager().callEvent(dMobDeathEvent);
    if (dMobDeathEvent.isCancelled()) {
        return;
    }

    if (type instanceof DMobType) {
        event.getDrops().clear();

        for (ItemStack itemStack : ((DMobType) type).getDrops().keySet()) {
            Random randomGenerator = new Random();
            int random = randomGenerator.nextInt(100);

            if (((DMobType) type).getDrops().get(itemStack) > random) {
                event.getDrops().add(itemStack);
            }
        }

        name = type.getId();

    } else if (isExternalMob() && trigger != null) {
        name = trigger;

    } else {
        name = VanillaMob.get(victim.getType()).getId();
    }

    MobTrigger mobTrigger = MobTrigger.getByName(name, gameWorld);
    if (mobTrigger != null) {
        mobTrigger.onTrigger();
    }

    Set<WaveTrigger> waveTriggers = WaveTrigger.getByGameWorld(gameWorld);
    for (WaveTrigger waveTrigger : waveTriggers) {
        if (((DGame) gameWorld.getGame()).getWaveKills() >= Math.ceil(gameWorld.getMobCount() * waveTrigger.getMustKillRate())) {
            waveTrigger.onTrigger();
        }
    }

    gameWorld.removeMob(this);
}
 
Example 18
Source File: KillsMobsListener.java    From Statz with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDie(final EntityDeathEvent event) {

    final PlayerStat stat = PlayerStat.KILLS_MOBS;

    Entity e = event.getEntity();

    if (!(e.getLastDamageCause() instanceof EntityDamageByEntityEvent)) {
        return;
    }

    PlayerStatSpecification specification;

    EntityDamageByEntityEvent nEvent = (EntityDamageByEntityEvent) e.getLastDamageCause();
    if (nEvent.getDamager() instanceof Player) {
        // Entity died because of Player
        // Killer
        final Player player = (Player) nEvent.getDamager();

        // Do general check
        if (!plugin.doGeneralCheck(player, stat))
            return;

        if (e instanceof Player) {
            // Player killed player
            // Handled by other listener
        } else {
            // Player killed mob

            String mobType = StatzUtil.getMobType(e);

            String weapon = "";

            ItemStack item = player.getInventory().getItemInMainHand();

            if (item.getType() == Material.AIR) {
                weapon = "HAND";
            } else {
                weapon = item.getType().toString();
            }

            specification = new KillsMobsSpecification(player.getUniqueId(), 1, player.getWorld().getName(),
                    mobType, weapon);

            // Update value to new stat.
            plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery());

        }
    } else if (nEvent.getDamager() instanceof Arrow) {
        // Entity was killed by an arrow, now check if it was shot by a player
        Arrow killerArrow = (Arrow) nEvent.getDamager();

        if (killerArrow.getShooter() instanceof Player) {
            Player shooter = (Player) killerArrow.getShooter();

            specification = new KillsMobsSpecification(shooter.getUniqueId(), 1, shooter.getWorld().getName(),
                    StatzUtil.getMobType(e), "BOW");

            // Now update database.
            plugin.getDataManager().setPlayerInfo(shooter.getUniqueId(), stat, specification.constructQuery());
        }
    }

    //
}
 
Example 19
Source File: ActionListener.java    From ActionHealth with MIT License 4 votes vote down vote up
@EventHandler
public void onDeath(EntityDeathEvent event) {
    Entity entity = event.getEntity();
    main.configStore.actionStore.remove(entity.getUniqueId());
}
 
Example 20
Source File: LootTables.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onDeath(EntityDeathEvent event) {

    if (event.getEntity() == null) return;

    EliteMobEntity eliteMobEntity = EntityTracker.getEliteMobEntity(event.getEntity());
    if (eliteMobEntity == null) return;

    if (!eliteMobEntity.getHasSpecialLoot()) return;

    if (eliteMobEntity.getLevel() < 2) return;

    Item item = generateLoot(eliteMobEntity);

    if (item == null) return;

    RareDropEffect.runEffect(item);

}