Search in sources :

Example 1 with SimpleConfigurationNode

use of ninja.leaping.configurate.SimpleConfigurationNode in project AtherysCore by Atherys-Horizons.

the class PluginConfig method save.

/**
 * Save the contents of the object mapper to the config file. This will override config values already-present in the file.
 */
public void save() {
    try {
        SimpleConfigurationNode out = SimpleConfigurationNode.root();
        this.configMapper.serialize(out);
        this.loader.save(out);
    } catch (ObjectMappingException | IOException e) {
        e.printStackTrace();
    }
}
Also used : IOException(java.io.IOException) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException)

Example 2 with SimpleConfigurationNode

use of ninja.leaping.configurate.SimpleConfigurationNode in project SpongeCommon by SpongePowered.

the class ConfigurateTranslator method translate.

@Override
public ConfigurationNode translate(DataView view) throws InvalidDataException {
    final SimpleConfigurationNode node = SimpleConfigurationNode.root();
    populateNode(node, view);
    return node;
}
Also used : SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode)

Example 3 with SimpleConfigurationNode

use of ninja.leaping.configurate.SimpleConfigurationNode in project LanternServer by LanternPowered.

the class MultimapTypeSerializer method serialize.

@Override
public void serialize(TypeToken<?> type, Multimap obj, ConfigurationNode node) throws ObjectMappingException {
    TypeToken<?> key = type.resolveType(Multimap.class.getTypeParameters()[0]);
    TypeToken<?> value = type.resolveType(Multimap.class.getTypeParameters()[1]);
    TypeSerializer keySerial = node.getOptions().getSerializers().get(key);
    TypeSerializer valueSerial = node.getOptions().getSerializers().get(value);
    if (keySerial == null) {
        throw new ObjectMappingException("No type serializer available for type " + key);
    }
    if (valueSerial == null) {
        throw new ObjectMappingException("No type serializer available for type " + value);
    }
    node.setValue(ImmutableMap.of());
    for (Object k : obj.keySet()) {
        for (Object v : obj.get(k)) {
            SimpleConfigurationNode keyNode = SimpleConfigurationNode.root();
            keySerial.serialize(key, k, keyNode);
            valueSerial.serialize(value, v, node.getNode(keyNode.getValue()));
        }
    }
}
Also used : TypeSerializer(ninja.leaping.configurate.objectmapping.serialize.TypeSerializer) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) SimpleConfigurationNode(ninja.leaping.configurate.SimpleConfigurationNode)

Aggregations

SimpleConfigurationNode (ninja.leaping.configurate.SimpleConfigurationNode)3 ObjectMappingException (ninja.leaping.configurate.objectmapping.ObjectMappingException)2 IOException (java.io.IOException)1 TypeSerializer (ninja.leaping.configurate.objectmapping.serialize.TypeSerializer)1