Saving & Loading Player Inventories

Discussion in 'Plugin Development' started by Wolf7115, Dec 3, 2011.

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

    Wolf7115

    Hello, I am developing a mini-game plugin right now. I've got everything I need in place except saving, removing, and loading player inventories. I have searched around, and I cannot find anything that helps me do this. I would mush appreciate it if anyone could give me a few tips on these three things:

    1. Storing a player's inventory for later use
    2. Removing a player's inventory so they have nothing on them
    3. Loading and replacing their inventory with their other saved items after the mini-game completes

    These would of course have their own subroutine for the saving and loading. I would assume that a simple line of code would be placed at the end of saving to clear the inventory.

    Thanks in advance.
     
  2. Offline

    wwsean08

    this is all off the top of my head but here are the (rough) methods to do this:
    1. ItemStack[] is = Player.getInventory().getContents();
    2. Player.getInventory().clear();
    3. Player.setContents(is);
     
    njallam and Wolf7115 like this.
  3. Offline

    Wolf7115

    Seems simple enough. I'll try that out.
     
  4. Offline

    wwsean08

    ya your actual storage and stuff like that is where it becomes tricky, and that implementation I will leave up to you, I suggest a hash map, and also remember to take into account the player getting kicked or quiting to prevent loss of inventory
     
  5. If the server crashes or something then his inventory will be lost :/
     
  6. Offline

    wwsean08

    true, but this is why i told him in a later post to take care of the player quiting, or getting kick, you gotta take care of stuff like that. I forgot about mentioning the server crashing scinario.
     
  7. Offline

    Wolf7115

    I might be able to try to save the inventories as a configuration or something similar.
     
  8. Offline

    wwsean08

    yes you can output an item stack (or in this case an item stack array) using an object output stream as ItemStack is serializable
     
Thread Status:
Not open for further replies.

Share This Page