How would I go about creating multiple teams for an arena?

Discussion in 'Plugin Development' started by ItsComits, Oct 18, 2017.

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

    ItsComits

    Hello, I just need some guidance on how I would approach this type of situation. What I am thinking is that one Team object per arena and have more than one team(red,blue,yellow etc) in that team object. Do you think this is the best approach?
     
  2. Online

    timtower Administrator Administrator Moderator

    @ItsComits List or Map of teams is probably the best way.
     
  3. Offline

    ItsComits

    @timtower Thanks for your response. I am having a problem adding a player to team. I have this so far:
    Code:
        private static ArrayList<Integer> teams = new ArrayList<Integer>();
        private static HashMap<UUID, Integer> playerTeams = new HashMap<UUID, Integer>();
        public void addPlayer(Player p) {
            if (hasTeam(p)) {
                p.sendMessage("You are already in a team. (" + getTeam(p) + ")");
                return;
            }
            //Here I am wanting to get all the teams(.forEach) and getting all the UUIDs. in the hashmap that have the team(integer)
            
     
    Last edited: Oct 18, 2017
  4. Offline

    MightyOne

    Make an ArrayList with all your team maps. Then you can iterate through the teams and in every team through the players
     
  5. Offline

    mine2012craft

    @ItsComits Hmm... There are multiple ways to about this, but what I would recommend doing is create a Team object. This team object would allow the coder to add and remove players from the team (Saving by UUIDs is a good idea). You can also use the team object to get the amount of players, get a certain player, etc This also makes it easier to add.later features, such as team leaders, spawn points, names, team color(s?), allied teams, enemy teams, and so on.
    If you have already created your arena object, you could store teams in a list inside the arena object. Make sure to create getters and editors for the teams as well.

    Doing this will also allow you to check if the player is in a team, check for team names, get certain teams by colors, integers, names, etc.

    Then again, this suggestion is focusing on customizability and possibly efficiency. It's what I would do at least.
     
  6. Offline

    ItsComits

    @mine2012craft @MightyOne @timtower I have come to a slight problem with a hashmap. What I want to do is get a number of values in the hashmap that are the same and get the size. I have got this so far. But I am unsure if this will work and is there a better way of doing this?
    Code:
            teams.forEach(team -> {
    
                // Checking if there is 0 players in the team
                if (playerTeams.get(team) == null) {
                    playerTeams.put(p.getUniqueId(), team);
                    return;
                    // There is players in the team
                    // Check if the amount of player in the team is the correct
                    // amount of players
                } else if (playerTeams.get(teams).SIZE < a.getMaxPlayers() / a.getTotalTeams()) {
                    playerTeams.put(p.getUniqueId(), team);
                    return;
                }
            });
     
Thread Status:
Not open for further replies.

Share This Page