Persistent metadata

Discussion in 'Plugin Development' started by einstein5, Jan 4, 2014.

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

    einstein5

    Is there any way of making a metadata of an placed item that has a metadata to make it persistent.(to stay there after the plugin restarts)
     
  2. Offline

    messageofdeath

    The plugin restart or the server? If the server restarts it will be lost, but if it reloads it will stay. If the plugin reloads it will stay as long as the server is still running. It will reset as it is temporary data and shouldn't be relied on to save data.
     
  3. Offline

    einstein5

    so there is no way of saving the metadata when the server restarts

    isn't it?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  4. Offline

    dillyg10

    Not... really...

    What you can do is store the item entity's UUID in a map with whatever metadata you need, then serialize that and save it to a config... I must ask, for what purpose do you need to save the metadata for?
     
  5. Offline

    Techy4198

    I have a similar issue to this with my plugin, MiscBukkit. it is only up to the second version but so far both of them have used metadata on entities in huge quantities, for water pistols. I managed to do a clever way using a perfectly human-readable item lore to store restart-proof data. I wonder if it is possible to do something similar with entities which utilizes the entity's information saved to file, such as the entity id and stuff. I need this because at the moment, it is very unsafe. my features use normal item entities and fallingsand entities with metadata. so if the server restarts, the entities will be saved but the metadata will not. this could mean that fallingsand entities marked as 'fake', from a water pistol, that would normally get destroyed on contact with anything, will just land and form water blocks when the server has loaded back up. I want some alternative to metadata, but due to such huge quantities of these entities that could be popping in and out of existence at any given moment, I believe saving to a config just wouldn't be fast enough to handle it without lagging the server. any suggestions?
     
  6. Offline

    WillTheBastard

    Sure you can. You can store any java object by just serializing it into a base64 string and storing it by file or via a database. The object needs to implement the Serializable class, most bukkit objects don't. So you may have to create your own object that implements Serializable, store the metadata information in it and have your object then store it somewhere.. Then when you want to retrieve it, decode it and cast back into your object.
     
  7. Offline

    dillyg10


    Or you can use Google's GSON / Bukkit's Serialization API and save yourself the headache of stroing a most likely non YAML safe base64 string ;).
     
  8. Offline

    einstein5

    Ok,but it if the metadata is specific for a block , how to I save it in a map?Actually what do I save in the map:the position of the block ? Or how do I specify that the metadata belongs to that specific block....

    noone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page