org.bukkit.event.entity.PlayerDeathEvent Java Examples
The following examples show how to use
org.bukkit.event.entity.PlayerDeathEvent.
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: PlayerDeathListener.java From PerWorldInventory with GNU General Public License v3.0 | 8 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); Group group = groupManager.getGroupFromWorld(player.getLocation().getWorld().getName()); if (!event.getKeepInventory()) { player.getInventory().clear(); } if (!event.getKeepLevel()) { player.setExp(event.getNewExp()); player.setLevel(event.getNewLevel()); } player.setFoodLevel(20); player.setSaturation(5f); player.setExhaustion(0f); player.setFallDistance(0f); player.setFireTicks(0); for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } playerManager.addPlayer(player, group); }
Example #2
Source File: PlayerDeathListener.java From PerWorldInventory with GNU General Public License v3.0 | 7 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); Group group = groupManager.getGroupFromWorld(player.getLocation().getWorld().getName()); if (!event.getKeepInventory()) { player.getInventory().clear(); } if (!event.getKeepLevel()) { player.setExp(event.getNewExp()); player.setLevel(event.getNewLevel()); } player.setFoodLevel(20); player.setSaturation(5f); player.setExhaustion(0f); player.setFallDistance(0f); player.setFireTicks(0); for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } playerManager.addPlayer(player, group); }
Example #3
Source File: CustomItemManager.java From civcraft with GNU General Public License v2.0 | 6 votes |
private boolean processDurabilityChanges(PlayerDeathEvent event, ItemStack stack, int i) { LoreCraftableMaterial craftMat = LoreCraftableMaterial.getCraftMaterial(stack); if (craftMat != null) { ItemChangeResult result = craftMat.onDurabilityDeath(event, stack); if (result != null) { if (!result.destroyItem) { event.getEntity().getInventory().setItem(i, result.stack); } else { event.getEntity().getInventory().setItem(i, new ItemStack(Material.AIR)); event.getDrops().remove(stack); return false; } } } return true; }
Example #4
Source File: QAListener.java From QualityArmory with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onDeathChat(PlayerDeathEvent e){ if(QAMain.changeDeathMessages){ if(e.getEntity().getKiller()!=null && e.getEntity().getKiller() instanceof Player){ Player killer = e.getEntity().getKiller(); if(e.getDeathMessage().contains(" using ")){ CustomBaseObject base = IronsightsHandler.getGunUsed(killer); if(base instanceof Gun){ e.setDeathMessage(((Gun) base).getDeathMessage() .replaceAll("%player%",e.getEntity().getDisplayName()) .replaceAll("%killer%",killer.getDisplayName()) .replaceAll("%name%",base.getDisplayName()) ); } } } } }
Example #5
Source File: DeathBansModule.java From UHC with MIT License | 6 votes |
@EventHandler public void on(PlayerDeathEvent event) { if (!isEnabled()) return; final UUID uuid = event.getEntity().getUniqueId(); // skip if there is already a timer running if (timers.containsKey(uuid)) return; final BanRunnable runnable = new BanRunnable(uuid); runnable.runTaskLater(plugin, delay * TICKS_PER_SECOND); timers.put(uuid, runnable); if (types.contains(BanType.MOVE_WORLD)) { final World world = Bukkit.getWorld(worldName); if (world == null) { plugin.getLogger() .severe("World for deathbans `" + worldName + "` does not exist, could not move player"); } else { event.getEntity().setBedSpawnLocation(world.getSpawnLocation(), true); } } }
Example #6
Source File: ListenerDamageDeath.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true) public void onDeath(PlayerDeathEvent e) { Player player = e.getEntity(); if(player.hasMetadata("NPC")) return; NPCManager npcManager = this.expansion.getNPCManager(); YamlConfiguration data = npcManager.getData(player); String deathMessage = data.getString("citizens-compatibility.last-death-message"); if(deathMessage == null) return; e.setDeathMessage(null); player.sendMessage(deathMessage); data.set("citizens-compatibility.last-death-message", null); npcManager.setData(player, data); }
Example #7
Source File: ItemKeepPlayerFacet.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
/** * NOTE: Must be called before {@link tc.oc.pgm.tracker.trackers.DeathTracker#onPlayerDeath(PlayerDeathEvent)} */ @SuppressWarnings("deprecation") @TargetedEventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void processPlayerDeath(PlayerDeathEvent event) { if(!player.isParticipating()) return; if(!rules.canKeepAny()) return; final Map<Slot, ItemStack> carrying = new HashMap<>(); Slot.Player.player().forEach(slot -> slot.item(event.getEntity()) .ifPresent(item -> carrying.put(slot, item))); kept.clear(); carrying.forEach((slot, item) -> { if(rules.canKeep(slot, item)) { event.getDrops().remove(item); kept.put(slot, item); } }); }
Example #8
Source File: DropOnDeath.java From Minepacks with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onDeath(PlayerDeathEvent event) { if(honorKeepOnDeath && event.getKeepInventory()) return; final Player player = event.getEntity(); if(plugin.isDisabled(player) != WorldBlacklistMode.None) return; if (!player.hasPermission(Permissions.KEEP_ON_DEATH)) { final Location location = player.getLocation(); plugin.getBackpack(player, new Callback<Backpack>() { @Override public void onResult(Backpack backpack) { backpack.drop(location); } @Override public void onFail() {} }); } }
Example #9
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 #10
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 #11
Source File: PlayerDeath.java From AdditionsAPI with MIT License | 6 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerDeath(PlayerDeathEvent event) { String msg = event.getDeathMessage(); if(msg!=null) { Debug.saySuper("Original Death Message: " + msg); for (CustomItem cItem : AdditionsAPI.getAllCustomItems()) { if (msg.contains(cItem.getDisplayName())) { msg.replaceFirst(LangFileUtils.get("death_message").replaceFirst("CustomItem", cItem.getDisplayName()), ""); Debug.saySuper("Replaced " + cItem.getDisplayName()); break; } } Debug.saySuper("Final Death Message: " + msg); event.setDeathMessage(msg); } }
Example #12
Source File: UCListener.java From UltimateChat with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onDeath(PlayerDeathEvent e) { Player p = e.getEntity(); if (UChat.get().getUCJDA() != null && !p.hasPermission(UChat.get().getUCConfig().getString("discord.vanish-perm"))) { Bukkit.getScheduler().runTaskAsynchronously(UChat.get(), () -> UChat.get().getUCJDA().sendRawToDiscord(UChat.get().getLang().get("discord.death").replace("{player}", p.getName()))); } }
Example #13
Source File: PetOwnerListener.java From SonarPet with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerDeath(PlayerDeathEvent event) { Player p = event.getEntity(); IPet pet = EchoPet.getManager().getPet(p); if (pet != null) { EchoPet.getManager().saveFileData("autosave", pet); EchoPet.getSqlManager().saveToDatabase(pet, false); EchoPet.getManager().removePet(pet, true); //p.sendMessage(Lang.REMOVE_PET_DEATH.toString()); } }
Example #14
Source File: CombatTagger.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onDeath(PlayerDeathEvent event) { String playerID = PlayerConverter.getID(event.getEntity()); tagged.remove(playerID); BukkitRunnable runnable = untaggers.remove(playerID); if (runnable != null) runnable.cancel(); }
Example #15
Source File: PetOwnerListener.java From EchoPet with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerDeath(PlayerDeathEvent event) { Player p = event.getEntity(); IPet pet = EchoPet.getManager().getPet(p); if (pet != null) { EchoPet.getManager().saveFileData("autosave", pet); EchoPet.getSqlManager().saveToDatabase(pet, false); EchoPet.getManager().removePet(pet, true); //p.sendMessage(Lang.REMOVE_PET_DEATH.toString()); } }
Example #16
Source File: Blitz.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); Optional<TeamModule> team = Teams.getTeamByPlayer(player); if (team.isPresent() && !team.get().isObserver()) { int oldMeta = this.getLives(player); player.removeMetadata("lives", Cardinal.getInstance()); player.setMetadata("lives", new LazyMetadataValue(Cardinal.getInstance(), LazyMetadataValue.CacheStrategy.NEVER_CACHE, new BlitzLives(oldMeta - 1))); if (this.getLives(player) == 0) { Teams.getTeamById("observers").get().add(player, true, false); player.removeMetadata("lives", Cardinal.getInstance()); } } }
Example #17
Source File: SentinelTrait.java From Sentinel with MIT License | 5 votes |
/** * 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 #18
Source File: DPlayerListener.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); if (isCitizensNPC(player)) { return; } DGamePlayer dPlayer = (DGamePlayer) dPlayers.getGamePlayer(player); if (dPlayer == null) { return; } dPlayer.onDeath(event); }
Example #19
Source File: FlagSpectate.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGH) public void onPlayerDeath(PlayerDeathEvent event) { SpleefPlayer player = getHeavySpleef().getSpleefPlayer(event.getEntity()); if (!isSpectating(player)) { return; } event.getDrops().clear(); deadPlayers.add(player); }
Example #20
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 #21
Source File: UHPluginListener.java From KTP with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerDeath(final PlayerDeathEvent ev) { Location l = ev.getEntity().getLocation(); for (Player ps : Bukkit.getOnlinePlayers()) { ps.playSound(ps.getLocation(), Sound.ENTITY_WITHER_SPAWN, 1F, 1F); } this.p.addDead(ev.getEntity().getName()); Bukkit.getScheduler().runTaskLater(this.p, new BukkitRunnable() { @Override public void run() { p.setLife((Player)ev.getEntity(), 0); } }, 1L); if (this.p.getConfig().getBoolean("kick-on-death.kick", true)) { Bukkit.getScheduler().runTaskLater(this.p, new BukkitRunnable() { @Override public void run() { ev.getEntity().kickPlayer("jayjay"); } }, 20L*this.p.getConfig().getInt("kick-on-death.time", 30)); } try { ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal()); SkullMeta skullMeta = (SkullMeta) skull.getItemMeta(); skullMeta.setOwner(((Player)ev.getEntity()).getName()); skullMeta.setDisplayName(ChatColor.RESET + ((Player)ev.getEntity()).getName()); skull.setItemMeta(skullMeta); l.getWorld().dropItem(l, skull); } catch (Exception e) { e.printStackTrace(); } }
Example #22
Source File: StatsListener.java From ScoreboardStats with MIT License | 5 votes |
/** * Tracks player deaths and kills * * @param deathEvent the death event. */ @EventHandler public void onDeath(PlayerDeathEvent deathEvent) { Player killed = deathEvent.getEntity(); //killer is null if it's not a player Player killer = killed.getKiller(); if (killed.equals(killer)) { return; } if (Settings.isActiveWorld(killed.getWorld().getName())) { ReplaceManager replaceManager = ReplaceManager.getInstance(); database.getStats(killed).ifPresent(killedCache -> { killedCache.onDeath(); replaceManager.forceUpdate(killed, "deaths", killedCache.getDeaths()); replaceManager.forceUpdate(killed, "kdr", killedCache.getKdr()); //will reset replaceManager.forceUpdate(killed, "current_streak", killedCache.getCurrentStreak()); }); database.getStats(killer).ifPresent(killercache -> { killercache.onKill(); replaceManager.forceUpdate(killer, "kills", killercache.getKills()); replaceManager.forceUpdate(killer, "kdr", killercache.getKdr()); //maybe the player reaches a new high score replaceManager.forceUpdate(killer, "killstreak", killercache.getKillstreak()); replaceManager.forceUpdate(killer, "current_streak", killercache.getCurrentStreak()); }); } }
Example #23
Source File: PlayerEvents.java From askyblock with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onVistorDeath(final PlayerDeathEvent e) { if (DEBUG) { plugin.getLogger().info(e.getEventName()); } if (!IslandGuard.inWorld(e.getEntity())) { return; } // Mute death messages if (Settings.muteDeathMessages) { e.setDeathMessage(null); } // If visitors will keep items and their level on death // This will override any global settings if (Settings.allowVisitorKeepInvOnDeath) { // If the player is not a visitor then they die and lose everything - // sorry :-( Island island = plugin.getGrid().getProtectedIslandAt(e.getEntity().getLocation()); if (island != null && !island.getMembers().contains(e.getEntity().getUniqueId())) { // They are a visitor InventorySave.getInstance().savePlayerInventory(e.getEntity()); e.getDrops().clear(); e.setKeepLevel(true); e.setDroppedExp(0); } } }
Example #24
Source File: JoinRequester.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerDeath(PlayerDeathEvent event) { SpleefPlayer player = heavySpleef.getSpleefPlayer(event.getEntity()); if (!checking.containsKey(player)) { return; } handleFail(player, FailCause.DEATH, null); }
Example #25
Source File: NoCleanListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerDeath(PlayerDeathEvent e){ if (e.getEntity().getKiller() != null){ Player killer = e.getEntity().getKiller().getPlayer(); pvpCooldown.put(killer.getUniqueId(), System.currentTimeMillis() + duration*TimeUtils.SECOND); killer.sendMessage(Lang.SCENARIO_NOCLEAN_INVULNERABLE); } }
Example #26
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 #27
Source File: PlayerDeathListenerTest.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
@Test public void shouldNotResetExp() { // given Player player = mock(Player.class); given(player.getInventory()).willReturn(mock(PlayerInventory.class)); given(player.getActivePotionEffects()).willReturn(new ArrayList<>()); Location loc = mock(Location.class); World world = mock(World.class); given(player.getLocation()).willReturn(loc); given(loc.getWorld()).willReturn(world); given(world.getName()).willReturn("test"); Group group = mockGroup("test"); given(groupManager.getGroupFromWorld("test")).willReturn(group); List<ItemStack> drops = new ArrayList<>(); PlayerDeathEvent event = new PlayerDeathEvent(player, drops, 5, 5, 5, 5, "Bob died."); event.setKeepLevel(true); // when listener.onPlayerDeath(event); // then verify(player, never()).setExp(5); verify(player, never()).setLevel(5); }
Example #28
Source File: PlayerDeathListenerTest.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
@Test public void shouldResetExp() { // given Player player = mock(Player.class); given(player.getInventory()).willReturn(mock(PlayerInventory.class)); given(player.getActivePotionEffects()).willReturn(new ArrayList<>()); Location loc = mock(Location.class); World world = mock(World.class); given(player.getLocation()).willReturn(loc); given(loc.getWorld()).willReturn(world); given(world.getName()).willReturn("test"); Group group = mockGroup("test"); given(groupManager.getGroupFromWorld("test")).willReturn(group); List<ItemStack> drops = new ArrayList<>(); PlayerDeathEvent event = new PlayerDeathEvent(player, drops, 5, 5, 5, 5, "Bob died."); event.setKeepLevel(false); // when listener.onPlayerDeath(event); // then verify(player).setExp(5); verify(player).setLevel(5); }
Example #29
Source File: DurabilityBar.java From AdditionsAPI with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onDeath(PlayerDeathEvent event) { Bukkit.getScheduler().scheduleSyncDelayedTask(AdditionsAPI.getInstance(), () -> { sendDurabilityBossBar(event.getEntity(), event.getEntity().getInventory().getItemInMainHand(), EquipmentSlot.HAND); sendDurabilityBossBar(event.getEntity(), event.getEntity().getInventory().getItemInOffHand(), EquipmentSlot.OFF_HAND); }); }
Example #30
Source File: ArmorListener.java From AdditionsAPI with MIT License | 5 votes |
@EventHandler public void playerDeathEvent(PlayerDeathEvent e){ Player p = e.getEntity(); for(ItemStack i : p.getInventory().getArmorContents()){ if(!isAirOrNull(i)){ Bukkit.getServer().getPluginManager().callEvent(new ArmorEquipEvent(p, EquipMethod.DEATH, ArmorType.matchType(i), i, null)); // No way to cancel a death event. } } }