Search in sources :

Example 1 with TeamsModule

use of au.com.mineauz.minigames.minigame.modules.TeamsModule in project Minigames by AddstarMC.

the class PlayerData method endMinigame.

public void endMinigame(Minigame minigame, List<MinigamePlayer> winners, List<MinigamePlayer> losers) {
    EndMinigameEvent event = new EndMinigameEvent(winners, losers, minigame);
    Bukkit.getServer().getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        winners = event.getWinners();
        losers = event.getLosers();
        //Call Mechanics End
        minigame.getMechanic().endMinigame(minigame, winners, losers);
        //Prepare split money
        double bets = 0;
        if (minigame.getMpBets() != null) {
            if (minigame.getMpBets().hasMoneyBets()) {
                List<MinigamePlayer> plys = new ArrayList<MinigamePlayer>();
                plys.addAll(event.getWinners());
                if (!plys.isEmpty()) {
                    bets = minigame.getMpBets().claimMoneyBets() / (double) plys.size();
                    BigDecimal roundBets = new BigDecimal(bets);
                    roundBets = roundBets.setScale(2, BigDecimal.ROUND_HALF_UP);
                    bets = roundBets.doubleValue();
                }
                minigame.setMpBets(null);
            }
        }
        //Broadcast Message
        if (plugin.getConfig().getBoolean("broadcastCompletion") && minigame.isEnabled()) {
            if (minigame.isTeamGame()) {
                if (winners.size() > 0 || ((TeamsModule) minigame.getModule("Teams")).getDefaultWinner() != null) {
                    Team team;
                    if (winners.size() > 0)
                        team = winners.get(0).getTeam();
                    else
                        team = ((TeamsModule) minigame.getModule("Teams")).getTeam(((TeamsModule) minigame.getModule("Teams")).getDefaultWinner());
                    String score = "";
                    List<Team> teams = TeamsModule.getMinigameModule(minigame).getTeams();
                    for (Team t : teams) {
                        score += t.getColor().getColor().toString() + t.getScore();
                        if (t != teams.get(teams.size() - 1)) {
                            score += ChatColor.WHITE + " : ";
                        }
                    }
                    String nscore = ", " + MinigameUtils.formStr("player.end.team.score", score);
                    if (team.getScore() > 0) {
                        MinigameUtils.broadcast(MinigameUtils.formStr("player.end.team.win", team.getChatColor() + team.getDisplayName() + ChatColor.WHITE, minigame.getName(true)) + nscore, minigame, ChatColor.GREEN);
                    } else {
                        MinigameUtils.broadcast(MinigameUtils.formStr("player.end.team.win", team.getChatColor() + team.getDisplayName() + ChatColor.WHITE, minigame.getName(true)), minigame, ChatColor.GREEN);
                    }
                } else {
                    MinigameUtils.broadcast(MinigameUtils.formStr("player.end.broadcastNobodyWon", minigame.getName(true)), minigame, ChatColor.RED);
                }
            } else {
                if (winners.size() == 1) {
                    String score = "";
                    if (winners.get(0).getScore() != 0)
                        score = MinigameUtils.formStr("player.end.broadcastScore", winners.get(0).getScore());
                    MinigameUtils.broadcast(MinigameUtils.formStr("player.end.broadcastMsg", winners.get(0).getDisplayName(minigame.usePlayerDisplayNames()), minigame.getName(true)) + ". " + score, minigame, ChatColor.GREEN);
                } else if (winners.size() > 1) {
                    String win = "";
                    Collections.sort(winners, new Comparator<MinigamePlayer>() {

                        @Override
                        public int compare(MinigamePlayer o1, MinigamePlayer o2) {
                            return Integer.valueOf(o1.getScore()).compareTo(o2.getScore());
                        }
                    });
                    for (MinigamePlayer pl : winners) {
                        if (winners.indexOf(pl) < 2) {
                            win += pl.getDisplayName(minigame.usePlayerDisplayNames());
                            if (winners.indexOf(pl) + 2 >= winners.size()) {
                                win += " and ";
                            } else {
                                win += ", ";
                            }
                        } else {
                            win += String.valueOf(winners.size() - 3) + " others";
                        }
                    }
                    MinigameUtils.broadcast(MinigameUtils.formStr("player.end.broadcastMsg", win, minigame.getName(true)) + ". ", minigame, ChatColor.GREEN);
                } else {
                    MinigameUtils.broadcast(MinigameUtils.formStr("player.end.broadcastNobodyWon", minigame.getName(true)), minigame, ChatColor.RED);
                }
            }
        }
        GameOverModule gom = GameOverModule.getMinigameModule(minigame);
        boolean usedTimer = false;
        gom.setWinners(winners);
        gom.setLosers(losers);
        if (gom.getTimer() > 0 && minigame.getType() == MinigameType.MULTIPLAYER) {
            gom.startEndGameTimer();
            usedTimer = true;
        }
        for (MinigamePlayer player : losers) {
            player.setEndTime(System.currentTimeMillis());
            if (!usedTimer)
                quitMinigame(player, true);
            PlayMGSound.playSound(player, MGSounds.getSound("lose"));
        }
        for (MinigamePlayer player : winners) {
            player.setEndTime(System.currentTimeMillis());
            StoredGameStats saveData = new StoredGameStats(minigame, player);
            saveData.addStat(MinigameStats.Attempts, 1);
            saveData.addStat(MinigameStats.Wins, 1);
            saveData.addStat(MinigameStats.Kills, player.getKills());
            saveData.addStat(MinigameStats.Deaths, player.getDeaths());
            saveData.addStat(MinigameStats.Score, player.getScore());
            saveData.addStat(MinigameStats.Reverts, player.getReverts());
            saveData.addStat(MinigameStats.CompletionTime, player.getEndTime() - player.getStartTime() + player.getStoredTime());
            for (DynamicMinigameStat stat : MinigameStats.getDynamicStats()) {
                if (stat.doesApply(minigame, player, true)) {
                    saveData.addStat(stat, stat.getValue(minigame, player, true));
                }
            }
            saveData.applySettings(minigame.getStatSettings(saveData));
            if (!usedTimer)
                quitMinigame(player, true);
            //Group money bets
            if (bets != 0) {
                plugin.getEconomy().depositPlayer(player.getPlayer().getPlayer(), bets);
                player.sendMessage(MinigameUtils.formStr("player.bet.winMoney", Minigames.plugin.getEconomy().format(bets)), null);
            }
            // Record player completion and give rewards
            if (minigame.isEnabled()) {
                plugin.queueStatSave(saveData, true);
            } else {
                MinigameUtils.debugMessage("Skipping SQL data save for " + saveData + "; minigame is disabled");
            }
            //Item Bets (for non groups)
            if (minigame.getMpBets() != null) {
                if (minigame.getMpBets().hasBets()) {
                    if (!player.isInMinigame())
                        player.getPlayer().getInventory().addItem(minigame.getMpBets().claimBets());
                    else {
                        for (ItemStack i : minigame.getMpBets().claimBets()) {
                            player.addTempRewardItem(i);
                        }
                    }
                    minigame.setMpBets(null);
                }
            }
            PlayMGSound.playSound(player, MGSounds.getSound("win"));
        }
        if (!usedTimer) {
            gom.clearLosers();
            gom.clearWinners();
        }
        mdata.clearClaimedScore(minigame);
        //Call Types End.
        mdata.minigameType(minigame.getType()).endMinigame(winners, losers, minigame);
        minigame.getScoreboardData().reload();
    }
}
Also used : StoredGameStats(au.com.mineauz.minigames.stats.StoredGameStats) ArrayList(java.util.ArrayList) DynamicMinigameStat(au.com.mineauz.minigames.stats.DynamicMinigameStat) TeamsModule(au.com.mineauz.minigames.minigame.modules.TeamsModule) BigDecimal(java.math.BigDecimal) Comparator(java.util.Comparator) EndMinigameEvent(au.com.mineauz.minigames.events.EndMinigameEvent) Team(au.com.mineauz.minigames.minigame.Team) GameOverModule(au.com.mineauz.minigames.minigame.modules.GameOverModule) ItemStack(org.bukkit.inventory.ItemStack)

