ItemStack toString

Discussion in 'Plugin Development' started by rominos2, Sep 1, 2012.

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

    rominos2

    Hi dev fellows, I've encountered some problem.
    I need to save an itemStack into a String

    But serialize return me a Map (having inside another map for enchantment for example)

    Do you have some idea ?

    Thanks in advance,

    Rominos2
     
  2. Offline

    andf54

    One solution is to use Gson. It is included in bukkit.

    // Writing:
    MyObject obj = blahblahblah;
    Gson gson =new Gson();
    String objStr = gson.toJson(obj);
    save(objStr);

    // Reading:
    String objStr = read();
    MyObject = gson.fromJson(objStr, MyObject.class);

    You can modify my plugins WriterReader.java: https://github.com/andfRa/Saga/blob/master/src/org/saga/saveload/WriterReader.java if you want. You only need to change Directory enum values.
     
  3. Offline

    rominos2

    andf54

    Hmm that sounds great.
    I'll test it.
    Thanks

    EDIT : It provides strings too long but I'll test some other ways not saving the ItemStack but number, the data, and the enchantements one after the other (less long string)
     
Thread Status:
Not open for further replies.

Share This Page