Solved Item Metadata Deserialization

Discussion in 'Plugin Development' started by Coelho, Jan 5, 2013.

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

    Coelho

    You can serialize Item Metadata to a Map<String, Object>, however I can not find a way to deseralize Item Metadata from Map<String, Object> while using only the Bukkit API.

    Anything I'm missing?

    This seems to work, although it is a bit more hackish than I'd like.
    Code:
    public static ItemMeta deserializeItemMeta(Class<? extends ItemMeta> itemMetaClass, Map<String, Object> args) {
    DelegateDeserialization delegate = itemMetaClass.getAnnotation(DelegateDeserialization.class);
    return (ItemMeta) ConfigurationSerialization.deserializeObject(args, delegate.value());
    }
    
    You need to pass in the class of an existing ItemStack's metadata, but everything else is straightforward, and it does not use any NMS or OBC calls.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 8, 2016
  2. Offline

    fireblast709

    ItemMeta implements ConfigurationSerializable, you should just be able to do
    Code:
    someConfig.set("path.to.meta", itemmeta)
     
    Zwander likes this.
Thread Status:
Not open for further replies.

Share This Page