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...
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.
It's not meant how it's shown. I meant to get the value of the hashmap of the player, and increment that
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...?
That Code: HashMap<String, Integer> mapcount = new HashMap<String, Integer>(); is my mapcount hashmap
Doing this in basic, most likely non functioning code. mapcount.put(p.getName(), mapcount.get(p.getName())++)
No. You can't use pre/post-increment on method return values. This has already been discussed in this thread.
Why oh why do people think one can increment a name? Anyhow, Get old value from hashmap Increment this value 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.