public String getWhoDestroyed(String locale) { String whoDestroyed = ""; List<String> toCombine = new ArrayList<>(); for (UUID player : MiscUtils.getSortedHashMapKeyset(playersCompleted)) { if (getPercentFromAmount(playersCompleted.get(player)) > (100 / 3)) { toCombine.add( TeamUtils.getTeamColorByPlayer(Bukkit.getPlayer(player)) + Bukkit.getPlayer(player).getName() + ChatColor.GRAY + " (" + getPercentFromAmount(playersCompleted.get(player)) + "%)"); } } if (toCombine.size() == 0) { toCombine.add( ChatColor.DARK_AQUA + new LocalizedChatMessage(ChatConstant.MISC_ENEMY).getMessage(locale)); } if (toCombine.size() < playersCompleted.keySet().size()) { toCombine.add( ChatColor.DARK_AQUA + new LocalizedChatMessage(ChatConstant.MISC_OTHERS).getMessage(locale)); } whoDestroyed = toCombine.get(0); for (int i = 1; i < toCombine.size(); i++) { whoDestroyed += ChatColor.GRAY + (i == toCombine.size() - 1 ? " " + new LocalizedChatMessage(ChatConstant.MISC_AND).getMessage(locale) + " " : ", ") + toCombine.get(i); } return whoDestroyed; }
@EventHandler(priority = EventPriority.HIGHEST) public void onBlockBreak(BlockBreakEvent event) { if (!event.isCancelled()) { if (getBlocks().contains(event.getBlock())) { if (TeamUtils.getTeamByPlayer(event.getPlayer()) != team) { boolean touchMessage = false; if (!playersTouched.contains(event.getPlayer().getUniqueId())) { playersTouched.add(event.getPlayer().getUniqueId()); TeamModule teamModule = TeamUtils.getTeamByPlayer(event.getPlayer()); if (this.show && !this.completed) { TeamUtils.getTeamChannel(teamModule) .sendLocalizedMessage( new LocalizedChatMessage( ChatConstant.UI_OBJECTIVE_DAMAGED_FOR, teamModule.getColor() + event.getPlayer().getName() + ChatColor.WHITE, ChatColor.AQUA + name + ChatColor.WHITE, teamModule.getCompleteName() + ChatColor.WHITE)); for (Player player : Bukkit.getOnlinePlayers()) { if (TeamUtils.getTeamByPlayer(player) != null && TeamUtils.getTeamByPlayer(player).isObserver()) { player.sendMessage( new LocalizedChatMessage( ChatConstant.UI_OBJECTIVE_DAMAGED_FOR, teamModule.getColor() + event.getPlayer().getName() + ChatColor.WHITE, ChatColor.AQUA + name + ChatColor.WHITE, teamModule.getCompleteName() + ChatColor.WHITE) .getMessage(player.getLocale())); } if (Settings.getSettingByName("Sounds") != null && Settings.getSettingByName("Sounds") .getValueByPlayer(player) .getValue() .equalsIgnoreCase("on")) { player.playSound(player.getLocation(), Sound.FIREWORK_TWINKLE, 1, 1); } } } } boolean oldState = this.isTouched(); this.complete++; this.playersCompleted.put( event.getPlayer().getUniqueId(), (playersCompleted.containsKey(event.getPlayer().getUniqueId()) ? playersCompleted.get(event.getPlayer().getUniqueId()) + 1 : 1)); if ((this.complete / size) >= this.required && !this.completed) { this.completed = true; event.setCancelled(false); 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())); } FireworkUtil.spawnFirework( event.getPlayer().getLocation(), event.getPlayer().getWorld(), MiscUtils.convertChatColorToColor(team.getColor())); ObjectiveCompleteEvent compEvent = new ObjectiveCompleteEvent(this, event.getPlayer()); Bukkit.getServer().getPluginManager().callEvent(compEvent); } else if (!this.completed) { ObjectiveTouchEvent touchEvent = new ObjectiveTouchEvent( this, event.getPlayer(), !oldState || showPercent, touchMessage); Bukkit.getServer().getPluginManager().callEvent(touchEvent); } } else { event.setCancelled(true); if (this.show) ChatUtils.sendWarningMessage( event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_OWN_OBJECTIVE)); } } } }