How to test hashmap players/ send messages to hashmap players

Discussion in 'Plugin Development' started by SeanyJo, Sep 13, 2013.

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

    Benatat12

    Why are people saying use map.entrySet().size(). Why not just map.size(), since it is a collection?
     
  2. Offline

    SeanyJo

    Type mismatch: cannot convert from element type Player to String is the error i get. I fix it by changing the String to Player, but then it underlines the getPlayerExact() and tells me to either change Player back to String, or to change getPlayerExact() to getPlayer();.
     
  3. Offline

    Benatat12

    getPlayerExact() takes a String parameter. You are passing in a Player object.

    in the HashMap, change the type to String. Then, when using put, use player.getName(). When you want to retrieve, then you can use: Bukkit.getPlayerExact(playerName)
     
  4. Offline

    Quantix

    Never store Player objects in lists. Here's an explanation from ferrybig's signature: Memory leaks: - Player logs off: Javas GC can't remove it cause your list/set/other still contains it. So you still have the whole instance of the player (with the IP, the real name, the display name, the list name, the health, the potion effects, ...) even if minecraft tries to save it to disc and unloads it from ram. - Multiworld (or some other multi world plugin) unloads the world the (maybe since two or more days... but still in your list...) logged off player was in. The GC can't remove it cause there's still that player instance in your map, which is holding the world loaded, which prevents the GC from releasing RAM...
     
  5. Offline

    SeanyJo

    Never Mind.

    Also, not to criticize or anything, but the public void tellPlayersInMap should have been static, if that helps at all.

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

    Benatat12

    Why? If it was, then it wouldn't work, due to being unable to reference the map, whoch he made an instance field, in a static context.
     
  7. Offline

    SeanyJo

    it worked for me...
     
  8. Offline

    Benatat12

    SeanyJo
    Yes, because your map was static. I was referring to his sample code, where the map wasn't static.
     
  9. Offline

    SeanyJo

    ohh, ok.
     
Thread Status:
Not open for further replies.

Share This Page