public Duel accept(ArenaPlayer player) { Duel d = getChallengedDuel(player); if (d != null) { d.accept(player); if (d.isReady()) { /// Do a final check to see if they have completed all the duel options if (!checkWager(d)) return null; ArenaTeam t = d.getChallengerTeam(); ArenaTeam t2 = d.makeChallengedTeam(); List<ArenaTeam> teams = new ArrayList<ArenaTeam>(); teams.add(t); teams.add(t2); JoinOptions jo = new JoinOptions(); jo.setMatchParams(d.getMatchParams()); jo.setJoinLocation(player.getLocation()); if (d.getOptions().hasOption(DuelOption.ARENA)) { jo.setArena((Arena) d.getOptions().getOptionValue(DuelOption.ARENA)); } Matchup m = new Matchup(d.getMatchParams(), teams, jo); m.addArenaListener(this); formingDuels.remove(d); ongoingDuels.put(m, d); MatchTeamQObject mo = new MatchTeamQObject(m); BattleArena.getBAController().addMatchup(mo); } } return d; }
private void makePreliminaryRound() { Matchup m; round++; Round tr = new Round(round); rounds.add(tr); int nrounds = getNRounds(teams.size()) + 1; int minTeams = eventParams.getMinTeams(); final int needed_size = (int) Math.pow(minTeams, nrounds - 1); final int nprelims = (aliveTeams.size() - needed_size) / (minTeams - 1); int loffset = needed_size - 1; int hoffset = needed_size; for (int i = 0; i < nprelims; i++) { List<Team> newTeams = new ArrayList<Team>(); for (int j = 0; j < minTeams / 2; j++) { newTeams.add(aliveTeams.get(loffset)); newTeams.add(aliveTeams.get(hoffset)); loffset--; hoffset++; } m = new Matchup(eventParams, newTeams); m.addArenaListener(this); tr.addMatchup(m); } }
@MatchEventHandler public void matchCompleted(MatchCompletedEvent event) { Match am = event.getMatch(); MatchResult r = am.getResult(); Matchup m = null; if (r.getVictors() != null && !r.getVictors().isEmpty()) { m = getMatchup(r.getVictors().iterator().next(), round); } else if (r.getLosers() != null && !r.getLosers().isEmpty()) { m = getMatchup(r.getLosers().iterator().next(), round); } else if (r.getDrawers() != null && !r.getDrawers().isEmpty()) { m = getMatchup(r.getDrawers().iterator().next(), round); } if (m == null) { // / This match wasnt in our tournament return; } if (am.getState() == MatchState.ONCANCEL) { endEvent(); return; } Team victor = null; if (r.isDraw()) { // / match was a draw, pick a random lucky winner victor = pickRandomWinner(r, r.getDrawers()); } else if (r.hasVictor() && r.getVictors().size() != 1) { victor = pickRandomWinner(r, r.getVictors()); } else if (r.hasVictor()) { victor = r.getVictors().iterator().next(); // / single winner } m.setResult(r); for (Team t : r.getLosers()) { super.removeTeam(t); } aliveTeams.removeAll(r.getLosers()); if (roundFinished()) { TimeUtil.testClock(); if (Defaults.DEBUG) System.out.println("ROUND FINISHED !!!!! " + aliveTeams); if (round + 1 == nrounds || isFinished()) { Server server = Bukkit.getServer(); Team t = aliveTeams.get(0); server.broadcastMessage( Log.colorChat( eventParams.getPrefix() + "&e Congratulations to &6" + t.getDisplayName() + "&e for winning!")); HashSet<Team> losers = new HashSet<Team>(competingTeams); losers.remove(victor); Set<Team> victors = new HashSet<Team>(Arrays.asList(victor)); eventVictory(victors, losers); PerformTransition.transition(am, MatchState.FIRSTPLACE, t, false); PerformTransition.transition(am, MatchState.PARTICIPANTS, losers, false); eventCompleted(); } else { makeNextRound(); startRound(); } } }
private void announceRound() { Round tr = rounds.get(round); String strround = preliminary_round && round == 0 ? "PreliminaryRound" : ("Round " + (round + 1)); if (round + 1 == nrounds) { strround = "Final Round"; } if (preliminary_round) { preliminary_round = false; int nprelims = tr.getMatchups().size() * eventParams.getMinTeams(); for (int i = 0; i < aliveTeams.size() - nprelims; i++) { Team t = aliveTeams.get(i); t.sendMessage("&4[" + strround + "]&e You have a &5bye&e this round"); } } BTInterface bti = new BTInterface(eventParams); final String prefix = eventParams.getPrefix(); if (tr.getMatchups().size() <= 8) { for (Matchup m : tr.getMatchups()) { List<String> names = new ArrayList<String>(); for (Team t : m.getTeams()) { names.add("&8" + t.getDisplayName() + "&6[" + bti.getElo(t) + "]"); } String msg = "&e" + strround + ": " + StringUtils.join(names, " vs "); if (ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH > msg.length() + prefix.length()) { broadcastAlive(prefix + " " + msg); } else { broadcastAlive(msg); } } } else { broadcastAlive( prefix + "&e Round " + strround + " has " + tr.getMatchups().size() + " " + MessageUtil.teamsOrPlayers(eventParams.getMinTeamSize()) + " competing. &6/tourney status:&e for updates"); } if (round != nrounds) broadcast( prefix + "&e " + strround + " will start in &4" + timeBetweenRounds + " &eseconds!"); else broadcast( prefix + "&e The " + strround + " will start in &4" + timeBetweenRounds + " &eseconds!"); }
private void announceRound() { Round tr = rounds.get(round); String strround = "Round " + (round + 1); if (round + 1 == nrounds) { strround = "Final Round"; } if (preliminary_round) { preliminary_round = false; int nprelims = tr.getMatchups().size() * 2; for (int i = 0; i < aliveTeams.size() - nprelims; i++) { Team t = aliveTeams.get(i); t.sendMessage("&4[" + strround + "]&e You have a &5bye&e this round"); } } BTInterface bti = new BTInterface(eventParams); final String prefix = eventParams.getPrefix(); for (Matchup m : tr.getMatchups()) { if (m.getTeams().size() == 2) { Team t1 = m.getTeam(0); Team t2 = m.getTeam(1); Double elo1 = (double) bti.getElo(t1); Double elo2 = (double) bti.getElo(t2); // System.out.println("team1 stat= " + bti.loadRecord(t1.getPlayers())); broadcast( prefix + "&e " + strround + ": &8" + t1.getDisplayName() + "&6[" + elo1 + "]" + "&e vs &8" + t2.getDisplayName() + "&6[" + elo2 + "]"); } } if (round != nrounds) broadcast( prefix + "&e " + strround + " will start in &4" + timeBetweenRounds + " &eseconds!"); else broadcast( prefix + "&e The " + strround + " will start in &4" + timeBetweenRounds + " &eseconds!"); }
private void makeNextRound() { Matchup m; round++; Round tr = new Round(round); rounds.add(tr); int minTeams = eventParams.getMinTeams(); int size = aliveTeams.size(); final int nMatches = size / minTeams; for (int i = 0; i < nMatches; i++) { List<Team> newTeams = new ArrayList<Team>(); for (int j = 0; j < minTeams / 2; j++) { int index = i + j * nMatches; newTeams.add(aliveTeams.get(index)); newTeams.add(aliveTeams.get(size - 1 - index)); } m = new Matchup(eventParams, newTeams); m.addArenaListener(this); tr.addMatchup(m); } }
@EventHandler public void matchCompleted(MatchCompletedEvent event) { if (!isRunning()) return; Match am = event.getMatch(); Team victor = am.getVictor(); Matchup m; if (victor == null) m = getMatchup(am.getResult().getLosers().iterator().next(), round); else m = getMatchup(victor, round); // System.out.println("victor ===" + victor + " am= " +am + " losers=" + am.getLosers() +" m // = " + m +" am.result="+am.getResult()); if (m == null) { // / This match wasnt in our tournament return; } if (am.getState() == MatchState.ONCANCEL) { endEvent(); return; } MatchResult r = am.getResult(); if (victor == null) { // / match was a draw, pick a random lucky winner List<Team> ls = new ArrayList<Team>(am.getResult().getLosers()); if (ls.isEmpty()) { Log.err("[BattleArena] Tournament found a match with no players, cancelling tournament"); this.cancelEvent(); return; } victor = ls.get(rand.nextInt(ls.size())); victor.sendMessage("&2You drew your match but have been randomly selected as the winner!"); r.setVictor(victor); Set<Team> losers = new HashSet<Team>(ls); losers.remove(victor); r.setLosers(losers); for (Team l : losers) { l.sendMessage( "&cYou drew your match but someone else has been randomly selected as the winner!"); } } m.setResult(r); for (Team t : r.getLosers()) { super.removeTeam(t); } aliveTeams.removeAll(r.getLosers()); if (roundFinished()) { TimeUtil.testClock(); if (Defaults.DEBUG) System.out.println("ROUND FINISHED !!!!! " + aliveTeams); if (round + 1 == nrounds || isFinished()) { Server server = Bukkit.getServer(); Team t = aliveTeams.get(0); server.broadcastMessage( Log.colorChat( eventParams.getPrefix() + "&e Congratulations to &6" + t.getDisplayName() + "&e for winning!")); HashSet<Team> losers = new HashSet<Team>(competingTeams); losers.remove(victor); eventVictory(victor, losers); PerformTransition.transition(am, MatchState.FIRSTPLACE, t, false); PerformTransition.transition(am, MatchState.PARTICIPANTS, losers, false); eventCompleted(); } else { makeNextRound(); startRound(); } } }