Get the hashmap highest value

Discussion in 'Plugin Development' started by tryfme, Jul 16, 2014.

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

    tryfme

    Hey!I am making a bukkit minigame plugin.So i am stucked here:

    When a player kills other player, must add a point to the Hashmap <String, Integer>.
    And when some player arrives 10 kills, the game ends.Please, help.
     
  2. Code:Java
    1.  
    2. int highestNumber = 0;
    3. String highestPlayer = null;
    4.  
    5. for (String player : hashMap.keySet()) {
    6. if(hashMap.get(player) > highestNumber)
    7. highestNumber = hashMap.get(player);
    8. highestPlayer = player;
    9. }
    10.  
     
  3. Offline

    tryfme

    Okay, but when the player kills other player must be added to the hashmap in this way?
    hashMap.put(killer.getName(), +1) ?

    Anyone? Please respond.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  4. Offline

    malandrix_bunny

    Get their current score and add one
    Score++
    Score = Score + 1
     
  5. Offline

    tryfme

    Code example?
     
  6. Offline

    AoH_Ruthless

    tryfme
    What have you tried? It seems you don't have an understanding of Java, so maybe try learning some of that first.

    FisheyLP Huge spoonfeed :(.
     
    Traks likes this.
  7. Offline

    Flamedek

    tryfme To add one to their HashMap value, get their current kills value, add 1 to it, then put that new value in the map.
    During that process you could add a check to see if the new value is 10 (or old value is 9) and if so, end the game.
     
  8. Offline

    tryfme

    How must be look like?
     
  9. tryfme As above, please learn Java first. Nobody should be willing to provide the code for you, that's entirely your job.
     
  10. Offline

    Flamedek

    tryfme However it's correct java and does what it should ;)
    This shouldn't be to hard to figure out if you know what you're doing
     
Thread Status:
Not open for further replies.

Share This Page