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

The following examples show how to use org.bukkit.event.entity.EntityDeathEvent#setDroppedExp() . 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: SentinelTrait.java    From Sentinel with MIT License 6 votes vote down vote up
/**
 * Called when any entity dies.
 */
public void whenSomethingDies(EntityDeathEvent event) {
    UUID id = event.getEntity().getUniqueId();
    if (needsDropsClear.contains(id)) {
        needsDropsClear.remove(id);
        if (event.getEntity().getType() != EntityType.PLAYER) {
            if (SentinelPlugin.debugMe) {
                debug("A " + event.getEntity().getType() + " with id " + id + " died. Clearing its drops.");
            }
            event.getDrops().clear();
            event.setDroppedExp(0);
        }
    }
    else {
        if (SentinelPlugin.debugMe) {
            debug("A " + event.getEntity().getType() + " with id " + id + " died, but that's none of my business.");
        }
    }
    targetingHelper.removeTarget(id);
}
 
Example 2
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 3
Source File: Pickup.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onDeath(EntityDeathEvent event) {
    if(isSpawned() && event.getEntity().equals(entity.get())) {
        event.setDroppedExp(0);
        event.getDrops().clear();
        despawn(false);
    }
}
 
Example 4
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 5
Source File: EntityDeathListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
private void handleMobLoot(EntityDeathEvent event){
	EntityType entity = event.getEntityType();
	if(mobLoots.containsKey(entity)){
		MobLootConfiguration lootConfig = mobLoots.get(entity);
		event.getDrops().clear();
		event.getDrops().add(lootConfig.getLoot().clone());
		event.setDroppedExp(lootConfig.getAddXp());
		UhcItems.spawnExtraXp(event.getEntity().getLocation(),lootConfig.getAddXp());
	}
}
 
Example 6
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 7
Source File: BukkitExpListener.java    From Parties with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Used to hook into Mythic Mobs mobs handling
 * necessary to completely remove exp from the mob
 *
 * @return Returns true to cancel main event
 */
private boolean checkForMythicMobsHandler(EntityDeathEvent event) {
	boolean ret = false;
	if (BukkitConfigMain.ADDITIONAL_EXP_DROP_ADDITIONAL_MYTHICMOBS_ENABLE) {
		if (MythicMobsHandler.isMythicMob(event.getEntity())) {
			// Mythic Mob
			
			// Remove experience of mobs if handled by MythicMobHandler
			if (BukkitConfigMain.ADDITIONAL_EXP_DROP_CONVERT_REMOVEREALEXP
					&& BukkitConfigMain.ADDITIONAL_EXP_DROP_GET_NORMAL
					&& event.getDroppedExp() > 0
					&& MythicMobsHandler.getMobsExperienceToSuppress().remove(event.getEntity().getUniqueId())) {
				// We already know that the killer is a Player
				// Remove entity experience if the event has been handled by MythicMobHandler
				// This is a workaround to fix MythicMobs exp drop bug
				event.setDroppedExp(0);
			}
			
			plugin.getLoggerManager().logDebug(PartiesConstants.DEBUG_EXP_MMBYPASS, true);
			// MythicMobHandler will handle this event
			ret = true;
		} else {
			// Non Mythic Mob
			if (BukkitConfigMain.ADDITIONAL_EXP_DROP_ADDITIONAL_MYTHICMOBS_HANDLEONLYMMMOBS) {
				// Return after this method ends
				ret = true;
			}
		}
	}
	return ret;
}
 
Example 8
Source File: SentinelTrait.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Called when the NPC dies.
 */
public void whenWeDie(EntityDeathEvent event) {
    if (SentinelPlugin.debugMe) {
        debug("Died! Death event received.");
    }
    event.getDrops().clear();
    if (event instanceof PlayerDeathEvent && !SentinelPlugin.instance.deathMessages) {
        ((PlayerDeathEvent) event).setDeathMessage("");
    }
    if (!SentinelPlugin.instance.workaroundDrops) {
        event.getDrops().addAll(getDrops());
    }
    event.setDroppedExp(0);
    generalDeathHandler(event.getEntity());
}
 
