Solved HashMap with ItemStack[] to set inventory contents

Discussion in 'Plugin Development' started by RoboticPlayer, Oct 12, 2015.

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

    RoboticPlayer

    I am trying to set the contents of a player's inventory by using data stored in a HashMap.
    Code:java
    1. private HashMap<String, ItemStack[]> inventory = new HashMap<String, ItemStack[]>();

    I also have a getter for this HashMap, as I am using it in other classes. However, I don't know how to set the player's inventory to the items in the HashMap. If this is not possible (or not practical), could I have a HashMap with the player's inventory and set the inventory itself instead of the contents? And then for the armor just use a HashMap<String, ItemStack>? In case you were wondering, the String in the HashMap is needed (I can't use an ArrayList), it contains the player's name. If I need to explain this more, please say so.
     
  2. Offline

    Xerox262

    player.getInventory().setContents(inventory.get(player.getName()));
    player.updateInventory();
    I guess that would work? What are you using it for?
     
  3. Offline

    oceantheskatr

  4. Offline

    RoboticPlayer

    @Xerox262 Thanks, I had forgotten how to use the HashMap.get() method, so I didn't think of that. Solved.
     
Thread Status:
Not open for further replies.

Share This Page