Serialize ItemStack Array?

Discussion in 'Plugin Development' started by SnowGears, Aug 17, 2012.

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

    SnowGears

    I have a hashmap containing playerNames and their inventories( ItemStack[] ):

    Map<String, ItemStack[]> inventoryMapAlive = new HashMap<String,ItemStack[]>();

    I have a file inventory.yml that I need to save the hashmap to. I know how to save hashmaps to files so no need for that, just need to figure out how to serialize this hashmap and how to unserialize it when loading it from file.

    Any help would be great. I found some classes to serialize an ItemStack but I still need help figuring out how to get it into a serialized ItemStack Array and then that into a hashmap and also loading it. Thanks in advance!
     
    Pangamma likes this.
  2. Offline

    devilquak

    I actually need to do this exact thing too, and the thread that Digi points to only serializes single ItemStacks, not ItemStack arrays. Does anyone know how to do this?
     
  3. Offline

    Tirelessly

    If you can serialize an itemstack you can serialize an itemstack array... If you can't think of a solution yourself you can't call yourself a developer.
     
  4. Offline

    devilquak


    This forum is specifically for help with developing plugins. The title for this forum is "Need help developing a plugin? Got a bug you can't squash? Ask in here!", and I'm asking for help with something I can't do myself, even after hours of searching, trial, and error.

    I'm not inept at coding, but I'm not a complete imbecile either. I still have trouble with a lot of things, this being one of them, and when I need help, I come here to find it. I never called myself a developer, and although I would probably fall under that category compared to 90% of the other people that come here, I would probably never call myself that in the first place.

    The term "developer" is very subjective anyway, a person who just writes a "Hello World" program can be called a developer. Especially in the Bukkit forums, a place where nearly everything is free and provided open-source, with no real professions involved, the term "developer" can't be held to such high standards as a position that a real job can be, like being a scientist or a doctor, or developing for a "real" gaming company.

    I'm still learning, and like every other skill and like everyone else who learns, I need help and guidance with things I can't do myself. You don't tell a kid in school they're "not a student" if they're in the 4th grade if they can't figure out calculus, so why would you tell me "i'm not a developer" if I can't figure out this thing I just haven't learned yet?
     
    Lactem likes this.
  5. Offline

    Zidkon

    You just had to say that you don't even know what is an Array, then we will be pleased to show you a website where you identify what is an array.

    http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

    Enjoy it

    PD: Is not about calling you a developer or not, is just not making ourselves to do the research for you.

    After you read the whole Array thing, tell me what you don't get about:

     
  6. Offline

    Sushi

    I'm not one for making fun of people who ask for help here, but we gave you an ItemStack serializer. If you need help serializing ItemStack arrays even though you already have this ItemStack serializer, that's more of an issue with you-not-knowing-mechanics-of-java than you-not-knowing-mechanics-of-bukkit.
     
  7. Offline

    devilquak

    I know what Arrays are and how to use them, I use them all the time, they're very useful for a lot of things. I'm asking about ItemStack arrays here because for my purposes, it's very different from serializing a single ItemStack.

    Like the OP, I'm trying to save a HashMap with a player's name and their inventory in an ItemStack array to a file, and to do that, I need a serializer for the stacks. I can serialize stuff already, but I have trouble trying to use the thread Digi pointed to to serialize the ItemStack array.

    Now, of course I could be wrong and am spouting crap, and so that's what I'm asking about. I'm usually unsure about what I do if I've never done it before, and so I also just want other people's input about what the best way to proceed is for whatever I end up doing.
     
  8. Offline

    Zidkon

    Serialize an array is indeed different from serializing a unique ItemStack, with the very big difference is an array of ItemStacks, so it means for each ItemStack on the arraylist you will need to serialize it like an individual ItemStack.

    Now yea, sorry for my sarcasm, but is that bad that you don't get the meaning of an Array, or I don't get what problem do you have trying to serialize an ItemStack Array with a method that serialize a unique ItemStack.
     
  9. Offline

    devilquak

    I know what an array is. I use them all the time, and I am pretty familiar with most everything you can do with them. I still don't know what many things are, and I'm not ashamed to say I'm relatively bad at coding, but I actually do know a lot about Arrays. I'm still learning Java in general, and this particular situation, for whatever reason, I can't figure out on my own, so I'm asking other people for help.

    That being said, I'd really just like to find a solution to my problem...

    Edit: I'd also like to point out that it's not simply just serializing an ItemStack array, like the OP, I need to save it to a file and then be able to retrieve that and delete the entry from the file after I'm done using it. I know how to do like 1/5 of this, which is why I'm asking for help from people I know are much smarter than me.
     
  10. Offline

    Sagacious_Zed Bukkit Docs

    I would like to point out that an ItemStack is does not implement Serializable. It does however implement ConfiguraitonSerializable which means you need to do it through the Configuration API, which will make your life much easier.
     
  11. Offline

    Zidkon

    Ok, I still don't get exactly all, as well I will try help.

    What actually can you do? That 1/5 that you say, what is it?
     
  12. Offline

    devilquak

    I'm saying that even the 1/5 that I think I can do is probably wrong, and so I'm just asking someone else for guidance. I'm sure I need to start from scratch, so I just want to know what I should be doing before I go any further.
     
  13. Offline

    Zidkon

    Now it sounds to me that you want it all done so you can copy it all, seriously.

    Go better open your own post about what you need because I think you are not going anywhere here.
     
  14. Offline

    devilquak

    Complete facepalm...

    I'm asking the exact same question the OP did. The answer's link did not help me, or I did not use it correctly, so I'm asking anyone for any info related to this at all. This doesn't mean I'm asking anyone to write anything for me, though that would be nice.
     
    Pangamma likes this.
  15. Offline

    SnowGears

    I disagree. This is a forum for helping people and getting help. There is no need to make a duplicate post to the same forum if he has the exact same issue, that doesn't make any sense. If you you can not or will not help devilquak, there is no reason to make fun of him, we all learn somewhere.

    devilquak I would be happy to try to help you with this. I do not know exactly how to do this with itemstacks still but I have been working with serializable since my original post and I bet I could help if I play around with it for a while.
     
    devilquak likes this.
  16. Offline

    devilquak

    Thank goodness, someone who doesn't condescend on me for not being an expert at Java. Thanks so much for replying. I'm able to save ItemStack arrays in HashMaps, but as the maps are cleared on a reload/restart, I need a way to save them. ItemStack arrays aren't serializable, whereas I know single stacks are, so I'm looking for a way to somehow just serialize the array of stacks to a string and back.
     
    Pangamma likes this.
Thread Status:
Not open for further replies.

Share This Page