Need help with HashMaps

Discussion in 'Plugin Development' started by DutchChris, May 14, 2020.

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

    DutchChris

    Hello!

    I recently made a post about players and variables and how I should store them and I was told HashMaps were the way to go. Sadly, I don't really know how to use HashMaps with Players. For example, how would I make a HashMap that stores player stats(levels & xp) so every player has their own stats? Thanks for the help!

    - DutchChris_
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    DutchChris

    @timtower how would I then put stuff in for each player?
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    leberwurst88

    @DutchChris
    HashMaps aren't too difficult, you can create one by using
    Code:
    HashMap<UUID,OtherClass> map = new HashMap<UUID,OtherClass>();
    Then simply add things to it:
    Code:
    map.put(player.getUniqueId(), object_of_other_class);
    To get the object back:
    Code:
    OtherClass object_of_other_class = map.get(player.getUniqueId());
    Check out the HashMap docs to see all the methods you can use on them:
    https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html
     
Thread Status:
Not open for further replies.

Share This Page