Saving Metadata

Discussion in 'Plugin Development' started by kellerkindt, Dec 29, 2012.

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

    kellerkindt

    Whats the recommended way to save the metadata of an ItemStack?

    Currently I am saving the HashMap through serialization (ObjectOutpuStream...)
    But that doesn't work for example for the MetaData of fireworks, because they
    have the Object "org.bukkit.FireworkEffect" in their MetaData Map, which isn't serializable.

    So whats the recommended and best way to store the MetaData of an ItemStack
    to load it again later?

    Greets
     
  2. Offline

    fireblast709

    FireworkMeta implements ConfigurationSerializable, so it should be able to store it in a config
     
  3. Offline

    kellerkindt

    Thanks for you reply!
    Could you give me a quick code example?
     
  4. Offline

    fireblast709

    Afaik set("path", themeta) and (FireworkMeta)get("path") should work
     
  5. Offline

    kellerkindt

    Isn't there a way given by bukkit, to store the returned HashMap directly into a file?
    Or something else to store and load it again?
     
  6. Offline

    fireblast709

    I have seen people use ObjectOutputStreams. But you can also just use a manual version:
    Code:java
    1. for(Entry<K,V> entry : yourHashMap.entrySet())
    2. {
    3. yourConfig.set(entry.getKey().toString(), entry.getValue());
    4. }

    And
    Code:java
    1. for(String key : yourConfig.getKeys(false))
    2. {
    3. yourHashMap.put(new K(key), (V)yourConfig.get(key));
    4. }
    Note that this method would only function with primitive types, as I cannot guarantee that it would work with others. Replace K and V with your key and value types
     
  7. Offline

    kellerkindt

    Actually, I am working with the java Serialization,
    but hoped there is another - better - way.
    Currently I have the issue, that in the serialized FireworkMeta,
    the - not Serializable - effects are added.

    As there seems to be no other way than serialization,
    this would sovle the/my issue: https://github.com/Bukkit/CraftBukkit/pull/975/files
     
Thread Status:
Not open for further replies.

Share This Page