@EventHandler(priority = EventPriority.MONITOR) public void onEntityExplode(EntityExplodeEvent event) { for (Block block : event.blockList()) { for (Player player : Bukkit.getOnlinePlayers()) { Location location = block.getLocation(); location.setY(location.getY() + 1); Location playerLoc = player.getLocation(); if (playerLoc.getBlockX() == location.getBlockX() && playerLoc.getBlockY() == location.getBlockY() && playerLoc.getBlockZ() == location.getBlockZ()) { OfflinePlayer damager = (TntTracker.getWhoPlaced(event.getEntity()) != null ? Bukkit.getOfflinePlayer(TntTracker.getWhoPlaced(event.getEntity())) : null); Bukkit.getServer() .getPluginManager() .callEvent( new TrackerSpleefEvent( player, damager, (damager != null && damager.isOnline() ? ((Player) damager).getItemInHand() : null), Type.TNT)); } } } }
@EventHandler(priority = EventPriority.HIGHEST) public void onEntityExplode(EntityExplodeEvent event) { if (!event.isCancelled()) { List<Block> objectiveBlownUp = new ArrayList<>(); for (Block block : event.blockList()) { if (getBlocks().contains(block)) { objectiveBlownUp.add(block); } } boolean oldState = this.isTouched(); boolean blownUp = false; Player eventPlayer = null; int originalPercent = getPercent(); boolean touchMessage = false; for (Block block : objectiveBlownUp) { boolean blockDestroyed = false; if (TntTracker.getWhoPlaced(event.getEntity()) != null) { UUID player = TntTracker.getWhoPlaced(event.getEntity()); if (Bukkit.getOfflinePlayer(player).isOnline()) { if (TeamUtils.getTeamByPlayer(Bukkit.getPlayer(player)) == team) { event.blockList().remove(block); } else { if (!playersTouched.contains(player)) { playersTouched.add(player); TeamModule teamModule = TeamUtils.getTeamByPlayer(Bukkit.getPlayer(player)); if (this.show && !this.completed) { TeamUtils.getTeamChannel(teamModule) .sendLocalizedMessage( new LocalizedChatMessage( ChatConstant.UI_OBJECTIVE_DAMAGED_FOR, teamModule.getColor() + Bukkit.getPlayer(player).getName() + ChatColor.WHITE, ChatColor.AQUA + name + ChatColor.WHITE, teamModule.getCompleteName() + ChatColor.WHITE)); for (Player player1 : Bukkit.getOnlinePlayers()) { if (TeamUtils.getTeamByPlayer(player1) != null && TeamUtils.getTeamByPlayer(player1).isObserver()) { player1.sendMessage( new LocalizedChatMessage( ChatConstant.UI_OBJECTIVE_DAMAGED_FOR, teamModule.getColor() + Bukkit.getPlayer(player).getName() + ChatColor.WHITE, ChatColor.AQUA + name + ChatColor.WHITE, teamModule.getCompleteName() + ChatColor.WHITE) .getMessage(player1.getLocale())); } if (Settings.getSettingByName("Sounds") != null && Settings.getSettingByName("Sounds") .getValueByPlayer(player1) .getValue() .equalsIgnoreCase("on")) { player1.playSound(player1.getLocation(), Sound.FIREWORK_TWINKLE, 1, 1); } } touchMessage = true; } } blockDestroyed = true; blownUp = true; eventPlayer = Bukkit.getPlayer(player); } } else { if (!playersTouched.contains(player)) { playersTouched.add(player); } blockDestroyed = true; blownUp = true; } } else { blockDestroyed = true; blownUp = true; } if (blockDestroyed) { this.complete++; if (eventPlayer != null) this.playersCompleted.put( eventPlayer.getUniqueId(), (playersCompleted.containsKey(eventPlayer.getUniqueId()) ? playersCompleted.get(eventPlayer.getUniqueId()) + 1 : 1)); if ((this.complete / size) >= this.required && !this.completed) { this.completed = true; if (this.show) { for (Player player : Bukkit.getOnlinePlayers()) player.sendMessage( ChatColor.GRAY + new UnlocalizedChatMessage( "{0}", new LocalizedChatMessage( ChatConstant.UI_OBJECTIVE_DESTROYED, team.getCompleteName() + ChatColor.GRAY, ChatColor.AQUA + name + ChatColor.GRAY, getWhoDestroyed(player.getLocale()))) .getMessage(player.getLocale())); Bukkit.getLogger() .info( ChatColor.GRAY + new UnlocalizedChatMessage( "{0}", new LocalizedChatMessage( ChatConstant.UI_OBJECTIVE_DESTROYED, team.getCompleteName() + ChatColor.GRAY, ChatColor.AQUA + name + ChatColor.GRAY, getWhoDestroyed(Locale.getDefault().toString()))) .getMessage(Locale.getDefault().toString())); } ObjectiveCompleteEvent compEvent = new ObjectiveCompleteEvent(this, eventPlayer); Bukkit.getServer().getPluginManager().callEvent(compEvent); } } } if (!this.completed && blownUp) { ObjectiveTouchEvent touchEvent = new ObjectiveTouchEvent( this, eventPlayer, !oldState || (getPercent() != originalPercent), touchMessage); Bukkit.getServer().getPluginManager().callEvent(touchEvent); } } }