How to get the value out of hashmap?

Discussion in 'Plugin Development' started by elementalgodz11, Mar 2, 2014.

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

    elementalgodz11

    Hello, so I am trying to get the value of a HashMap <String><String>

    The second string being the target and the first string being the actual player;

    So on quit I want to send a message to the players name in the second string and remove the player of the first string from the HashMap.

    I can get the first string value using if (Hashmap.containsKey(p.getName())), however I am confused on how to get the player in the second string;

    And how I'm connecting the two players together;
    Code:java
    1. if (grouped.containsKey(p.getName())) {
    2. grouped.remove(p.getName());
    3. }
    4. if (grouped.containsKey(t.getName())) {
    5. grouped.remove(t.getName());
    6. }
    7.  
    8. grouped.put(t.getName(), p.getName());
    9. grouped.put(p.getName(), t.getName());


    Sorry for the poor explanation.

    Any help will be very appreciated. Thanks
     
  2. Offline

    dailison

    You can use Entry<String,String>

    Ex:
    Code:java
    1. for(Entry<String,List<String>> entry : Servidor.Permissoes.entrySet()){
    2. if(j.Permissao.equalsIgnoreCase(entry.getKey())){
    3. for(String s : entry.getValue()){
    4. p.addAttachment(plugin, s , true);
    5. }
    6. }
    7. }
     
  3. Offline

    elementalgodz11

    dailison
    Thanks
    So how would I go from here?
    Code:java
    1. @EventHandler
    2. public void onQuit(PlayerQuitEvent e) {
    3.  
    4. Player p = e.getPlayer();
    5.  
    6. if (grouped.containsKey(p.getName())) {
    7.  
    8. for(Entry<String, String> entry : grouped.entrySet()){
    9.  
    10.  
    11.  
    12. }
    13.  
    14. }
    15.  
    16. }
     
  4. Offline

    dailison

    if(TheCondiction){
    If you need get Key use, entry.getKey()
    If you need get Value use, entry.getValue()
    }
     
Thread Status:
Not open for further replies.

Share This Page