Help with Teams (winning game)

Discussion in 'Plugin Development' started by LegitJava, Sep 28, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    LegitJava

    Hi there,

    I'm currently developing a mini-game plugin but I'm lost about how I would check to see if the specified team (red/blue) won the game. Can anyone help with this?
     
  2. Offline

    chasechocolate

    Please elaborate on what you mean by "winning". Red kills all the players on blue team? The red team reaches an objective before the blue team?
     
  3. Offline

    Gater12

  4. Offline

    LegitJava

    When all the players on either side of the team are "out" of the game, then the game would stop and the opposite team would win.
     
  5. Offline

    chasechocolate

    LegitJava List<String> for red and blue, when a player gets out, remove them from their teams' ArrayList. Then, check if blue.size() == 0, which means red won, and if red.size() == 0, then blue won.
     
    Gater12 likes this.
  6. Offline

    LegitJava

    How would I do this if I was using an enum for teams? I also am using a PlayerData class as well which gets their specified team, etc. but I don't know if that would make a difference or not.
     
  7. Offline

    chasechocolate

    LegitJava you could either do it with a HashMap<String, TeamEnum> or HashMap<TeamEnum, List<String>>. The latter would be done with what I posted above, the the former can be done with:
    Code:java
    1. int redSize = 0;
    2. int blueSize = 0;
    3.  
    4. for(String playerName : map.keySet()){
    5. TeamEnum team = map.get(playerName);
    6.  
    7. if(team == TeamEnum.RED){
    8. redSize += 1;
    9. } else if(team == TeamEnum.BLUE){
    10. blueSize += 1;
    11. }
    12. }
    13.  
    14. //Compare sizes
     
  8. Offline

    LegitJava


    Okay, is there anyway I can use my PlayerData class instead of a String in the HashMap and still have this work? I deal with player names in the PlayerData class. I posted the code below, along with another method referencing Teams. All of this code is found in my Arena.java class.

    PlayerData Class:
    Code:java
    1. class PlayerData {
    2.  
    3. private String playerName;
    4. private ItemStack[] contents, armorContents;
    5. private Location location;
    6. private Team team;
    7.  
    8. protected PlayerData(Player p, Team team) {
    9. this.playerName = p.getName();
    10. this.contents = p.getInventory().getContents();
    11. this.armorContents = p.getInventory().getArmorContents();
    12. this.location = p.getLocation();
    13. this.team = team;
    14. }
    15.  
    16. protected Team getTeam() {
    17. return team;
    18. }
    19.  
    20. protected Player getPlayer() {
    21. return Bukkit.getServer().getPlayer(playerName);
    22. }
    23.  
    24. protected void restorePlayer() {
    25. Player p = Bukkit.getServer().getPlayer(playerName);
    26.  
    27. p.getInventory().setContents(contents);
    28. p.getInventory().setArmorContents(armorContents);
    29. p.teleport(location);
    30. }
    31.  
    32. protected boolean isForPlayer(Player p) {
    33. return playerName.equalsIgnoreCase(p.getName());
    34. }
    35. }

    I also have a method using the Team enum.
    Code:java
    1. private Team getTeamWithLessPlayers() {
    2. int red = 0, blue = 0;
    3. for (PlayerData d : data) {
    4. if (d.getTeam() == Team.RED) red++;
    5. else blue++;
    6. }
    7. if (red > blue) return Team.BLUE;
    8. else return Team.RED;
    9. }


    I initialized my PlayerData as an ArrayList at the beginning of the class.
     
Thread Status:
Not open for further replies.

Share This Page