Removing a players entire inventory?

Discussion in 'Plugin Development' started by techboy291, Sep 4, 2012.

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

    techboy291

    Hi,


    So what I want to do is save a player's entire inventory, delete everything from it, and then when the time is right, put everything back in their inventory. Also, I want to do this for multiple players so I'm using an ArrayList right now. The problem is I can't figure out a good way to do all of it. Thanks!
     
  2. Offline

    makskay

    I'd suggest a HashMap<String, Inventory> that maps playernames to stored inventories.
     
  3. Offline

    kyle1320

    techboy291
    I'd use a hashmap to store the inventories:
    Code:
    HashMap<String, ItemStack[]> inventories = new HashMap<String, ItemStack[]>();
    This would be the code to move an inventory to the hashmap:
    Code:
    inventories.put(player.getName(), player.getInventory().getContents());
    player.getInventory().clear();
    Then to replace their inventory:
    Code:
    player.getInventory().setContents(inventories.get(player.getName()));
    :)
     
  4. Offline

    techboy291

    Oh great, thanks.

    Also, assuming the player had more than one item in their inventory, wouldn't you use PlayerInventory instead of ItemStack for the hashmap? Just wondering.
     
  5. Offline

    makskay

    The code that kyle1320 posted actually refers to an array of ItemStacks, which is a simplified form of the contents of any given inventory. I'd use a PlayerInventory myself but his approach is equally valid.
     
  6. Offline

    techboy291

    Oh, I didn't see that that was an array.
     
Thread Status:
Not open for further replies.

Share This Page