Ejemplo n.º 1
0
  @ArenaEventHandler
  public void matchComplete(MatchCompletedEvent event) {
    Match match = event.getMatch();
    Matchup matchup = matchups.remove(match);
    if (matchup == null) return;
    Duel d = ongoingDuels.remove(matchup);
    if (d == null) return;
    MatchResult mr = match.getResult();

    Double money = (Double) d.getDuelOptionValue(DuelOption.MONEY);
    if (money != null) {
      if (mr.hasVictor()) {
        Collection<ArenaTeam> winningTeams = mr.getVictors();
        int winningSize = 0;
        for (ArenaTeam winTeam : winningTeams) {
          winningSize += winTeam.size();
        }
        final double split = d.getTotalMoney() / winningSize;
        for (ArenaTeam winTeam : winningTeams) {
          for (ArenaPlayer ap : winTeam.getPlayers()) {
            MessageUtil.sendMessage(
                ap,
                "&4[Duel] &eYou have won &6"
                    + split
                    + " "
                    + Defaults.MONEY_STR
                    + "&e for your victory!");
            MoneyController.add(ap.getName(), split);
          }
        }
      } else {
        refundMoney(money, mr.getDrawers());
      }
    }
  }
Ejemplo n.º 2
0
  @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();
      }
    }
  }
Ejemplo n.º 3
0
  @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();
      }
    }
  }