Solved Serializing Item Stacks...

Discussion in 'Plugin Development' started by Yneeb, Apr 28, 2013.

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

    Yneeb

    Hi, I'm having a problem while trying to serialize ItemStacks. Here is the code:
    Code:
    ItemStack is = new ItemStack(276);
    is.addEnchantment(Enchantment.FIRE_ASPECT, 1);
    HashMap<String, Object> hm = new HashMap<String, Object>(is.serialize());
    try {
    new ObjectOutputStream(new FileOutputStream("file")).writeObject(hm);
    } catch(Exception e) {
    e.printStackTrace();
    }
    
    This works when the item isn't enchanted, but when it is I get a NotSerializableException. Am I doing this completely wrong or is it some kind of bug?
     
  2. Offline

    Jake0oo0

  3. Offline

    Yneeb

  4. ItemStacks implement ConfigurationSerializable which means you can store in and load from YAML files.
    It's a more flexible and built-in solution for that.
    Also, nobody is forcing you to use .yml extension.
     
Thread Status:
Not open for further replies.

Share This Page