Solved HashMap: Getting key from value and value from key?

Discussion in 'Plugin Development' started by Ragnarok_, Apr 11, 2017.

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

    Ragnarok_

    Hello, I'm making a duels plugin, close to wrapping it up, but there's those little bugs that happen in the middle of it. Like, when a player leaves, while they are in a match. I have them in a HashMap, but I got to check who the logger was. So I check both of them, and if it was the key, then I get the player, set his health to 0, and send the other person(value) back to spawn, and the other way around. I know how I'm going to do all this, but I just don't know how to get the value from the key and get the key from the value. If you have another method on doing this or any help at all that'd be great! Thanks in advance!
     
  2. Offline

    Zombie_Striker

    @Ragnarok_
    Hashmap#entrySet() returns all the Entries in the map. Each entry contains a Key and the corresponding value. Loop through all the entries, and check if either the key or value is the player.
     
  3. Offline

    Ragnarok_

    Yeah, I tried that, but how do I check the key's value and check the value's key.

    OH, I GET IT NOW!
    Thanks man, I love you.
    What I did was I looped through, like you said, and I checked if it was the key, and if it was the key, then I got the value, basically I did what I was asking. Thanks man
     
    Last edited: Apr 11, 2017
Thread Status:
Not open for further replies.

Share This Page