How would I create a teams

Discussion in 'Spigot Plugin Development' started by Fluddershy, Apr 24, 2017.

  1. Hello, I want to create temporary teams, for like duels and stuff, but I have no idea how to do it. The only thing I did was create a HashMap<String, ArrayList<>> teammanager = new HashMap<String, ArrayList<>>();
    I thought I could store who the teams in the ArrayList, or something, but I was wrong. Can someone help me through this, I should probably create a team object, but I don't know how to use it. What I'm wanting to do, is let the user create a Team (Its not forever, no need to save in the config), and allow them to invite and kick. It's pretty hard and I'm dumbstruck on what to do. Thanks for helping in advance!
     
  2. Hm, but how would I allow each and every player to create a team. And disband it and create another one? I don't want to create 100 teams, and check if ones full then add to the next.
     
  3. You would need to create a team class.
    In your team class you would have types for
    members hashmap
    owner
    and any other data you wish the team to store
    You would also have getters and setters to alter the data.
     
  4. Then I guess you could have a map<integer, team> and just add teams to the map
    myMap.put(myMap.size+1, new team(data)); <-- freehand and untested, just an example of the top of my head

    You could also have other maps of say members mapped to the integer of their team and owners mapped to the integer of the team they own. This would allow for quicker lookup.
    something like int ownedTeam = owners.get(player.getUniqueId().toString());
     
    #5 Stuperfied, Apr 24, 2017
    Last edited: Apr 24, 2017
  5. Create a Team Class with it's getters and setters to keep Team-data:
    Code (Text):
    package /*<PACKAGE>*/;

    public class Team {
        private List<Player> players;
        /*private /vars/ <.........> <.....>;*/
        private BukkitTask timeoutUpdatePacketTask;
     
        public TeamManager (String name) {
            this.name = name;
        }
     
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public void addPlayer (Player player) {
            this.players.add(player);
        }
        public void removePlayer (Player player) {
            this.players.remove(player);
        }
    }
     
    and create some Class like TeamManager which will have it's HashMap with Key String (which is for Team name) and Value Team.