Hey, I want to know how to get a the number of player of role with an HashMap ! Code: public static HashMap<UUID, Role> playerRole = new HashMap<>(); //Role is an Enum And this is an exemple :/ Code: if(playerRole.contains(Role.CIVIL).size() < 1){ playerRole.put(p.getUniqueID, Role.CIVIL); } My enum class: Code: package fr.etn.utils; import java.util.Random; public enum Role { SHERIF,TUEUR,MEDECIN,CIVIL; public static Role selectRandomRole(){ Random rand = new Random(); Role[] roles = Role.values(); return roles[rand.nextInt(roles.length)]; } } Thanks, and sorry for my bad english i'm french :/
@timtower so if i do Code: if(playerRole.forEach((key,value) -> value == Role.CIVIL.size())){ playerRole.put(p.getUniqueID, Role.CIVIL); } Is that good ?
@timtower yes, because I want to understand but putting the player in the HashMap is the final step :/ @timtower The first step is checking how many player are in the ROLE.CIVIL and if it's < 1 put in the hashmap to Role.CIVIL EDIT by Moderator: merged posts, please use the edit button instead of double posting.