Storing Chest contetnt(and saving)

Discussion in 'Plugin Development' started by Tster, Feb 4, 2012.

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

    Tster

    Thanks

    Found this out from LWC source.
    New question, how do I store the contents of a chest, and load them into a chest screen

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  2. You could just save all of the itemstacks and them insert them one by one into the chest upon loading.
     
  3. Offline

    Tster

    aha, But I need to store the contents in a hashmap where the key is the player's name,
    and as far as i know, Arrays of Itemstacks aren't seriazble
     
  4. Well if you use Sync that is possible. You can serialize itemstacks and many other Bukkit objects.
     
  5. Offline

    Tster

    Advertising your work again? JKS :p
    I will give it a go, how should I use it though, like sput? Adamki11s

    My bad, saw a wiki

    Sorry, I am not good with interfacing stuff, how do I make this work Adamki11s

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  6. Tster Yes I know I am advertising it but in my defence I need to otherwise it won't get known :p. Plus I spent a lot of hard work on it and it is actually extremely helpful ;)

    What you want to do is create an Array of ItemStacks and then this can be saved and loaded like so

    Code:java
    1.  
    2. public void saveItems(ItemStack[] stacks){
    3. SyncItemStack[] saveStacks = new SyncItemStacks[stacks.length];
    4. for(int i = 0; i < stacks.length; i++){
    5. saveStacks[i] = new SyncItemStack(stacks[i]);
    6. }
    7. File f;//create a file to save to
    8. SyncObjectIO stream = new SyncObjectIO(f);
    9. stream.add("Items", saveStacks);
    10. stream.write();
    11. }
    12.  
    13. public ItemStack[] loadItems(){
    14. SyncObjectIO stream = new SyncObjectIO(f);
    15. stream.read();
    16. Object o = stream.getObject("Items");
    17. SyncItemStack[] readStacks = (ItemStack[]) o;
    18. ItemStack[] stack = new ItemStacks[readStacks.length];
    19. for(int i = 0; i < readStacks.length; i++){
    20. stack[i] = readStacks[i].getBukkitItemStack();
    21. }
    22. return stack;
    23. }
    24. [/i][/i][/i][/i]
     
Thread Status:
Not open for further replies.

Share This Page