Example 9
Source File: PowerUps.java    From HolographicDisplays with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
	
	if (event.getEntityType() == EntityType.ZOMBIE) {

		// Remove normal drops and exp.
		event.getDrops().clear();
		event.setDroppedExp(0);
		
		// Spawn the floating item with a label.
		final Hologram hologram = HologramsAPI.createHologram(this, event.getEntity().getLocation().add(0.0, 0.9, 0.0));
		hologram.appendTextLine(ChatColor.AQUA  + "" + ChatColor.BOLD + "Speed PowerUp");
		ItemLine icon = hologram.appendItemLine(new ItemStack(Material.SUGAR));
		
		icon.setPickupHandler(new PickupHandler() {
			
			@Override
			public void onPickup(Player player) {
				
				// Play an effect.
				player.playEffect(hologram.getLocation(), Effect.MOBSPAWNER_FLAMES, null);
				
				// 30 seconds of speed II.
				player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 30 * 20, 1), true);
				
				// Delete the hologram.
				hologram.delete();
				
			}
		});
		
	}
}
 
Example 10
Source File: BonusXpListener.java    From MarriageMaster with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setEventExp(EntityDeathEvent event, double xp, Object o, MarriagePlayer player, Marriage marriage)
{
	BonusXPDropEvent bonusXPDropEvent = new BonusXPDropEvent(player, marriage, (int) Math.round(xp));
	Bukkit.getServer().getPluginManager().callEvent(bonusXPDropEvent);
	if(!bonusXPDropEvent.isCancelled())
	{
		event.setDroppedExp(bonusXPDropEvent.getAmount());
	}
}
 
Example 11
Source File: DefaultDropsHandler.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
    public void onDeath(EntityDeathEvent event) {

        if (!EntityTracker.isEliteMob(event.getEntity())) return;

        if (!EntityTracker.isNaturalEntity(event.getEntity()) &&
                !ConfigValues.itemsDropSettingsConfig.getBoolean(ItemsDropSettingsConfig.SPAWNER_DEFAULT_LOOT_MULTIPLIER))
            return;

        List<ItemStack> droppedItems = event.getDrops();
        int mobLevel = (int) (EntityTracker.getEliteMobEntity(event.getEntity()).getLevel() *
                ConfigValues.itemsDropSettingsConfig.getDouble(ItemsDropSettingsConfig.DEFAULT_LOOT_MULTIPLIER));

        if (mobLevel > ConfigValues.itemsDropSettingsConfig.getInt(ItemsDropSettingsConfig.MAXIMUM_LEVEL_FOR_LOOT_MULTIPLIER))
            mobLevel = ConfigValues.itemsDropSettingsConfig.getInt(ItemsDropSettingsConfig.MAXIMUM_LEVEL_FOR_LOOT_MULTIPLIER);

        inventoryItemsConstructor(event.getEntity());

        for (ItemStack itemStack : droppedItems) {

//                ItemStack can be null for some reason, probably due to other plugins
            if (itemStack == null) continue;
            boolean itemIsWorn = false;

            for (ItemStack wornItem : wornItems)
                if (wornItem.isSimilar(itemStack))
                    itemIsWorn = true;

            if (!itemIsWorn)
                for (int i = 0; i < mobLevel * 0.1; i++)
                    event.getEntity().getLocation().getWorld().dropItem(event.getEntity().getLocation(), itemStack);

        }

        mobLevel = (int) (EntityTracker.getEliteMobEntity(event.getEntity()).getLevel() *
                ConfigValues.itemsDropSettingsConfig.getDouble(ItemsDropSettingsConfig.EXPERIENCE_LOOT_MULTIPLIER));

        int droppedXP = (int) (event.getDroppedExp() + event.getDroppedExp() * 0.1 * mobLevel);
        event.setDroppedExp(0);
        event.getEntity().getWorld().spawn(event.getEntity().getLocation(), ExperienceOrb.class).setExperience(droppedXP);

    }