Example 2 with TeamsModule

use of au.com.mineauz.minigames.minigame.modules.TeamsModule in project Minigames by AddstarMC.

the class ScoreCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args != null && args.length >= 2) {
        MinigamePlayer ply = null;
        TeamColor color = TeamColor.matchColor(args[1]);
        if (color == null) {
            List<Player> plys = plugin.getServer().matchPlayer(args[1]);
            if (!plys.isEmpty()) {
                ply = plugin.pdata.getMinigamePlayer(plys.get(0));
            } else {
                sender.sendMessage(ChatColor.RED + "No player or team found by the name " + args[1]);
                return true;
            }
        }
        if (args[0].equalsIgnoreCase("get") && args.length >= 2) {
            if (ply != null) {
                if (ply.isInMinigame()) {
                    sender.sendMessage(ChatColor.GRAY + ply.getName() + "'s Score: " + ChatColor.GREEN + ply.getScore());
                } else {
                    sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!");
                }
            } else if (color != null) {
                if (args.length >= 3) {
                    Minigame mg = null;
                    if (plugin.mdata.hasMinigame(args[2])) {
                        mg = plugin.mdata.getMinigame(args[2]);
                    } else {
                        sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[2]);
                        return true;
                    }
                    TeamsModule tmod = TeamsModule.getMinigameModule(mg);
                    if (mg.isTeamGame()) {
                        if (tmod.hasTeam(color)) {
                            Team t = tmod.getTeam(color);
                            sender.sendMessage(color.getColor() + t.getDisplayName() + ChatColor.GRAY + " score in " + mg.getName(false) + ": " + ChatColor.GREEN + t.getScore());
                        } else {
                            sender.sendMessage(ChatColor.RED + mg.getName(false) + " does not have a " + color.toString().toLowerCase() + " team.");
                        }
                    } else {
                        sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!");
                        return true;
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "This command requires a Minigame name as the last argument!");
                }
            }
            return true;
        } else if (args[0].equalsIgnoreCase("set") && args.length >= 3) {
            int score = 0;
            if (args[2].matches("-?[0-9]+")) {
                score = Integer.parseInt(args[2]);
            } else {
                sender.sendMessage(ChatColor.RED + args[2] + " is not a valid number!");
                return true;
            }
            if (ply != null) {
                if (ply.isInMinigame()) {
                    ply.setScore(score);
                    ply.getMinigame().setScore(ply, ply.getScore());
                    sender.sendMessage(ChatColor.GRAY + ply.getName() + "'s score has been set to " + score);
                    if (ply.getMinigame().getMaxScore() != 0 && score >= ply.getMinigame().getMaxScorePerPlayer()) {
                        plugin.pdata.endMinigame(ply);
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!");
                }
            } else if (color != null) {
                if (args.length >= 4) {
                    Minigame mg = null;
                    if (plugin.mdata.hasMinigame(args[3])) {
                        mg = plugin.mdata.getMinigame(args[3]);
                    } else {
                        sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[2]);
                        return true;
                    }
                    TeamsModule tmod = TeamsModule.getMinigameModule(mg);
                    if (mg.isTeamGame() && mg.hasPlayers()) {
                        Team t = null;
                        if (tmod.hasTeam(color)) {
                            t = tmod.getTeam(color);
                            t.setScore(score);
                            sender.sendMessage(t.getChatColor() + t.getDisplayName() + ChatColor.GRAY + " score has been set to " + score);
                        } else {
                            sender.sendMessage(ChatColor.RED + mg.getName(false) + " does not have a " + color.toString().toLowerCase() + " team.");
                            return true;
                        }
                        if (mg.getMaxScore() != 0 && score >= mg.getMaxScorePerPlayer()) {
                            List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(t.getPlayers());
                            List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(mg.getPlayers().size() - t.getPlayers().size());
                            for (Team te : tmod.getTeams()) {
                                if (te != t) {
                                    l.addAll(te.getPlayers());
                                }
                            }
                            plugin.pdata.endMinigame(mg, w, l);
                        }
                    } else if (!mg.hasPlayers()) {
                        sender.sendMessage(ChatColor.RED + mg.getName(false) + " has no players playing!");
                    } else {
                        sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!");
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "This command requires a Minigame name as the last argument!");
                }
            }
            return true;
        } else if (args[0].equalsIgnoreCase("add") && args.length >= 3) {
            int score = 0;
            if (args[2].matches("-?[0-9]+")) {
                score = Integer.parseInt(args[2]);
            } else {
                score = 1;
            }
            if (ply != null) {
                if (ply.isInMinigame()) {
                    ply.addScore(score);
                    ply.getMinigame().setScore(ply, ply.getScore());
                    sender.sendMessage(ChatColor.GRAY + "Added " + score + " to " + ply.getName() + "'s score, new score: " + ply.getScore());
                    if (ply.getMinigame().getMaxScore() != 0 && ply.getScore() >= ply.getMinigame().getMaxScorePerPlayer()) {
                        plugin.pdata.endMinigame(ply);
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!");
                }
            } else if (color != null) {
                Minigame mg = null;
                String mgName = null;
                if (args.length == 4) {
                    mgName = args[3];
                } else {
                    mgName = args[2];
                }
                if (plugin.mdata.hasMinigame(mgName)) {
                    mg = plugin.mdata.getMinigame(mgName);
                } else {
                    sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + mgName);
                    return true;
                }
                TeamsModule tmod = TeamsModule.getMinigameModule(mg);
                if (mg.isTeamGame() && mg.hasPlayers()) {
                    Team team = null;
                    if (tmod.hasTeam(color)) {
                        team = tmod.getTeam(color);
                        team.addScore(score);
                        sender.sendMessage(ChatColor.GRAY + "Added " + score + " to " + team.getChatColor() + team.getDisplayName() + ChatColor.GRAY + " score, new score: " + team.getScore());
                    } else {
                        sender.sendMessage(ChatColor.RED + mg.getName(false) + " does not have a " + color.toString().toLowerCase() + " team.");
                        return true;
                    }
                    if (mg.getMaxScore() != 0 && team.getScore() >= mg.getMaxScorePerPlayer()) {
                        List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(team.getPlayers());
                        List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(mg.getPlayers().size() - team.getPlayers().size());
                        for (Team te : tmod.getTeams()) {
                            if (te != team) {
                                l.addAll(te.getPlayers());
                            }
                        }
                        plugin.pdata.endMinigame(mg, w, l);
                    }
                } else if (!mg.hasPlayers()) {
                    sender.sendMessage(ChatColor.RED + mg.getName(false) + " has no players playing!");
                } else {
                    sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!");
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) ArrayList(java.util.ArrayList) TeamColor(au.com.mineauz.minigames.minigame.TeamColor) TeamsModule(au.com.mineauz.minigames.minigame.modules.TeamsModule) Team(au.com.mineauz.minigames.minigame.Team) List(java.util.List) ArrayList(java.util.ArrayList) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 3 with TeamsModule

use of au.com.mineauz.minigames.minigame.modules.TeamsModule in project Minigames by AddstarMC.

the class SetTeamCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args != null) {
        TeamsModule tmod = TeamsModule.getMinigameModule(minigame);
        if (args[0].equalsIgnoreCase("add")) {
            if (args.length >= 2) {
                TeamColor col = TeamColor.matchColor(args[1]);
                String name = null;
                if (col != null) {
                    if (args.length > 2) {
                        name = "";
                        for (int i = 2; i < args.length; i++) {
                            name += args[i];
                            if (i != args.length - 1)
                                name += " ";
                        }
                    }
                    if (name != null) {
                        tmod.addTeam(col, name);
                        sender.sendMessage(ChatColor.GRAY + "Added " + MinigameUtils.capitalize(col.toString()) + " team to " + minigame.getName(false) + " with the display name " + name);
                    } else {
                        tmod.addTeam(col);
                        sender.sendMessage(ChatColor.GRAY + "Added " + MinigameUtils.capitalize(col.toString()) + " team to " + minigame.getName(false));
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "Invalid team color! Valid options:");
                    List<String> cols = new ArrayList<String>(TeamColor.values().length);
                    for (TeamColor c : TeamColor.values()) {
                        cols.add(c.toString());
                    }
                    sender.sendMessage(MinigameUtils.listToString(cols));
                }
            } else {
                sender.sendMessage(ChatColor.RED + "Valid team color options:");
                List<String> cols = new ArrayList<String>(TeamColor.values().length);
                for (TeamColor c : TeamColor.values()) {
                    cols.add(c.toString());
                }
                sender.sendMessage(MinigameUtils.listToString(cols));
            }
            return true;
        } else if (args[0].equalsIgnoreCase("list")) {
            List<String> teams = new ArrayList<String>(tmod.getTeams().size());
            for (Team t : tmod.getTeams()) {
                teams.add(t.getChatColor() + t.getColor().toString() + ChatColor.GRAY + "(" + t.getChatColor() + t.getDisplayName() + ChatColor.GRAY + ")");
            }
            String teamsString = "";
            for (String t : teams) {
                teamsString += t;
                if (!t.equals(teams.get(teams.size() - 1)))
                    teamsString += ", ";
            }
            sender.sendMessage(ChatColor.GRAY + "List of teams in " + minigame.getName(false) + ":");
            sender.sendMessage(teamsString);
            return true;
        } else if (args[0].equalsIgnoreCase("remove")) {
            if (args.length >= 2) {
                TeamColor col = TeamColor.matchColor(args[1]);
                if (col != null) {
                    if (tmod.hasTeam(col)) {
                        tmod.removeTeam(col);
                        sender.sendMessage(ChatColor.GRAY + "Removed " + MinigameUtils.capitalize(col.toString()) + " from " + minigame.getName(false));
                    } else {
                        sender.sendMessage(ChatColor.RED + minigame.getName(false) + " does not have the team " + MinigameUtils.capitalize(col.toString()));
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "Invalid team color! Valid options:");
                    List<String> cols = new ArrayList<String>(TeamColor.values().length);
                    for (Team c : tmod.getTeams()) {
                        cols.add(c.getColor().toString());
                    }
                    sender.sendMessage(MinigameUtils.listToString(cols));
                }
            } else {
                sender.sendMessage(ChatColor.RED + "Valid teams:");
                List<String> cols = new ArrayList<String>(TeamColor.values().length);
                for (Team c : tmod.getTeams()) {
                    cols.add(c.getColor().toString());
                }
                sender.sendMessage(MinigameUtils.listToString(cols));
            }
            return true;
        } else if (args[0].equalsIgnoreCase("rename")) {
            if (args.length > 2) {
                TeamColor col = TeamColor.matchColor(args[1]);
                String name = "";
                for (int i = 2; i < args.length; i++) {
                    name += args[i];
                    if (i != args.length - 1)
                        name += " ";
                }
                if (col != null) {
                    if (tmod.hasTeam(col)) {
                        tmod.getTeam(col).setDisplayName(name);
                        sender.sendMessage(ChatColor.GRAY + "Set " + MinigameUtils.capitalize(col.toString()) + " display name to " + name + " for " + minigame.getName(false));
                    } else {
                        sender.sendMessage(ChatColor.RED + minigame.getName(false) + " does not have the team " + MinigameUtils.capitalize(col.toString()));
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "Invalid team color! Valid options:");
                    List<String> cols = new ArrayList<String>(TeamColor.values().length);
                    for (Team c : tmod.getTeams()) {
                        cols.add(c.getColor().toString());
                    }
                    sender.sendMessage(MinigameUtils.listToString(cols));
                }
            } else {
                sender.sendMessage(ChatColor.RED + "Valid teams:");
                List<String> cols = new ArrayList<String>(TeamColor.values().length);
                for (Team c : tmod.getTeams()) {
                    cols.add(c.getColor().toString());
                }
                sender.sendMessage(MinigameUtils.listToString(cols));
            }
            return true;
        } else if (args[0].equalsIgnoreCase("maxplayers") && args.length == 3) {
            if (TeamColor.matchColor(args[1]) != null) {
                TeamColor col = TeamColor.matchColor(args[1]);
                if (tmod.hasTeam(col)) {
                    if (args[2].matches("[0-9]+")) {
                        int val = Integer.valueOf(args[2]);
                        tmod.getTeam(col).setMaxPlayers(Integer.valueOf(args[2]));
                        sender.sendMessage(ChatColor.GRAY + "Maximum players for the team " + tmod.getTeam(col).getDisplayName() + " has been set to " + val);
                    } else {
                        sender.sendMessage(ChatColor.RED + args[2] + " is not a valid number!");
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "There is no " + MinigameUtils.capitalize(col.toString()) + " Team in " + minigame);
                }
            } else {
                sender.sendMessage(ChatColor.RED + args[1] + " is not a valid team color!");
            }
            return true;
        }
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) TeamColor(au.com.mineauz.minigames.minigame.TeamColor) List(java.util.List) ArrayList(java.util.ArrayList) Team(au.com.mineauz.minigames.minigame.Team) TeamsModule(au.com.mineauz.minigames.minigame.modules.TeamsModule)

Example 4 with TeamsModule

use of au.com.mineauz.minigames.minigame.modules.TeamsModule in project Minigames by AddstarMC.

the class MultiplayerType method timerExpire.

@EventHandler
public void timerExpire(TimerExpireEvent event) {
    if (event.getMinigame().getType() == MinigameType.MULTIPLAYER && event.getMinigameState() == MinigameState.STARTED) {
        if (event.getMinigame().isTeamGame()) {
            Minigame mgm = event.getMinigame();
            if (TeamsModule.getMinigameModule(mgm).getDefaultWinner() != null) {
                TeamsModule tm = TeamsModule.getMinigameModule(mgm);
                List<MinigamePlayer> w;
                List<MinigamePlayer> l;
                if (TeamsModule.getMinigameModule(mgm).hasTeam(TeamsModule.getMinigameModule(mgm).getDefaultWinner())) {
                    w = new ArrayList<MinigamePlayer>(tm.getTeam(tm.getDefaultWinner()).getPlayers().size());
                    l = new ArrayList<MinigamePlayer>(mgm.getPlayers().size() - tm.getTeam(tm.getDefaultWinner()).getPlayers().size());
                    w.addAll(tm.getTeam(tm.getDefaultWinner()).getPlayers());
                } else {
                    w = new ArrayList<MinigamePlayer>();
                    l = new ArrayList<MinigamePlayer>(mgm.getPlayers().size());
                }
                for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                    if (t.getColor() != TeamsModule.getMinigameModule(mgm).getDefaultWinner())
                        l.addAll(t.getPlayers());
                }
                plugin.pdata.endMinigame(mgm, w, l);
            } else {
                List<Team> drawTeams = new ArrayList<Team>();
                Team winner = null;
                for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                    if (winner == null || (t.getScore() > winner.getScore() && (drawTeams.isEmpty() || t.getScore() > drawTeams.get(0).getScore()))) {
                        winner = t;
                    } else if (winner != null && t.getScore() == winner.getScore()) {
                        if (!drawTeams.isEmpty()) {
                            drawTeams.clear();
                        }
                        drawTeams.add(winner);
                        drawTeams.add(t);
                        winner = null;
                    } else if (!drawTeams.isEmpty() && drawTeams.get(0).getScore() == t.getScore()) {
                        drawTeams.add(t);
                    }
                }
                if (winner != null) {
                    List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(winner.getPlayers());
                    List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(mgm.getPlayers().size() - winner.getPlayers().size());
                    for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                        if (t != winner)
                            l.addAll(t.getPlayers());
                    }
                    pdata.endMinigame(mgm, w, l);
                } else {
                    List<MinigamePlayer> players = new ArrayList<MinigamePlayer>(mgm.getPlayers());
                    for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                        t.resetScore();
                    }
                    if (mgm.getMinigameTimer() != null) {
                        mgm.getMinigameTimer().stopTimer();
                        mgm.setMinigameTimer(null);
                    }
                    if (mgm.getMpTimer() != null) {
                        mgm.getMpTimer().setStartWaitTime(0);
                        mgm.getMpTimer().pauseTimer();
                        mgm.getMpTimer().removeTimer();
                        mgm.setMpTimer(null);
                    }
                    if (mgm.getFloorDegenerator() != null && mgm.getPlayers().size() == 0) {
                        mgm.getFloorDegenerator().stopDegenerator();
                    }
                    if (mgm.getMpBets() != null && mgm.getPlayers().size() == 0) {
                        mgm.setMpBets(null);
                    }
                    for (MinigamePlayer ply : players) {
                        pdata.quitMinigame(ply, true);
                        if (!plugin.getConfig().getBoolean("multiplayer.broadcastwin")) {
                            if (drawTeams.size() == 2) {
                                ply.sendMessage(MinigameUtils.formStr("player.end.team.tie", drawTeams.get(0).getChatColor() + drawTeams.get(0).getDisplayName() + ChatColor.WHITE, drawTeams.get(1).getChatColor() + drawTeams.get(1).getDisplayName() + ChatColor.WHITE, event.getMinigame().getName(true)), "error");
                            } else {
                                ply.sendMessage(MinigameUtils.formStr("player.end.team.tieCount", drawTeams.size(), event.getMinigame().getName(true)), "error");
                            }
                            String scores = "";
                            int c = 1;
                            for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                                scores += t.getChatColor().toString() + t.getScore();
                                if (c != TeamsModule.getMinigameModule(mgm).getTeams().size())
                                    scores += ChatColor.WHITE + " : ";
                                c++;
                            }
                            ply.sendMessage(MinigameUtils.getLang("minigame.info.score") + " " + scores);
                        }
                    }
                    if (plugin.getConfig().getBoolean("multiplayer.broadcastwin")) {
                        if (drawTeams.size() == 2) {
                            plugin.getServer().broadcastMessage(ChatColor.RED + "[Minigames] " + MinigameUtils.formStr("player.end.team.tie", drawTeams.get(0).getChatColor() + drawTeams.get(0).getDisplayName() + ChatColor.WHITE, drawTeams.get(1).getChatColor() + drawTeams.get(1).getDisplayName() + ChatColor.WHITE, event.getMinigame().getName(true)));
                        } else {
                            plugin.getServer().broadcastMessage(ChatColor.RED + "[Minigames] " + MinigameUtils.formStr("player.end.team.tieCount", drawTeams.size(), event.getMinigame().getName(true)));
                        }
                        String scores = "";
                        int c = 1;
                        for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                            scores += t.getChatColor().toString() + t.getScore();
                            if (c != TeamsModule.getMinigameModule(mgm).getTeams().size())
                                scores += ChatColor.WHITE + " : ";
                            c++;
                        }
                        plugin.getServer().broadcastMessage(MinigameUtils.getLang("minigame.info.score") + " " + scores);
                    }
                }
            }
        } else {
            MinigamePlayer player = null;
            int score = 0;
            for (MinigamePlayer ply : event.getMinigame().getPlayers()) {
                if (ply.getScore() > 0) {
                    if (ply.getScore() > score) {
                        player = ply;
                        score = ply.getScore();
                    } else if (ply.getScore() == score) {
                        if (player != null && ply.getDeaths() < player.getDeaths()) {
                            player = ply;
                        } else if (player == null) {
                            player = ply;
                        }
                    }
                }
            }
            List<MinigamePlayer> losers = new ArrayList<MinigamePlayer>();
            losers.addAll(event.getMinigame().getPlayers());
            List<MinigamePlayer> winners = new ArrayList<MinigamePlayer>();
            if (player != null) {
                losers.remove(player);
                winners.add(player);
            }
            pdata.endMinigame(event.getMinigame(), winners, losers);
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) ArrayList(java.util.ArrayList) Team(au.com.mineauz.minigames.minigame.Team) Minigame(au.com.mineauz.minigames.minigame.Minigame) TeamsModule(au.com.mineauz.minigames.minigame.modules.TeamsModule) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Team (au.com.mineauz.minigames.minigame.Team)4 TeamsModule (au.com.mineauz.minigames.minigame.modules.TeamsModule)4 ArrayList (java.util.ArrayList)4 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)2 Minigame (au.com.mineauz.minigames.minigame.Minigame)2 TeamColor (au.com.mineauz.minigames.minigame.TeamColor)2 List (java.util.List)2 EndMinigameEvent (au.com.mineauz.minigames.events.EndMinigameEvent)1 GameOverModule (au.com.mineauz.minigames.minigame.modules.GameOverModule)1 DynamicMinigameStat (au.com.mineauz.minigames.stats.DynamicMinigameStat)1 StoredGameStats (au.com.mineauz.minigames.stats.StoredGameStats)1 BigDecimal (java.math.BigDecimal)1 Comparator (java.util.Comparator)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 ItemStack (org.bukkit.inventory.ItemStack)1