HashMaps and teams...

Discussion in 'Plugin Development' started by DuskFireHD, Feb 26, 2015.

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

    DuskFireHD

    Hey people of the bukkit community, I'm making a minigame plugin and I wanted to know how I would get the Object key size not the key size... Sorry if it don't really make sense :D
     
  2. @DuskFireHD in a java.util.Map (guessing you are using a HashMap correct?) there is always one key for one object. so the amount of the maped objects is the same as the amount of the keys. also a map has the method size(). so you could just call map.size(); instead of map.keySet().size();
     
  3. Offline

    DuskFireHD

    @Shmobi private HashMap<Player, TeamTypes> _team = new HashMap<Player, TeamTypes>();

    I want a method like this also TeamTypes is Enum's

    public int getSize(TeamTypes team){
    if(team == TeamTypes.PLAYER){
    return //I want to get how much is on that team..
    }else if(team == TeamTypes.SPECTATOR){
    return //Same here..
    }
    }
     
  4. @DuskFireHD wait what? :O HashMap<Player, TeamTypes> would mean, that every player can only be once in the hashmap. and every player has one TeamType. i think what you are searching for is:
    HashMap<TeamType, Set<UUID>> teams;
    this would mean, that every teamtype has a set of uuid (players). so if you would do this:
    Set<UUID> allSpectatingPlayers = teams.get(TeamType.SPECTATOR);
    you would get a set of all players who are spectating. (use uuid instead of player. every player has a uuid which only exists one time. it is a primary key. use player.getUUID() )
    if you use:
    allSpectatingPlayers.size();
    you know how many players are in the spectator team.

    ps: remove the s of TeamTypes. enum-names should be singular
     
Thread Status:
Not open for further replies.

Share This Page