How to check value in HashMap with if()

Discussion in 'Plugin Development' started by Doubtstand, Aug 12, 2015.

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

    Doubtstand

    The case is that I save the rank of a player in a hashmap, so it will be player UUID with a value of player or user bound to it. My question was how I can check what rank they have with if(), because I need to only do something if a player is an admin( and I dont want to check for OP ).
     
  2. Get the value with hashmap.get(key)
     
  3. Offline

    CoolDude53

    For a HashMap<UUID, Rank (or whatever you are storing)> you would just do

    Code:
    // assuming Rank is an enum
    HashMap<UUID, Rank> rankMap = new HashMap();
    UUID uuid = player.getUniqueId();
    
    if (rankMap.containsKey(uuid) && rankMap.get(uuid).equals(Rank.ADMIN))
        // do stuff here
     
Thread Status:
Not open for further replies.

Share This Page