Java Code Examples for org.bukkit.event.entity.PlayerDeathEvent#getDrops()
The following examples show how to use
org.bukkit.event.entity.PlayerDeathEvent#getDrops() .
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: BlockListeners.java From CratesPlus with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onDeath(PlayerDeathEvent event) { if (!cratesPlus.getConfigHandler().isDisableKeySwapping()) return; String title; List<ItemStack> items = event.getDrops(); for (ItemStack item : items) { for (Map.Entry<String, Crate> crate : cratesPlus.getConfigHandler().getCrates().entrySet()) { if (!(crate.getValue() instanceof KeyCrate)) { continue; } KeyCrate keyCrate = (KeyCrate) crate.getValue(); Key key = keyCrate.getKey(); if (key == null) continue; title = key.getName(); if (item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().contains(title)) { event.getDrops().remove(item); cratesPlus.getCrateHandler().giveCrateKey(event.getEntity(), crate.getValue().getName(), item.getAmount(), false, true); return; } } } }
Example 2
Source File: ItemDropEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) @SuppressWarnings("unused") public void onDeathEvent(PlayerDeathEvent event) { Player player = event.getEntity(); if (!plugin.getWorldManager().isSkyWorld(player.getWorld())) { return; } if (!visitorsCanDrop && !plugin.playerIsOnIsland(player) && !plugin.playerIsInSpawn(player)) { event.setKeepInventory(true); return; } // Take over the drop, since Bukkit don't do this in a Metadatable format. for (ItemStack stack : event.getDrops()) { addDropInfo(player, stack); } }
Example 3
Source File: QuestItemHandler.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onDeath(final PlayerDeathEvent event) { if (event.getEntity().getGameMode() == GameMode.CREATIVE) { return; } final String playerID = PlayerConverter.getID(event.getEntity()); // check if there is data for this player; NPCs don't have data if (BetonQuest.getInstance().getPlayerData(playerID) == null) return; // this prevents the journal from dropping on death by removing it from // the list of drops final List<ItemStack> drops = event.getDrops(); final ListIterator<ItemStack> litr = drops.listIterator(); while (litr.hasNext()) { final ItemStack stack = litr.next(); if (Journal.isJournal(playerID, stack)) { litr.remove(); } // remove all quest items and add them to backpack if (Utils.isQuestItem(stack)) { BetonQuest.getInstance().getPlayerData(playerID).addItem(stack.clone(), stack.getAmount()); litr.remove(); } } }
Example 4
Source File: CustomItemListener.java From NBTEditor with GNU General Public License v3.0 | 6 votes |
@EventHandler private void playerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); for (ItemStack item : event.getDrops()) { CustomItem customItem = CustomItemManager.getCustomItem(item); if (verifyCustomItem(customItem, player, true)) { // This is very dirty, all "Details" classes need to be refactored. customItem.onPlayerDeath(event, new PlayerDetails(item, player) { @Override public void consumeItem() { if (_player.getGameMode() == GameMode.CREATIVE) return; _item.setAmount(_item.getAmount() - 1); } }); } } }
Example 5
Source File: PlayerDeathListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 5 votes |
/** * Prevents enhanced item dropped from death. * * @param e */ @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerDeath(PlayerDeathEvent e) { Player p = e.getEntity(); List<ItemStack> newInventory = new ArrayList<ItemStack>(); File playerFile = new File(m.getDataFolder() + "/death/" + p.getName() + ".yml"); FileConfiguration pFile = YamlConfiguration.loadConfiguration(playerFile); pFile.set("PlayerName", p.getName()); if (!e.getDrops().isEmpty() || e.getDrops() != null) { for (int i = 0; i < e.getDrops().size(); i++) { ItemStack stack = e.getDrops().get(i); if (stack.hasItemMeta()) { ItemMeta meta = stack.getItemMeta(); if (meta.hasLore()) { List<String> lore = meta.getLore(); for (String s : lore) { s = ChatColor.stripColor(s); if (s.contains(ChatColor.stripColor(Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) || s.contains(ChatColor.stripColor(Util.toColor(SettingsManager.lang.getString("lore.tradeableLore"))))) { newInventory.add(e.getDrops().get(i)); } } } } } ItemStack[] newStack = newInventory.toArray(new ItemStack[newInventory.size()]); pFile.set("Items", newStack); try { pFile.save(playerFile); } catch (IOException e1) { } e.getDrops().removeAll(newInventory); } }
Example 6
Source File: NineSlotsListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerDeath(PlayerDeathEvent e){ List<ItemStack> drops = e.getDrops(); // Remove all fill items. while (drops.remove(fillItem)){} }
Example 7
Source File: TimebombListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler (priority = EventPriority.HIGHEST) public void onPlayerDeath(PlayerDeathEvent e) { Player p = e.getEntity().getPlayer(); List<ItemStack> drops = new ArrayList<>(e.getDrops()); e.getDrops().removeAll(e.getDrops()); TimebombThread timebombThread = new TimebombThread(drops, p.getLocation().getBlock().getLocation(), p.getName(), delay); Bukkit.getScheduler().scheduleSyncDelayedTask(UhcCore.getPlugin(), timebombThread,1L); }
Example 8
Source File: KitLoading.java From AnnihilationPro with MIT License | 5 votes |
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true) public void RemoveDeathDrops(PlayerDeathEvent event) { //Player player = event.getEntity(); for(ItemStack s : new ArrayList<ItemStack>(event.getDrops())) { if(KitUtils.isSoulbound(s)) event.getDrops().remove(s); } }
Example 9
Source File: DropProtectListener.java From NyaaUtils with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerDeath(PlayerDeathEvent e) { if (plugin.cfg.dropProtectMode == DropProtectMode.OFF) return; UUID id = e.getEntity().getUniqueId(); if (bypassPlayer.containsKey(id)) return; List<ItemStack> dropStacks = e.getDrops(); Location loc = e.getEntity().getLocation(); Bukkit.getScheduler().runTaskLater(plugin, () -> { Collection<Entity> ents = loc.getWorld().getNearbyEntities(loc, 3, 3, 10); ents.stream() .flatMap(ent -> (ent instanceof Item) ? Stream.of((Item) ent) : Stream.empty()) .filter(i -> dropStacks.contains(i.getItemStack())) .forEach(dropItem -> items.put(dropItem.getEntityId(), id)); }, 1); }
Example 10
Source File: MainListener.java From ArmorStandTools with MIT License | 5 votes |
@EventHandler public void onPlayerDeath(PlayerDeathEvent event) { final Player p = event.getEntity(); List<ItemStack> drops = event.getDrops(); for(ArmorStandTool t : ArmorStandTool.values()) { drops.remove(t.getItem()); } if(p.getWorld().getGameRuleValue("keepInventory").equalsIgnoreCase("true")) return; if(Bukkit.getServer().getPluginManager().getPermission("essentials.keepinv") != null && Utils.hasPermissionNode(p, "essentials.keepinv", true)) return; if(plugin.savedInventories.containsKey(p.getUniqueId())) { drops.addAll(Arrays.asList(plugin.savedInventories.get(p.getUniqueId()))); plugin.savedInventories.remove(p.getUniqueId()); } }
Example 11
Source File: ProjectileMatchModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerDeathEvent(PlayerDeathEvent event) { for (ItemStack itemStack : event.getDrops()) { this.resetItemName(itemStack); } }
Example 12
Source File: QAListener.java From QualityArmory with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.HIGH) public void onDeath(PlayerDeathEvent e) { if (QAMain.reloadingTasks.containsKey(e.getEntity().getUniqueId())) { for (GunRefillerRunnable r : QAMain.reloadingTasks.get(e.getEntity().getUniqueId())) { if(e.getEntity().getGameMode()!=GameMode.CREATIVE){ Gun gun = QualityArmory.getGun(r.getItem()); if(gun != null){ Ammo ammotype = gun.getAmmoType(); if(ammotype !=null){ ItemStack ammo = QualityArmory.getCustomItemAsItemStack(ammotype); ammo.setAmount(r.getAddedAmount()); e.getDrops().add(ammo); } } } r.getTask().cancel(); DEBUG("Canceling reload task " + r.getTask().getTaskId()); } } QAMain.reloadingTasks.remove(e.getEntity().getUniqueId()); for (ItemStack is : new ArrayList<>(e.getDrops())) { if(is==null) continue; if (QualityArmory.isIronSights(is)) { e.getDrops().remove(is); DEBUG("Removing IronSights"); }else if (is.hasItemMeta() && is.getItemMeta().hasDisplayName() && is.getItemMeta().getDisplayName().contains(QAMain.S_RELOADING_MESSAGE)) { Gun g = QualityArmory.getGun(is); ItemMeta im = is.getItemMeta(); im.setDisplayName(g.getDisplayName()); is.setItemMeta(im); DEBUG("Removed Reloading suffix"); } } if (e.getDeathMessage() != null && e.getDeathMessage().contains(QualityArmory.getIronSightsItemStack().getItemMeta().getDisplayName())) { try { e.setDeathMessage(e.getDeathMessage().replace(QualityArmory.getIronSightsItemStack().getItemMeta().getDisplayName(), e.getEntity().getKiller().getInventory().getItemInOffHand().getItemMeta().getDisplayName())); DEBUG("Removing ironsights from death message and replaced with gun's name"); } catch (Error | Exception e34) { } } BulletWoundHandler.bleedoutMultiplier.remove(e.getEntity().getUniqueId()); BulletWoundHandler.bloodLevel.put(e.getEntity().getUniqueId(), QAMain.bulletWound_initialbloodamount); if (e.getEntity().getKiller() instanceof Player) { Player killer = e.getEntity().getKiller(); if (QualityArmory.isGun(killer.getItemInHand()) || QualityArmory.isIronSights(killer.getItemInHand())) { DEBUG("This player \"" + e.getEntity().getName() + "\" was killed by a player with a gun"); } else if (QualityArmory.isCustomItem(e.getEntity().getItemInHand())) { DEBUG("This player \"" + e.getEntity().getName() + "\" was killed by a player, but not with a gun"); } } }
Example 13
Source File: DeathStandsModule.java From UHC with MIT License | 4 votes |
@EventHandler(priority = EventPriority.HIGH) public void on(PlayerDeathEvent event) { if (!isEnabled()) return; final Player player = event.getEntity(); // make the player invisible for the duration of their death animation player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, DEATH_ANIMATION_TIME, 1)); final Location location = player.getLocation(); // create an armour stand at the player final ArmorStand stand = player.getWorld().spawn(location.clone().add(0, .2D, 0), ArmorStand.class); stand.setBasePlate(false); stand.setArms(true); // give the armour stand the death message as a name stand.setCustomName(STAND_PREFIX + event.getDeathMessage()); stand.setCustomNameVisible(true); // face the same direction as the player stand.getLocation().setDirection(location.getDirection()); // set the armour stand helmet to be looking at the same yaw stand.setHeadPose(new EulerAngle(Math.toRadians(location.getPitch()), 0, 0)); // use the player's velocity as a base and apply it to the stand stand.setVelocity( player.getVelocity() .clone() .multiply(PLAYER_VELOCITY_MULTIPLIER) .add(new Vector(0D, PLAYER_VELOICY_Y_ADDITIONAL, 0D)) ); // start with player's existing items in each slot (if exists) Map<EquipmentSlot, ItemStack> toSet = getItems(player.getInventory()); // overide with any saved items in the metadata toSet.putAll(getSavedSlots(player)); // filter out the invalid items toSet = Maps.filterValues(toSet, Predicates.not(EMPTY_ITEM)); final List<ItemStack> drops = event.getDrops(); for (final Map.Entry<EquipmentSlot, ItemStack> entry : toSet.entrySet()) { final ItemStack stack = entry.getValue(); if (stack == null) continue; // remove the first matching stack in the drop list removeFirstEquals(drops, stack); // set the item on the armour stand in the correct slot switch (entry.getKey()) { case HAND: stand.setItemInHand(stack); break; case HEAD: stand.setHelmet(stack); break; case CHEST: stand.setChestplate(stack); break; case LEGS: stand.setLeggings(stack); break; case FEET: stand.setBoots(stack); break; default: } } }