Search in sources :

Example 1 with HoconConfigurationLoader

use of org.spongepowered.configurate.hocon.HoconConfigurationLoader in project SpongeCommon by SpongePowered.

the class SpongeConfigs method create.

public static <T extends Config> ConfigHandle<T> create(final Class<T> instance, @Nullable final Supplier<ConfigurationTransformation> versionModifier, final String fileName) {
    try {
        final HoconConfigurationLoader loader = SpongeConfigs.createLoader(SpongeConfigs.getDirectory().resolve(fileName));
        final ConfigHandle<T> handle = new ConfigHandle<>(instance, versionModifier, loader);
        handle.load();
        return handle;
    } catch (final IOException ex) {
        SpongeConfigs.LOGGER.error("Unable to load configuration {}. Sponge will operate in " + "fallback mode, with default configuration options and will not write to the invalid file", fileName, ex);
        return new ConfigHandle<>(instance);
    }
}
Also used : HoconConfigurationLoader(org.spongepowered.configurate.hocon.HoconConfigurationLoader) IOException(java.io.IOException)

Example 2 with HoconConfigurationLoader

use of org.spongepowered.configurate.hocon.HoconConfigurationLoader in project SpongeCommon by SpongePowered.

the class HoconDataFormat method writeTo.

private static void writeTo(final Callable<BufferedWriter> sink, final DataView data) throws IOException {
    final HoconConfigurationLoader loader = HoconConfigurationLoader.builder().sink(sink).build();
    final ConfigurationNode node = loader.createNode();
    ConfigurateTranslator.instance().translateDataToNode(node, data);
    try {
        loader.save(node);
    } catch (final ConfigurateException ex) {
        throw new IOException(ex);
    }
}
Also used : HoconConfigurationLoader(org.spongepowered.configurate.hocon.HoconConfigurationLoader) CommentedConfigurationNode(org.spongepowered.configurate.CommentedConfigurationNode) ConfigurationNode(org.spongepowered.configurate.ConfigurationNode) ConfigurateException(org.spongepowered.configurate.ConfigurateException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 HoconConfigurationLoader (org.spongepowered.configurate.hocon.HoconConfigurationLoader)2 CommentedConfigurationNode (org.spongepowered.configurate.CommentedConfigurationNode)1 ConfigurateException (org.spongepowered.configurate.ConfigurateException)1 ConfigurationNode (org.spongepowered.configurate.ConfigurationNode)1