node.getOptions().getSerializers().registerType(yourToken, yourSerializer) shoud allow you to register your serializer (that must implements TypeSerializer<YourClass>)
Thanks guys I will check it as soon as I can!
Can I ask you one more question?
What is better way to check, is config node exists?
Is there an analogue to Bukkit configurationSection.isSet(“path”) ?
public class LocationSerializer implements TypeSerializer<Location> {
@Override
public Location<World> deserialize(TypeToken<?> token, ConfigurationNode node) throws ObjectMappingException {
if (!node.getNode("WORLD").isVirtual()) {
throw new ObjectMappingException("World does not specified!");
}
if (!node.getNode("X").isVirtual()) {
throw new ObjectMappingException("X coordinate does not specified!");
}
if (!node.getNode("Y").isVirtual()) {
throw new ObjectMappingException("Y coordinate does not specified");
}
if (!node.getNode("Z").isVirtual()) {
throw new ObjectMappingException("Z coordinate does not specified!");
}
String world_name = node.getNode("WORLD").getString();
Optional<World> optional_world = Sponge.getServer().getWorld(world_name);
if (!optional_world.isPresent()) {
throw new ObjectMappingException("World \"" + world_name + "\" does not exist!");
}
World world = optional_world.get();
double x = node.getNode("X").getDouble();
double y = node.getNode("Y").getDouble();
double z = node.getNode("Z").getDouble();
Location<World> location = new Location<World>(world, x, y, z);
return location;
}
@Override
public void serialize(TypeToken<?> token, Location<World> location, ConfigurationNode node) throws ObjectMappingException {
World world = location.getExtent();
double x = location.getX();
double y = location.getY();
double z = location.getZ();
String world_name = world.getName();
node.getNode("WORLD").setValue(world_name);
node.getNode("X").setValue(x);
node.getNode("Y").setValue(y);
node.getNode("Z").setValue(z);
}
When you register TypeToken.of(Location.class), this isn’t valid. The TypeToken needs to be exactly the same type parameters as the TypeSerializer. So you construct the TypeToken like this: new TypeToken<Location<World>>(){}