I create the teams but Bukkit says theres only 1!

Discussion in 'Plugin Development' started by Rushmead, Apr 12, 2014.

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

    Rushmead

    Haiii
    So i have my TeamManager Class That creates 6 teams From my Custom Team Class
    Code:java
    1. package endless.uhc;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5. import java.util.Set;
    6. import java.util.UUID;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.Location;
    11. import org.bukkit.OfflinePlayer;
    12. import org.bukkit.entity.Player;
    13. public class Team {
    14.  
    15. private List<UUID> players = new ArrayList<UUID>();
    16. private ChatColor chatColor = null;
    17. private org.bukkit.scoreboard.Team team;
    18. public Team(UHC plugin, ChatColor chatColor, org.bukkit.scoreboard.Team t) {
    19.  
    20. this.chatColor = chatColor;
    21. team = t;
    22.  
    23. }
    24.  
    25. public void teleport(double x, double y, double z) {
    26. for(UUID uuid: players) {
    27. Player player = Bukkit.getPlayer(uuid);
    28. player.teleport(new Location(player.getWorld(), x, y, z));
    29. }
    30. }
    31.  
    32. public Player getPlayer(int id) {
    33. return Bukkit.getPlayer(players.get(id));
    34. }
    35.  
    36. public boolean addPlayer(Player player) {
    37. if(isFull()) {
    38. return false;
    39. } else {
    40. if(player.getUniqueId() == null){
    41. System.out.print("No UUID");
    42. return false;
    43. }else{
    44. System.out.print(player.getUniqueId());
    45. players.add(player.getUniqueId());
    46. team.addPlayer(player);
    47. player.sendMessage(getChatColor() + "Joined team");
    48. return true;
    49. }
    50. }
    51. }
    52.  
    53. public void removePlayer(Player player) {
    54. players.remove(player.getUniqueId());
    55. team.removePlayer(player);
    56. player.sendMessage(getChatColor() + "Left team");
    57. }
    58.  
    59. public boolean isFull() {
    60. return players.size() == 2;
    61. }
    62.  
    63. public boolean isPlayer(Player player) {
    64. return players.contains(player.getUniqueId());
    65. }
    66.  
    67. public void clear() {
    68. team.getPlayers().clear();
    69. players.clear();
    70.  
    71. players = new ArrayList<UUID>(); //Just to be safe
    72. chatColor = null;
    73. }
    74.  
    75. public ChatColor getChatColor() {
    76. return chatColor;
    77. }
    78. public Set<OfflinePlayer> getScoreboardTeamPlayers() {
    79. return team.getPlayers();
    80. }
    81. }

    This is my Method to Create a Team
    Code:java
    1. public static void createTeam(ChatColor c){
    2. org.bukkit.scoreboard.Team tm = UHC.sb.registerNewTeam(c.name());
    3. tm.setPrefix(c.toString());
    4. tm.setAllowFriendlyFire(false);
    5.  
    6. Team t = new Team(UHC.main, c, tm);
    7. possibleTeams.add(t);
    8.  
    9.  
    10. }

    This is My TeamManager Class
    Code:java
    1. package endless.uhc;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.HashMap;
    5. import java.util.List;
    6. import java.util.Random;
    7. import java.util.UUID;
    8.  
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.entity.Player;
    11.  
    12. public class TeamManager {
    13. private static List<Team> possibleTeams = new ArrayList<Team>();
    14. private static HashMap<UUID, Team> teams = new HashMap<UUID, Team>();
    15.  
    16. static {
    17. createTeam(ChatColor.RED);
    18. createTeam(ChatColor.BLUE);
    19. createTeam(ChatColor.YELLOW);
    20. createTeam(ChatColor.GREEN);
    21. createTeam(ChatColor.DARK_PURPLE);
    22. createTeam(ChatColor.AQUA);
    23.  
    24. }
    25.  
    26. public static void assignTeam(Player player) {
    27.  
    28. Team team = null;
    29. do {
    30. team = possibleTeams.get(new Random().nextInt(possibleTeams.size()));
    31. } while(team.isFull());
    32. team.addPlayer(player);
    33. teams.put(player.getUniqueId(), team);
    34. }
    35.  
    36. public static Team getTeam(Player player) {
    37. return teams.get(player.getUniqueId());
    38. }
    39. public static List<Team> getTeams() {
    40. List<Team> allTeams = new ArrayList<Team>();
    41. for(Team team: teams.values()) {
    42. allTeams.add(team);
    43. }
    44. return allTeams;
    45. }
    46. public static void createTeam(ChatColor c){
    47. org.bukkit.scoreboard.Team tm = UHC.sb.registerNewTeam(c.name());
    48. tm.setPrefix(c.toString());
    49. tm.setAllowFriendlyFire(false);
    50.  
    51. Team t = new Team(UHC.main, c, tm);
    52. possibleTeams.add(t);
    53.  
    54.  
    55. }
    56. }

    I create the team and give i to my custom Team class
    i run this 6 times. 1 for each colour. But only 1 team is apparently created....
     
  2. Offline

    Beasty

    Repeat the Events, Rush <3
     
  3. Offline

    Rushmead

    Wut?

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Offline

    ZodiacTheories

    Rushmead

    Please use the 'code' format when typing code please and please post your whole code.
     
  5. Offline

    Rushmead

    Updated
     
  6. Offline

    Beasty

    Bumpy :D
     
Thread Status:
Not open for further replies.

Share This Page