Help With Hashmaps

Discussion in 'Plugin Development' started by bjsnow, Nov 17, 2012.

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

    bjsnow

    I am trying to make "mapcount" go up by 1 each time this command is issued:

    Code:
          if (args[0].equalsIgnoreCase("Mapcount1")) {
              Player p = (Player) sender;
            
                       if(!mapcount.containsKey(p.getName())) {
            mapcount.put(p.getName(), 1); //Give the killer one kill
            
          
            
            } else {
            mapcount.put(p.getName(), mapcount.get(p.getName()) + 1); //Increment the kills of the killer by 1
            
      
            }
              
          }
     
    
    But It Just goes up by 1 once then stays at one ;/

    I Need Help...
     
  2. Offline

    ZeusAllMighty11

    Instead of +1 do ++
     
  3. Offline

    bjsnow

    Ok will now and see if it works

    EDIT:
    unexpected type
    required:
    variable
    found:
    value

    when I tried doing ++ instead of +1

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

    ZeusAllMighty11

    p.getName()++ ?
     
  5. Offline

    bjsnow

    Same error
     
  6. Offline

    ZeusAllMighty11

    sry i cant think right now its 3am
     
  7. Offline

    bjsnow

    Still Need Help ;/
     
  8. Offline

    break2471

    What is a hashmap......I honestly don't know and it seems to be a popular topic on the forums.
     
  9. Offline

    Sushi

    It's a basic Java collection. Look it up.
    Why are you trying to increment a String.
     
  10. Offline

    break2471

    Okay, thanks.
     
  11. Offline

    LaxWasHere

     
    break2471 likes this.
  12. Offline

    ZeusAllMighty11


    It's not meant how it's shown. I meant to get the value of the hashmap of the player, and increment that
     
  13. Offline

    bjsnow

    still cant work this out ;/
     
  14. Offline

    desht

    bjsnow your original code looks fine in itself, so I suspect the problem is elsewhere. I assume your mapcount hash is actually a field of the object, and not a local variable...?
     
  15. Offline

    bjsnow

    That
    Code:
    HashMap<String, Integer> mapcount = new HashMap<String, Integer>();
    
    is my mapcount hashmap
     
  16. Offline

    desht

    Right, but where are you defining it? As an object field, or a local variable in the method?
     
  17. Offline

    Cirno

    Doing this in basic, most likely non functioning code.

    mapcount.put(p.getName(), mapcount.get(p.getName())++)
     
  18. Offline

    desht

    No. You can't use pre/post-increment on method return values. This has already been discussed in this thread.
     
  19. Offline

    bergerkiller

    :'(

    Why oh why do people think one can increment a name? Anyhow,
    1. Get old value from hashmap
    2. Increment this value
    3. Put new value into hashmap
    Each of the above three steps can be googled if you don't know how to do those. It's basic Java.
     
  20. Offline

    fireblast709

    bjsnow post more of the code
     
  21. Offline

    bjsnow

    Solved My self
     
Thread Status:
Not open for further replies.

Share This Page