Solved Best way to check if won minigame?

Discussion in 'Spigot Plugin Development' started by jusjus112, Jul 11, 2016.

  1. Hello guys,

    Im currently working on a minigame, but there is something that i cant figure out.
    I need to check if there is 1 alive team. And let that team win blablabla.
    I have tried many ways, but im really stuck at this point.

    So i have 4 teams, and when a player dies, i need to check if that team has more then 1 player, and the other teams need to have NOT more then 0.

    So, maybe you guys can help me out
     
  2. MiniDigger

    Supporter

    well, the depends on how your data structure works.
    but you should be able to loop through all alive players and check if they are all in the same team. if thats the case, they win.
     
  3. Make a enum class whith death and alive. When a player join store his name and the enum class When he join just say alive when he died set that to Death. To detect if there is a winner loop trough the player and see of the alive value of the enum class is equal to 1. That is the winner.
     
  4. Im working just with the bukkit Teams api ;) So, i can try your idea a little bit ;)


    Hmm. Good thing, gone try it :D
     
  5. I do this.
    Code (Text):
    for (Player all : Bukkit.getServer().getOnlinePlayers()) {
                    if (!TeamManager.getManager().getTeamByName("spectator").hasPlayer(all)) {
                        if (TeamManager.getManager().getTeamPlayer(e.getEntity()).hasPlayer(all)) {
                            String winningTeam = TeamManager.getManager().getPlayerTeamName(e.getEntity());
                            Bukkit.broadcastMessage(winningTeam + " Has won the game");
                        }
                    }
                }
    We have 3 poeple on the server. 1 on the red team 2 on the blue.
    When a player dies, it broadcasts 2 times "Blue has won the game"
    And 1 time "Red has won the game"

    So, how do i do this xD, im really confused right now haha
     
  6. MiniDigger

    Supporter

    how does your team manager work?
    easiest way would be to iterate though all teams (that are not named spectator) and check how many players it has. if you find only one team that has more then 0 player that team has one.