org.bukkit.event.entity.EntityDeathEvent Java Examples
The following examples show how to use
org.bukkit.event.entity.EntityDeathEvent.
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: ExprAttacked.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) { if (!ScriptLoader.isCurrentEvent(EntityDamageEvent.class, EntityDeathEvent.class, VehicleDamageEvent.class, VehicleDestroyEvent.class)) { Skript.error("The expression 'victim' can only be used in a damage or death event", ErrorQuality.SEMANTIC_ERROR); return false; } final String type = parser.regexes.size() == 0 ? null : parser.regexes.get(0).group(); if (type == null) { this.type = EntityData.fromClass(Entity.class); } else { final EntityData<?> t = EntityData.parse(type); if (t == null) { Skript.error("'" + type + "' is not an entity type", ErrorQuality.NOT_AN_EXPRESSION); return false; } this.type = t; } return true; }
Example #2
Source File: GolemListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@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: EventListener.java From iDisguise with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
@EventHandler public void onEntityDeath(EntityDeathEvent event) { final LivingEntity livingEntity = event.getEntity(); final int entityId = livingEntity.getEntityId(); if(livingEntity instanceof Player) return; // we have a seperate method for players if(DisguiseManager.isDisguised(livingEntity)) { Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { public void run() { DisguiseManager.undisguise(livingEntity); } }, 100L); } Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { public void run() { EntityIdList.removeEntity(entityId); } }, 200L); }
Example #4
Source File: CustomDropListener.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onEntityDeath(EntityDeathEvent event) { int i = 0; while (event.getEntity().hasMetadata("betonquest-drops-" + i)) { try { List<MetadataValue> metadata = event.getEntity().getMetadata("betonquest-drops-" + i); for (MetadataValue m : metadata) { String item = m.asString(); int index = item.indexOf(':'); event.getDrops().add(new QuestItem(new ItemID(null, item.substring(0, index))) .generate(Integer.valueOf(item.substring(index + 1)))); } } catch (Exception e) { LogUtils.getLogger().log(Level.WARNING, "Error when dropping custom item from entity: " + e.getMessage()); LogUtils.logThrowable(e); } i++; } }
Example #5
Source File: DMobListener.java From DungeonsXL with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onEntityDeath(EntityDeathEvent event) { World world = event.getEntity().getWorld(); if (event.getEntity() instanceof LivingEntity) { LivingEntity entity = event.getEntity(); GameWorld gameWorld = plugin.getGameWorld(world); if (gameWorld != null) { if (gameWorld.isPlaying()) { DMob dMob = (DMob) plugin.getDungeonMob(entity); if (dMob != null) { dMob.onDeath(plugin, event); } } } } }
Example #6
Source File: IslandGuard.java From askyblock with GNU General Public License v2.0 | 6 votes |
/** * 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 #7
Source File: UHPluginListener.java From KTP with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onEntityDeath(EntityDeathEvent ev) { if (ev.getEntity() instanceof Ghast) { Bukkit.getLogger().info("Modifying drops for Ghast"); List<ItemStack> drops = new ArrayList<ItemStack>(ev.getDrops()); ev.getDrops().clear(); for (ItemStack i : drops) { if (i.getType() == Material.GHAST_TEAR) { Bukkit.getLogger().info("Added "+i.getAmount()+" ghast tear(s)"); ev.getDrops().add(new ItemStack(Material.GOLD_INGOT,i.getAmount())); } else { Bukkit.getLogger().info("Added "+i.getAmount()+" "+i.getType().toString()); ev.getDrops().add(i); } } } }
Example #8
Source File: StatsListener.java From ScoreboardStats with MIT License | 6 votes |
/** * 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 #9
Source File: TalismanListener.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@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 #10
Source File: EntityDeathListener.java From UhcCore with GNU General Public License v3.0 | 6 votes |
private void handleGoldDrop(EntityDeathEvent event){ if(enableGoldDrops && affectedMobs.contains(event.getEntityType())){ Random r = new Random(); if(r.nextInt(100) < chance){ int drop; try{ drop = min+r.nextInt(1+max-min); }catch(IllegalArgumentException e){ drop=0; } if(drop > 0){ ItemStack gold = new ItemStack(Material.GOLD_INGOT,drop); event.getDrops().add(gold); } } } }
Example #11
Source File: SentinelTrait.java From Sentinel with MIT License | 6 votes |
/** * 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 #12
Source File: Corpse.java From EliteMobs with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onDeath(EntityDeathEvent event) { EliteMobEntity eliteMobEntity = EntityTracker.getEliteMobEntity(event.getEntity()); if (eliteMobEntity == null) return; if (!eliteMobEntity.hasPower(this)) return; if (!event.getEntity().getLocation().getBlock().getType().equals(Material.AIR)) return; blocks.add(event.getEntity().getLocation().getBlock()); event.getEntity().getLocation().getBlock().setType(Material.BONE_BLOCK); new BukkitRunnable() { @Override public void run() { blocks.remove(event.getEntity().getLocation().getBlock()); if (event.getEntity().getLocation().getBlock().getType().equals(Material.BONE_BLOCK)) event.getEntity().getLocation().getBlock().setType(Material.AIR); } }.runTaskLater(MetadataHandler.PLUGIN, 20 * 60 * 2); }
Example #13
Source File: Talisman.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private static Player getPlayerByEventType(Event e) { if (e instanceof EntityDeathEvent) { return ((EntityDeathEvent) e).getEntity().getKiller(); } else if (e instanceof BlockBreakEvent) { return ((BlockBreakEvent) e).getPlayer(); } else if (e instanceof PlayerEvent) { return ((PlayerEvent) e).getPlayer(); } else if (e instanceof EntityEvent) { return (Player) ((EntityEvent) e).getEntity(); } else if (e instanceof EnchantItemEvent) { return ((EnchantItemEvent) e).getEnchanter(); } return null; }
Example #14
Source File: EffCancelDrops.java From Skript with GNU General Public License v3.0 | 6 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { cancelItems = parseResult.mark == 0 || parseResult.mark == 1; cancelExps = parseResult.mark == 0 || parseResult.mark == 2; if (ScriptLoader.isCurrentEvent(BlockBreakEvent.class)) { if (cancelItems && !CAN_CANCEL_BLOCK_ITEM_DROPS) { Skript.error("Cancelling drops of items in a block break event requires Minecraft 1.12 or newer"); return false; } } else if (!ScriptLoader.isCurrentEvent(EntityDeathEvent.class)) { Skript.error("The cancel drops effect can't be used outside of a death" + (CAN_CANCEL_BLOCK_ITEM_DROPS ? " or block break" : "") + " event"); return false; } if (isDelayed.isTrue()) { Skript.error("Can't cancel the drops anymore after the event has already passed"); return false; } return true; }
Example #15
Source File: DeathEvent.java From StackMob-3 with GNU General Public License v3.0 | 6 votes |
@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 #16
Source File: GolemListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@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 #17
Source File: ExprAttacker.java From Skript with GNU General Public License v3.0 | 6 votes |
@Nullable private static Entity getAttacker(final @Nullable Event e) { if (e == null) return null; if (e instanceof EntityDamageByEntityEvent) { if (((EntityDamageByEntityEvent) e).getDamager() instanceof Projectile) { final Object o = ProjectileUtils.getShooter((Projectile) ((EntityDamageByEntityEvent) e).getDamager()); if (o instanceof Entity) return (Entity) o; return null; } return ((EntityDamageByEntityEvent) e).getDamager(); // } else if (e instanceof EntityDamageByBlockEvent) { // return ((EntityDamageByBlockEvent) e).getDamager(); } else if (e instanceof EntityDeathEvent) { return getAttacker(((EntityDeathEvent) e).getEntity().getLastDamageCause()); } else if (e instanceof VehicleDamageEvent) { return ((VehicleDamageEvent) e).getAttacker(); } else if (e instanceof VehicleDestroyEvent) { return ((VehicleDestroyEvent) e).getAttacker(); } return null; }
Example #18
Source File: DeathEventListener.java From Plan with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR) public void onDeath(EntityDeathEvent event) { long time = System.currentTimeMillis(); LivingEntity dead = event.getEntity(); if (dead instanceof Player) { // Process Death SessionCache.getCachedSession(dead.getUniqueId()).ifPresent(Session::died); } try { EntityDamageEvent entityDamageEvent = dead.getLastDamageCause(); if (!(entityDamageEvent instanceof EntityDamageByEntityEvent)) { return; } EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) entityDamageEvent; Entity killerEntity = entityDamageByEntityEvent.getDamager(); UUID uuid = dead instanceof Player ? dead.getUniqueId() : null; handleKill(time, uuid, killerEntity); } catch (Exception e) { errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event, dead).build()); } }
Example #19
Source File: Implosion.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onDeath(EntityDeathEvent event) { EliteMobEntity eliteMob = EntityTracker.getEliteMobEntity(event.getEntity()); if (eliteMob == null) return; if (!eliteMob.hasPower(this)) return; new BukkitRunnable() { int counter = 0; @Override public void run() { if (counter < 20) for (int i = 0; i < 20; i++) event.getEntity().getLocation().getWorld().spawnParticle(Particle.PORTAL, event.getEntity().getLocation(), 1, 0.1, 0.1, 0.1, 1); if (counter > 20 * 3) { for (Entity entity : event.getEntity().getWorld().getNearbyEntities(event.getEntity().getLocation(), 10, 10, 10)) if (entity instanceof LivingEntity) entity.setVelocity(event.getEntity().getLocation().clone().subtract(entity.getLocation()).toVector().multiply(0.5)); cancel(); } counter++; } }.runTaskTimer(MetadataHandler.PLUGIN, 1, 0); }
Example #20
Source File: ZombieNecronomicon.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
@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 #21
Source File: BonusLoot.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onDeath(EntityDeathEvent event) { EliteMobEntity eliteMobEntity = EntityTracker.getEliteMobEntity(event.getEntity()); if (eliteMobEntity == null) return; if (!eliteMobEntity.hasPower(this)) return; LootTables.generateLoot(eliteMobEntity); }
Example #22
Source File: Spy.java From civcraft with GNU General Public License v2.0 | 5 votes |
@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 #23
Source File: DieObjective.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
@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 #24
Source File: EvtExperienceSpawn.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") private static void registerExecutor() { if (registeredExecutor) return; for (final Class<? extends Event> c : new Class[] {BlockExpEvent.class, EntityDeathEvent.class, ExpBottleEvent.class, PlayerFishEvent.class}) Bukkit.getPluginManager().registerEvent(c, new Listener() {}, SkriptConfig.defaultEventPriority.value(), executor, Skript.getInstance(), true); registeredExecutor = true; }
Example #25
Source File: EvtEntity.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("null") @Override public boolean check(final Event e) { if (types == null) return true; final Entity en = e instanceof EntityDeathEvent ? ((EntityDeathEvent) e).getEntity() : ((CreatureSpawnEvent) e).getEntity(); for (final EntityData<?> d : types) { if (d.isInstance(en)) return true; } return false; }
Example #26
Source File: ExprDrops.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable protected ItemType[] get(Event e) { return ((EntityDeathEvent) e).getDrops() .stream() .map(ItemType::new) .toArray(ItemType[]::new); }
Example #27
Source File: ExprDrops.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if (!ScriptLoader.isCurrentEvent(EntityDeathEvent.class)) { Skript.error("The expression 'drops' can only be used in death events", ErrorQuality.SEMANTIC_ERROR); return false; } return true; }
Example #28
Source File: BlockListener.java From civcraft with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onEntityDeath(EntityDeathEvent event) { Pasture pasture = Pasture.pastureEntities.get(event.getEntity().getUniqueId()); if (pasture != null) { pasture.onEntityDeath(event.getEntity()); } if (!ConfigTempleSacrifice.isValidEntity(event.getEntityType())) { return; } /* Check if we're 'inside' a temple. */ bcoord.setFromLocation(event.getEntity().getLocation()); HashSet<Buildable> buildables = CivGlobal.getBuildablesAt(bcoord); if (buildables == null) { return; } for (Buildable buildable : buildables) { if (buildable instanceof Temple) { if (buildable.getCorner().getY() <= event.getEntity().getLocation().getBlockY()) { /* We're 'above' the temple. Good enough. */ ((Temple)buildable).onEntitySacrifice(event.getEntityType()); } } } }
Example #29
Source File: EntityDamageListener.java From SaneEconomy with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onEntityDeath(EntityDeathEvent evt) { LivingEntity entity = evt.getEntity(); if (!this.damageDealt.containsKey(entity.getEntityId())) { return; } Map<UUID, Double> damageDoneToThisEntity = this.damageDealt.get(entity.getEntityId()); double totalDmg = entity.getMaxHealth();//sumValues(damageDoneToThisEntity); for (Map.Entry<UUID, Double> entry : damageDoneToThisEntity.entrySet()) { double thisDmg = entry.getValue(); double thisPercent = (thisDmg / totalDmg) * 100.0D; double thisAmount = this.plugin.getKillAmounts().get(this.getEntityType(entity)) * (thisPercent / 100); OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(entry.getKey()); if (offlinePlayer.isOnline()) { Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId()); this.plugin.getMessenger().sendMessage(player, "You have been awarded {1} for doing {2:.2f}% of the damage required to kill that {3}!", this.plugin.getSaneEconomy().getEconomyManager().getCurrency().formatAmount(BigDecimal.valueOf(thisAmount)), thisPercent, entity.getName()); } this.plugin.getSaneEconomy().getEconomyManager().transact(new Transaction( this.plugin.getSaneEconomy().getEconomyManager().getCurrency(), Economable.PLUGIN, Economable.wrap(offlinePlayer), BigDecimal.valueOf(thisAmount), TransactionReason.PLUGIN_GIVE )); } this.damageDealt.remove(evt.getEntity().getEntityId()); }
Example #30
Source File: EntityDeathListener.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@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); } }