Allows to serialize and deserialize Bukkit's PersistentDataContainers to and from List<Map<?,?>>
s and Json, without
requiring NMS.
The dependency is available on Maven Central:
<dependency>
<groupId>com.jeff-media</groupId>
<artifactId>persistent-data-serializer</artifactId>
<version>1.0</version>
</dependency>
You must also shade the dependency into your plugin's .jar. Click here if you don't know how to do that.
// 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()
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.