public boolean addBreak(Location location, Client breaker) { if (!isLocation(location)) return false; MonumentBlock block = getBlock(location); block.setBreaker(breaker); if (isDestroyed()) { String teamandname = getTeam().getColor() + getTeam().getDisplayName() + "'s " + ChatColor.AQUA + getName(); String destroyedby = ChatColor.GRAY + " destroyed by "; List<MonumentCalculation> calculations = new ArrayList<MonumentCalculation>(); List<Client> clients = new ArrayList<Client>(); for (MonumentBlock check : getBlocks()) if (check.isBroken() && !clients.contains(check.getBreaker())) clients.add(check.getBreaker()); for (Client client : clients) calculations.add(MonumentCalculation.getCalculation(client, this)); Collections.sort( calculations, new Comparator<MonumentCalculation>() { @Override public int compare(MonumentCalculation c1, MonumentCalculation c2) { return new Double(c1.getPercentage()).compareTo(new Double(c2.getPercentage())); } }); String destroyed = ""; if (calculations.size() == 1) { destroyed += calculations.get(0).getClient().getTeam().getColor() + calculations.get(0).getClient().getPlayer().getName(); destroyed += ChatColor.GRAY + " (" + calculations.get(0).getPercentage() + "%)"; } else if (getMap().getAuthors().size() >= 2) { /* * index 0 should prefix "" * index 1 to (max index - 1) should prefix ", " * index max index should prefix " and " */ int index = 0; while (index < calculations.size()) { if (index > 0) { destroyed += ChatColor.GRAY; if (index == (calculations.size() - 1)) destroyed += " and "; else destroyed += ", "; } destroyed += calculations.get(index).getClient().getTeam().getColor() + calculations.get(index).getClient().getPlayer().getName(); destroyed += ChatColor.GRAY + " (" + calculations.get(index).getPercentage() + "%)"; index++; } } String message = teamandname + destroyedby + destroyed; Scrimmage.broadcast(message); } setComplete(isDestroyed()); return true; }
public boolean isDestroyed() { List<MonumentBlock> broken = new ArrayList<MonumentBlock>(); for (MonumentBlock block : blocks) if (block.isBroken()) broken.add(block); return blocks.size() == broken.size(); }