PimvanderLoos / PersistentDataSerializer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PersistentDataSerializer

Javadocs Discord Donate

Allows to serialize and deserialize Bukkit's PersistentDataContainers to and from List<Map<?,?>>s and Json, without requiring NMS.

Maven Dependency

The dependency is available on Maven Central:

<dependency>
    <groupId>com.jeff-media</groupId>
    <artifactId>persistent-data-serializer</artifactId>
    <version>1.0</version>
</dependency>

Shading

You must also shade the dependency into your plugin's .jar. Click here if you don't know how to do that.

Usage

// Serialize to Map
List<Map<?,?>>map=PersistentDataSerializer.toMapList(persistentDataContainer);

// Serialize to Json
        String json=PersistentDataSerializer.toJson(persistentDataContainer);

// Deserialize from Map
        PersistentDataContainer pdc=PersistentDataSerializer.fromMapList(pdcContext,map);

// Deserialize from Json
        PersistentDataContainer pdc=PersistentDataSerializer.fromJson(pdcContext,json);

Note: To deserialize, you need to provide a PersistentDataAdapterContext. You can get one from any existing PersistentDataContainer by calling PersistentDataContainer#getAdapterContext()

Information about MockBukkit

If you're using MockBukkit, you'll notice that serializing to Json or YAML causes issues as the MockBukkit implementation of PersistentDataContainer is buggy. It will work fine on the actual server though.

About

License:GNU General Public License v3.0


Languages

Language:Java 100.0%